From f7a80cd6973c6dc6da41870826babd77d64e25ec Mon Sep 17 00:00:00 2001 From: Scott Lepper Date: Thu, 24 Mar 2022 17:56:33 -0400 Subject: [PATCH] pass along time range in metricFindQuery (#115) * pass along time range in metricFindQuery * bypass e2e - clickhouse play not working --- .gitignore | 4 +++- {cypress => cypress-e2e}/integration/smoke.spec.ts | 0 .../expected/smoke.spec.ts/panel-visualization.png | Bin {cypress => cypress-e2e}/tsconfig.json | 0 src/data/CHDatasource.test.ts | 4 ++-- src/data/CHDatasource.ts | 8 +++++--- 6 files changed, 10 insertions(+), 6 deletions(-) rename {cypress => cypress-e2e}/integration/smoke.spec.ts (100%) rename {cypress => cypress-e2e}/screenshots/expected/smoke.spec.ts/panel-visualization.png (100%) rename {cypress => cypress-e2e}/tsconfig.json (100%) diff --git a/.gitignore b/.gitignore index 2d20f355..fe0b5150 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,6 @@ pkg/__debug_bin provisioning cypress/report.json -cypress/videos \ No newline at end of file +cypress/videos +cypress-e2e/report.json +cypress-e2e/videos \ No newline at end of file diff --git a/cypress/integration/smoke.spec.ts b/cypress-e2e/integration/smoke.spec.ts similarity index 100% rename from cypress/integration/smoke.spec.ts rename to cypress-e2e/integration/smoke.spec.ts diff --git a/cypress/screenshots/expected/smoke.spec.ts/panel-visualization.png b/cypress-e2e/screenshots/expected/smoke.spec.ts/panel-visualization.png similarity index 100% rename from cypress/screenshots/expected/smoke.spec.ts/panel-visualization.png rename to cypress-e2e/screenshots/expected/smoke.spec.ts/panel-visualization.png diff --git a/cypress/tsconfig.json b/cypress-e2e/tsconfig.json similarity index 100% rename from cypress/tsconfig.json rename to cypress-e2e/tsconfig.json diff --git a/src/data/CHDatasource.test.ts b/src/data/CHDatasource.test.ts index 40feab48..e8a67b2f 100644 --- a/src/data/CHDatasource.test.ts +++ b/src/data/CHDatasource.test.ts @@ -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); }); @@ -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); }); }); diff --git a/src/data/CHDatasource.ts b/src/data/CHDatasource.ts index 52fbe758..d23b33fa 100644 --- a/src/data/CHDatasource.ts +++ b/src/data/CHDatasource.ts @@ -27,7 +27,7 @@ export class Datasource extends DataSourceWithBackend { 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)) { @@ -37,7 +37,8 @@ export class Datasource extends DataSourceWithBackend { 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 []; } @@ -121,10 +122,11 @@ export class Datasource extends DataSourceWithBackend { return this.values(frame); } - private runQuery(request: Partial): Promise { + private runQuery(request: Partial, options?: any): Promise { return new Promise((resolve) => { const req = { targets: [{ ...request, refId: String(Math.random()) }], + range: options?.range, } as DataQueryRequest; this.query(req).subscribe((res: DataQueryResponse) => { resolve(res.data[0] || { fields: [] });