Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependencies: Update @grafana dependencies to 9.3.2 #167

Merged
merged 3 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ jobs:
workflow-call:
uses: grafana/code-coverage/.github/workflows/code-coverage.yml@v0.1.13
with:
frontend-path-regexp:
frontend-path-regexp: src
backend-path-regexp: pkg\/(client|datasource)
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"@babel/core": "^7.16.7",
"@emotion/css": "^11.1.3",
"@grafana/aws-sdk": "0.0.42",
"@grafana/data": "8.1.5",
"@grafana/e2e": "9.1.2",
"@grafana/e2e-selectors": "9.1.2",
"@grafana/data": "9.3.2",
"@grafana/e2e": "9.3.2",
"@grafana/e2e-selectors": "9.3.2",
"@grafana/eslint-config": "^2.5.0",
"@grafana/runtime": "8.1.5",
"@grafana/runtime": "9.3.2",
"@grafana/tsconfig": "^1.2.0-rc1",
"@grafana/ui": "8.1.5",
"@grafana/ui": "9.3.2",
"@swc/core": "^1.2.144",
"@swc/helpers": "^0.3.6",
"@swc/jest": "^0.2.20",
Expand Down Expand Up @@ -63,7 +63,7 @@
"react": "17.0.1",
"react-dom": "17.0.1",
"replace-in-file-webpack-plugin": "^1.0.6",
"rxjs": "6.6.3",
"rxjs": "7.5.7",
"sass": "1.55.0",
"sass-loader": "13.1.0",
"style-loader": "3.3.1",
Expand Down
47 changes: 26 additions & 21 deletions src/DataSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
DataSourceInstanceSettings,
FieldType,
MutableDataFrame,
NodeGraphDataFrameFieldNames,
ScopedVars,
VariableModel,
TypedVariableModel,
} from '@grafana/data';
import {
XrayJsonData,
Expand All @@ -17,7 +18,7 @@ import {
XrayTraceDataRaw,
XrayTraceDataSegmentDocument,
} from './types';
import { of } from 'rxjs';
import { firstValueFrom, of } from 'rxjs';
import { TemplateSrv } from '@grafana/runtime';

jest.mock('@grafana/runtime', () => {
Expand All @@ -35,7 +36,7 @@ jest.mock('@grafana/runtime', () => {
},
getTemplateSrv(): TemplateSrv {
return {
getVariables(): VariableModel[] {
getVariables(): TypedVariableModel[] {
return [];
},
replace(target?: string, scopedVars?: ScopedVars, format?: string | Function): string {
Expand All @@ -54,6 +55,8 @@ jest.mock('@grafana/runtime', () => {
}
return target!;
},
containsTemplate: jest.fn(),
updateTimeRange: jest.fn(),
};
},
};
Expand All @@ -63,15 +66,17 @@ describe('XrayDataSource', () => {
describe('.query()', () => {
it('returns parsed data when querying single trace', async () => {
const ds = makeDatasourceWithResponse(makeTraceResponse(makeTrace()));
const response = await ds.query(makeQuery()).toPromise();
const response = await firstValueFrom(ds.query(makeQuery()));
expect(response.data.length).toBe(1);
expect(response.data[0].fields.length).toBe(13);
expect(response.data[0].fields[0].values.length).toBe(2);
});

it('returns parsed data with links when querying trace list', async () => {
const ds = makeDatasourceWithResponse(makeTraceSummariesResponse());
const response = await ds.query(makeQuery({ queryType: XrayQueryType.getTraceSummaries, query: '' })).toPromise();
const response = await firstValueFrom(
ds.query(makeQuery({ queryType: XrayQueryType.getTraceSummaries, query: '' }))
);
expect(response.data.length).toBe(1);
const df: DataFrame = response.data[0];
expect(df.fields.length).toBe(2);
Expand All @@ -86,23 +91,23 @@ describe('XrayDataSource', () => {

it('returns parsed data when querying service map', async () => {
const ds = makeDatasourceWithResponse(makeServiceMapResponse());
const response = await ds.query(makeQuery({ queryType: XrayQueryType.getServiceMap, query: '' })).toPromise();
const response = await firstValueFrom(ds.query(makeQuery({ queryType: XrayQueryType.getServiceMap, query: '' })));
expect(response.data.length).toBe(2);
const nodes: DataFrame = response.data[0];
expect(nodes.fields.length).toBe(9);
const edges: DataFrame = response.data[1];
expect(edges.fields.length).toBe(7);
expect(edges.fields.find((f) => f.name === 'mainStat')?.values.toArray()).toEqual(
expect(edges.fields.find((f) => f.name === NodeGraphDataFrameFieldNames.mainStat)?.values.toArray()).toEqual(
expect.arrayContaining(['N/A'])
);
expect(edges.fields.find((f) => f.name === 'secondaryStat')?.values.toArray()).toEqual(
expect(edges.fields.find((f) => f.name === NodeGraphDataFrameFieldNames.secondaryStat)?.values.toArray()).toEqual(
expect.arrayContaining([undefined])
);
});

it('should parse insight response correctly', async () => {
const ds = makeDatasourceWithResponse(makeInsightResponse());
const response = await ds.query(makeQuery({ queryType: XrayQueryType.getInsights, query: '' })).toPromise();
const response = await firstValueFrom(ds.query(makeQuery({ queryType: XrayQueryType.getInsights, query: '' })));
const df: DataFrame = response.data[0];
expect(df.fields[0].config.links?.[0].url).toBe(
'https://us-east.console.aws.amazon.com/xray/home?region=us-east#/insights/${__value.raw}'
Expand All @@ -114,51 +119,51 @@ describe('XrayDataSource', () => {

it('adds correct resolution based on interval', async () => {
const ds = makeDatasourceWithResponse({} as any);
await ds
.query(
await firstValueFrom(
ds.query(
makeQuery({ queryType: XrayQueryType.getTimeSeriesServiceStatistics, query: '' }, { intervalMs: 400 * 1000 })
)
.toPromise();
);
const mockQuery = (ds as any).mockQuery as jest.Mock;
expect(mockQuery.mock.calls[0][0].targets[0].resolution).toBe(300);
});

it('does not override explicit resolution', async () => {
const ds = makeDatasourceWithResponse({} as any);
await ds
.query(
await firstValueFrom(
ds.query(
makeQuery(
{ queryType: XrayQueryType.getTimeSeriesServiceStatistics, query: '', resolution: 60 },
{ intervalMs: 400 * 1000 }
)
)
.toPromise();
);
const mockQuery = (ds as any).mockQuery as jest.Mock;
expect(mockQuery.mock.calls[0][0].targets[0].resolution).toBe(60);
});

it('handles variable interpolation', async () => {
const ds = makeDatasourceWithResponse({} as any);
await ds
.query(
await firstValueFrom(
ds.query(
makeQuery({ query: 'service("$variable")' }, { scopedVars: { variable: { text: 'test', value: 'test' } } })
)
.toPromise();
);
const mockQuery = (ds as any).mockQuery as jest.Mock;
expect(mockQuery.mock.calls[0][0].targets[0].query).toBe('service("test")');
});

it('handles group', async () => {
const ds = makeDatasourceWithResponse({} as any);
await ds
.query(
await firstValueFrom(
ds.query(
makeQuery({
queryType: XrayQueryType.getTimeSeriesServiceStatistics,
query: 'service("something")',
group: { FilterExpression: 'service("from group")' } as any,
})
)
.toPromise();
);
const mockQuery = (ds as any).mockQuery as jest.Mock;
expect(mockQuery.mock.calls[0][0].targets[0].query).toBe('service("from group") AND service("something")');
});
Expand Down
2 changes: 1 addition & 1 deletion src/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class XrayDataSource extends DataSourceWithBackend<XrayQuery, XrayJsonDat
expandedQueries = queries.map((query) => {
const expandedQuery = {
...query,
datasource: this.name,
datasource: this.getRef(),
query: getTemplateSrv().replace(query.query, scopedVars),
};
return expandedQuery;
Expand Down
6 changes: 4 additions & 2 deletions src/components/QueryEditor/QueryEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { render, screen, fireEvent, act, waitFor } from '@testing-library/react'
import { QueryEditor } from './QueryEditor';
import { Group, Region, XrayJsonData, XrayQuery, XrayQueryType } from '../../types';
import { XrayDataSource } from '../../DataSource';
import { DataSourceInstanceSettings, ScopedVars, VariableModel } from '@grafana/data';
import { DataSourceInstanceSettings, ScopedVars, TypedVariableModel } from '@grafana/data';
import * as grafanaRuntime from '@grafana/runtime';

jest.spyOn(grafanaRuntime, 'getTemplateSrv').mockImplementation(() => {
return {
getVariables(): VariableModel[] {
getVariables(): TypedVariableModel[] {
return [];
},
replace(target?: string, scopedVars?: ScopedVars, format?: string | Function): string {
Expand All @@ -27,6 +27,8 @@ jest.spyOn(grafanaRuntime, 'getTemplateSrv').mockImplementation(() => {
}
return target!;
},
containsTemplate: jest.fn(),
updateTimeRange: jest.fn(),
};
});

Expand Down
2 changes: 1 addition & 1 deletion src/components/QueryEditor/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { XrayQueryType } from '../../types';
import { CascaderOption } from '@grafana/ui/components/Cascader/Cascader';
import { CascaderOption } from '@grafana/ui';

export type QueryTypeOption = CascaderOption & {
queryType?: XrayQueryType;
Expand Down
Loading