mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 20:59:35 +08:00

* wip: add slo support * Export DataSourcePlugin * wip: break out metric query editor into its own component * wip: refactor frontend - keep SLO and Metric query in differnt objects * wip - load services and slos * Fix broken test * Add interactive slo expression builder * Change order of dropdowns * Refactoring backend model. slo unit testing in progress * Unit test migration and SLOs * Cleanup SLO editor * Simplify alias by component * Support alias by for slos * Support slos in variable queries * Fix broken last query error * Update Help section to include SLO aliases * streamline datasource resource cache * Break out api specific stuff in datasource to its own file * Move get projects call to frontend * Refactor api caching * Unit test api service * Fix lint go issue * Fix typescript strict errors * Fix test datasource * Use budget fraction selector instead of budget * Reset SLO when service is changed * Handle error in case resource call returned no data * Show real SLI display name * Use unsafe prefix on will mount hook * Store goal in query model since it will be used as soon as graph panel supports adding a threshold * Add comment to describe why componentWillMount is used * Interpolate sloid * Break out SLO aggregation into its own func * Also test group bys for metricquery test * Remove not used type fields * Remove annoying stackdriver prefix from error message * Default view param to FULL * Add part about SLO query builder in docs * Use new images * Fixes after feedback * Add one more group by test * Make stackdriver types internal * Update docs/sources/features/datasources/stackdriver.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update docs/sources/features/datasources/stackdriver.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Update docs/sources/features/datasources/stackdriver.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Updates after PR feedback * add test for when no alias by defined * fix infinite loop when newVariables feature flag is on onChange being called in componentDidUpdate produces an infinite loop when using the new React template variable implementation. Also fixes a spelling mistake * implements feedback for documentation changes * more doc changes Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> Co-authored-by: Daniel Lee <dan.limerick@gmail.com>
70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
import Api from './api';
|
|
import { backendSrv } from 'app/core/services/backend_srv'; // will use the version in __mocks__
|
|
import { SelectableValue } from '@grafana/data';
|
|
|
|
jest.mock('@grafana/runtime', () => ({
|
|
...jest.requireActual('@grafana/runtime'),
|
|
getBackendSrv: () => backendSrv,
|
|
}));
|
|
|
|
const response = [
|
|
{ label: 'test1', value: 'test1' },
|
|
{ label: 'test2', value: 'test2' },
|
|
];
|
|
|
|
describe('api', () => {
|
|
const datasourceRequestMock = jest.spyOn(backendSrv, 'datasourceRequest');
|
|
beforeEach(() => {
|
|
datasourceRequestMock.mockImplementation((options: any) => {
|
|
const data = { [options.url.match(/([^\/]*)\/*$/)[1]]: response };
|
|
return Promise.resolve({ data, status: 200 });
|
|
});
|
|
});
|
|
|
|
describe('when resource was cached', () => {
|
|
let api: Api;
|
|
let res: Array<SelectableValue<string>>;
|
|
beforeEach(async () => {
|
|
api = new Api('/stackdriver/');
|
|
api.cache['some-resource'] = response;
|
|
res = await api.get('some-resource');
|
|
});
|
|
|
|
it('should return cached value and not load from source', () => {
|
|
expect(res).toEqual(response);
|
|
expect(api.cache['some-resource']).toEqual(response);
|
|
expect(datasourceRequestMock).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe('when resource was not cached', () => {
|
|
let api: Api;
|
|
let res: Array<SelectableValue<string>>;
|
|
beforeEach(async () => {
|
|
api = new Api('/stackdriver/');
|
|
res = await api.get('some-resource');
|
|
});
|
|
|
|
it('should return cached value and not load from source', () => {
|
|
expect(res).toEqual(response);
|
|
expect(api.cache['some-resource']).toEqual(response);
|
|
expect(datasourceRequestMock).toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
describe('when cache should be bypassed', () => {
|
|
let api: Api;
|
|
let res: Array<SelectableValue<string>>;
|
|
beforeEach(async () => {
|
|
api = new Api('/stackdriver/');
|
|
api.cache['some-resource'] = response;
|
|
res = await api.get('some-resource', { useCache: false });
|
|
});
|
|
|
|
it('should return cached value and not load from source', () => {
|
|
expect(res).toEqual(response);
|
|
expect(datasourceRequestMock).toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|