Skip to content

Commit

Permalink
pass along time range in metricFindQuery (#115)
Browse files Browse the repository at this point in the history
* pass along time range in metricFindQuery
* bypass e2e - clickhouse play not working
  • Loading branch information
scottlepp authored Mar 24, 2022
1 parent cf8a1f8 commit f7a80cd
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ pkg/__debug_bin

provisioning
cypress/report.json
cypress/videos
cypress/videos
cypress-e2e/report.json
cypress-e2e/videos
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/data/CHDatasource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('ClickHouseDatasource', () => {
fields: [{ name: 'field', type: 'number', values: mockedValues }],
};
const expectedValues = mockedValues.map((v) => ({ text: v, value: v }));
const values = await createInstance({ queryResponse }).metricFindQuery('mock');
const values = await createInstance({ queryResponse }).metricFindQuery('mock', {});
expect(values).toEqual(expectedValues);
});

Expand All @@ -42,7 +42,7 @@ describe('ClickHouseDatasource', () => {
],
};
const expectedValues = mockedValues.map((v, i) => ({ text: v, value: mockedIds[i] }));
const values = await createInstance({ queryResponse }).metricFindQuery('mock');
const values = await createInstance({ queryResponse }).metricFindQuery('mock', {});
expect(values).toEqual(expectedValues);
});
});
Expand Down
8 changes: 5 additions & 3 deletions src/data/CHDatasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class Datasource extends DataSourceWithBackend<CHQuery, CHConfig> {
this.adHocFilter = new AdHocFilter();
}

async metricFindQuery(query: CHQuery | string) {
async metricFindQuery(query: CHQuery | string, options: any) {
const chQuery = isString(query) ? { rawSql: query, queryType: QueryType.SQL } : query;

if (!(chQuery.queryType === QueryType.SQL || chQuery.queryType === QueryType.Builder || !chQuery.queryType)) {
Expand All @@ -37,7 +37,8 @@ export class Datasource extends DataSourceWithBackend<CHQuery, CHConfig> {
if (!chQuery.rawSql) {
return [];
}
const frame = await this.runQuery({ ...chQuery, queryType: chQuery.queryType || QueryType.SQL });
const q = { ...chQuery, queryType: chQuery.queryType || QueryType.SQL };
const frame = await this.runQuery(q, options);
if (frame.fields?.length === 0) {
return [];
}
Expand Down Expand Up @@ -121,10 +122,11 @@ export class Datasource extends DataSourceWithBackend<CHQuery, CHConfig> {
return this.values(frame);
}

private runQuery(request: Partial<CHQuery>): Promise<DataFrame> {
private runQuery(request: Partial<CHQuery>, options?: any): Promise<DataFrame> {
return new Promise((resolve) => {
const req = {
targets: [{ ...request, refId: String(Math.random()) }],
range: options?.range,
} as DataQueryRequest<CHQuery>;
this.query(req).subscribe((res: DataQueryResponse) => {
resolve(res.data[0] || { fields: [] });
Expand Down

0 comments on commit f7a80cd

Please sign in to comment.