Skip to content

Commit

Permalink
fix variable insertion (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
Loori-R authored Oct 7, 2024
1 parent fa90658 commit 518eca5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## tip

* BUGFIX: fix variable substitution in queries. See [this issue](https://github.com/VictoriaMetrics/victorialogs-datasource/issues/77).

## v0.5.0

* FEATURE: add support of the `$__interval` variable in queries. See [this issue](https://github.com/VictoriaMetrics/victorialogs-datasource/issues/61).
Expand Down
11 changes: 4 additions & 7 deletions src/datasource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaults, map as lodashMap } from 'lodash';
import { defaults } from 'lodash';
import { Observable, lastValueFrom } from "rxjs";
import { map } from 'rxjs/operators';

Expand Down Expand Up @@ -166,16 +166,13 @@ export class VictoriaLogsDatasource
}

interpolateQueryExpr(value: any, _variable: any) {
const wrapInQuotes = (v: string) => `"${v}"`;

if (typeof value === 'string') {
return wrapInQuotes(value);
return value;
}

if (Array.isArray(value)) {
const escapedAndQuotedValues = lodashMap(value, wrapInQuotes);
const combinedValues = escapedAndQuotedValues.join(' OR ');
return escapedAndQuotedValues.length > 1 ? `(${combinedValues})` : combinedValues;
const combinedValues = value.join(' OR ');
return value.length > 1 ? `(${combinedValues})` : combinedValues;
}

return value;
Expand Down

0 comments on commit 518eca5

Please sign in to comment.