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

Fix NaN for variables #206

Merged
merged 1 commit into from
Jun 26, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion provisioning/datasources/redis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ datasources:
type: redis-datasource
access: proxy
orgId: 1
isDefault: true
version: 1
url: redis://host.docker.internal:6379
jsonData:
Expand Down
33 changes: 33 additions & 0 deletions src/data-source/data-source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 9 additions & 6 deletions src/data-source/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,19 @@ export class DataSource extends DataSourceWithBackend<RedisQuery, RedisDataSourc
* Run Query
*/
return this.query({
targets: [{ datasource: options.variable.datasource, query: query }],
targets: [{ refId: 'A', datasource: options.variable.datasource, query: query }],
} as DataQueryRequest<RedisQuery>)
.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();
}
Expand Down