auth_proxy_test.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { sleep, check, group } from 'k6';
  2. import { createBasicAuthClient } from './modules/client.js';
  3. export let options = {
  4. noCookiesReset: true
  5. };
  6. let endpoint = __ENV.URL || 'http://localhost:10080/grafana';
  7. const client = createBasicAuthClient(endpoint, 'user1', 'grafana');
  8. client.withOrgId(1);
  9. export const setup = () => {
  10. const adminClient = createBasicAuthClient(endpoint, 'admin', 'admin');
  11. let res = adminClient.datasources.getByName('gdev-prometheus');
  12. if (res.status !== 200) {
  13. throw new Error('Expected 200 response status when creating datasource');
  14. }
  15. return {
  16. datasourceId: res.json().id,
  17. };
  18. }
  19. export default (data) => {
  20. group("auth proxy test", () => {
  21. group("batch proxy requests", () => {
  22. const d = new Date();
  23. const batchCount = 300;
  24. const requests = [];
  25. const query = encodeURI('topk(5, max(scrape_duration_seconds) by (job))');
  26. const start = (d.getTime() / 1000) - 3600;
  27. const end = (d.getTime() / 1000);
  28. const step = 20;
  29. requests.push({ method: 'GET', url: '/api/annotations?dashboardId=8&from=1558670300607&to=1558691900607' });
  30. for (let n = 0; n < batchCount; n++) {
  31. requests.push({
  32. method: 'GET',
  33. url: `/api/datasources/proxy/${data.datasourceId}/api/v1/query_range?query=${query}&start=${start}&end=${end}&step=${step}`,
  34. });
  35. }
  36. let responses = client.batch(requests);
  37. for (let n = 0; n < batchCount; n++) {
  38. check(responses[n], {
  39. 'response status is 200': (r) => r.status === 200,
  40. });
  41. }
  42. });
  43. });
  44. sleep(5)
  45. }
  46. export const teardown = (data) => {}