Skip to content

Commit

Permalink
Bugfix: Account for template variables that resolve to a number, prep…
Browse files Browse the repository at this point in the history
…are 2.9.10 (#323)
  • Loading branch information
idastambuk authored Nov 11, 2024
1 parent ede927c commit 299f908
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

All notable changes to this project will be documented in this file.

## 2.9.10

- Bugfix: Account for template variable being a number
- Chore: update dependabot config (#317)
- Dependency updates:
- Upgrade grafana-plugin-sdk-go (deps): Bump github.com/grafana/grafana-plugin-sdk-go from 0.251.0 to 0.258.0 in [#314](https://github.com/grafana/timestream-datasource/pull/314),[#315](https://github.com/grafana/timestream-datasource/pull/315), [#319](https://github.com/grafana/timestream-datasource/pull/319)
- Updates github.com/aws/aws-sdk-go from 1.51.31 to 1.55.5 in [#319](https://github.com/grafana/timestream-datasource/pull/319)
- Updates github.com/grafana/grafana-aws-sdk from 0.31.2 to 0.31.3 in [#319](https://github.com/grafana/timestream-datasource/pull/319)
- Updates actions/checkout from 2 to 4 in [#318](https://github.com/grafana/timestream-datasource/pull/318)
- Updates tibdex/github-app-token from 1.8.0 to 2.1.0 in [#318](https://github.com/grafana/timestream-datasource/pull/318)

## 2.9.9

- Fix "Wait for All Queries" toggle in [#313](https://github.com/grafana/timestream-datasource/pull/313)
Expand Down
3 changes: 2 additions & 1 deletion cspell.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"otelhttptrace",
"otelgrpc",
"sqlutil",
"errorsource"
"errorsource",
"tibdex"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "grafana-timestream-datasource",
"version": "2.9.9",
"version": "2.9.10",
"description": "Load data timestream in grafana",
"scripts": {
"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",
Expand Down
6 changes: 3 additions & 3 deletions src/DataSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('DataSource', () => {
expect(res.rawQuery).toEqual(`select * from foo where var in ('foo','bar')`);
});

it('should replace __interval interpolated variables with their original string', () => {
it('should return number variables', () => {
mockDatasource.applyTemplateVariables(
{ ...mockQuery, rawQuery: 'select $__interval_ms, $__interval' },
{
Expand All @@ -55,8 +55,8 @@ describe('DataSource', () => {
}
);
// check rawQuery.replace is called with correct interval value
expect(replaceMock.mock.calls[3][1].__interval).toEqual({ value: '$__interval' });
expect(replaceMock.mock.calls[3][1].__interval_ms).toEqual({ value: '$__interval_ms' });
expect(replaceMock.mock.calls[3][1].__interval).toEqual({ value: 50000 });
expect(replaceMock.mock.calls[3][1].__interval_ms).toEqual({ value: 5000000 });
});
});
});
14 changes: 5 additions & 9 deletions src/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ export class DataSource extends DataSourceWithBackend<TimestreamQuery, Timestrea
return query.rawQuery ?? '';
}

private interpolateVariable = (value: string | string[]) => {
private interpolateVariable = (value: string | string[] | number) => {
if (typeof value === 'string') {
return value;
}

if (typeof value === 'number') {
return value;
}

const quotedValues = value.map((v) => {
return this.quoteLiteral(v);
});
Expand All @@ -76,14 +80,6 @@ export class DataSource extends DataSourceWithBackend<TimestreamQuery, Timestrea
}

const variables = { ...scopedVars };
// We want to interpolate these variables on backend.
// The pre-calculated values are replaced with the variable strings.
variables.__interval = {
value: '$__interval',
};
variables.__interval_ms = {
value: '$__interval_ms',
};

const templateSrv = getTemplateSrv();
return {
Expand Down

0 comments on commit 299f908

Please sign in to comment.