diff --git a/provisioning/datasources/redis.yaml b/provisioning/datasources/redis.yaml index cba84ff..2e92ea5 100644 --- a/provisioning/datasources/redis.yaml +++ b/provisioning/datasources/redis.yaml @@ -5,7 +5,6 @@ datasources: type: redis-datasource access: proxy orgId: 1 - isDefault: true version: 1 url: redis://host.docker.internal:6379 jsonData: diff --git a/src/data-source/data-source.test.ts b/src/data-source/data-source.test.ts index d6b413f..98c619e 100644 --- a/src/data-source/data-source.test.ts +++ b/src/data-source/data-source.test.ts @@ -298,6 +298,39 @@ describe('DataSource', () => { }); }); + it('Should call query method with numbers', (done) => { + const querySpyMethod = jest.spyOn(dataSource, 'query').mockImplementation( + () => + new Observable((subscriber) => { + subscriber.next({ + data: [ + { + fields: [ + { + name: 'get', + values: { + toArray() { + return new Float64Array([21, 31]); + }, + }, + }, + ], + length: 1, + }, + ], + }); + subscriber.complete(); + }) + ); + + dataSource.metricFindQuery && + dataSource.metricFindQuery('123', { variable: { datasource: '123' } }).then((result: MetricFindValue[]) => { + expect(querySpyMethod).toHaveBeenCalled(); + expect(result).toEqual([{ text: 21 }, { text: 31 }]); + done(); + }); + }); + afterAll(() => { superQueryMock.mockReset(); setTemplateSrv(null as any); diff --git a/src/data-source/data-source.ts b/src/data-source/data-source.ts index ebdcb46..c265d2b 100644 --- a/src/data-source/data-source.ts +++ b/src/data-source/data-source.ts @@ -48,16 +48,19 @@ export class DataSource extends DataSourceWithBackend) .pipe( switchMap$((response) => response.data), switchMap$((data: DataFrame) => data.fields), - map$((field) => - field.values.toArray().map((value) => { - return { text: value }; - }) - ) + map$((field) => { + const values: MetricFindValue[] = []; + field.values.toArray().forEach((value) => { + values.push({ text: value }); + }); + + return values; + }) ) .toPromise(); }