Skip to content

Commit

Permalink
fix: loading with multiple queries (#224)
Browse files Browse the repository at this point in the history
Co-authored-by: Dmytro Kozlov <d.kozlov@victoriametrics.com>
  • Loading branch information
Loori-R and dmitryk-dk authored Nov 21, 2024
1 parent 95bea81 commit 2993c7b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## tip

* BUGFIX: fix query loading when using multiple visible queries in a panel. See [this issue](https://github.com/VictoriaMetrics/victoriametrics-datasource/issues/223).
* BUGFIX: fix escaping when selecting metrics in the metrics browser. See [this issue](https://github.com/VictoriaMetrics/victoriametrics-datasource/issues/214).
* BUGFIX: fix incorrect step calculation in annotation queries. See [this issue](https://github.com/VictoriaMetrics/victoriametrics-datasource/issues/217).

Expand Down
32 changes: 16 additions & 16 deletions src/datasource.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

import { cloneDeep } from 'lodash';
import { of } from 'rxjs';
import { ScopedVar, ScopedVars } from '@grafana/data';

import {
ScopedVar,
ScopedVars,
CoreApp,
DataQueryRequest,
DataQueryResponse,
Expand Down Expand Up @@ -224,8 +225,8 @@ describe('PrometheusDatasource', () => {
return str.replace('$topk', topk.value);
});
const caseTarget: PromQuery = { expr: 'topk_max($topk, vmalert_iteration_duration_seconds_sum)', refId: 'A' };
const result = ds.createQuery(caseTarget, { interval: '15s', scopedVars: { 'topk': { text: 'topk', value: '5' } } as ScopedVars} as DataQueryRequest<PromQuery>, 0, 0);
expect(result).toMatchObject({ expr: 'topk_max(5, vmalert_iteration_duration_seconds_sum{k1="v1"})'});
const result = ds.createQuery(caseTarget, { interval: '15s', scopedVars: { 'topk': { text: 'topk', value: '5' } } as ScopedVars } as DataQueryRequest<PromQuery>, 0, 0);
expect(result).toMatchObject({ expr: 'topk_max(5, vmalert_iteration_duration_seconds_sum{k1="v1"})' });
});
});

Expand Down Expand Up @@ -525,7 +526,7 @@ describe('PrometheusDatasource', () => {
refId: 'A'
};
const result = ds.applyTemplateVariables(query, { 'topk': { text: 'topk', value: '5' } } as ScopedVars);
expect(result).toMatchObject({ expr: 'topk_max(5, vmalert_iteration_duration_seconds_sum{k1="v1"})'});
expect(result).toMatchObject({ expr: 'topk_max(5, vmalert_iteration_duration_seconds_sum{k1="v1"})' });
});
});

Expand Down Expand Up @@ -653,7 +654,6 @@ function getPrepareTargetsContext({
const options = {
targets,
interval: '1s',
requestId: "request_id",
panelId,
app,
...queryOptions,
Expand All @@ -680,7 +680,7 @@ describe('prepareTargets', () => {
const target: PromQuery = {
refId: 'A',
expr: 'up',
requestId: 'request_id',
requestId: '2A',
};

const { queries, activeTargets, panelId, end, start } = getPrepareTargetsContext({ targets: [target] });
Expand All @@ -698,7 +698,7 @@ describe('prepareTargets', () => {
hinting: undefined,
instant: undefined,
refId: target.refId,
requestId: target.requestId,
requestId: panelId + target.refId,
start,
step: 1,
});
Expand Down Expand Up @@ -782,7 +782,7 @@ describe('prepareTargets', () => {
expr: 'up',
range: true,
instant: true,
requestId: 'request_id',
requestId: '2A',
};

const { queries, activeTargets, panelId, end, start } = getPrepareTargetsContext({
Expand All @@ -803,15 +803,15 @@ describe('prepareTargets', () => {
hinting: undefined,
instant: true,
refId: target.refId,
requestId: target.requestId + "_instant",
requestId: panelId + target.refId + '_instant',
start,
step: 1,
});
expect(activeTargets[0]).toEqual({
...target,
format: 'table',
instant: true,
requestId: target.requestId + "_instant",
requestId: panelId + target.refId + '_instant',
valueWithRefId: true,
});
expect(queries[1]).toEqual({
Expand All @@ -825,15 +825,15 @@ describe('prepareTargets', () => {
hinting: undefined,
instant: false,
refId: target.refId,
requestId: target.requestId,
requestId: panelId + target.refId,
start,
step: 1,
});
expect(activeTargets[1]).toEqual({
...target,
format: 'time_series',
instant: false,
requestId: target.requestId,
requestId: panelId + target.refId,
});
});
});
Expand All @@ -845,7 +845,7 @@ describe('prepareTargets', () => {
expr: 'up',
instant: true,
range: false,
requestId: 'request_id',
requestId: '2A',
};

const { queries, activeTargets, panelId, end, start } = getPrepareTargetsContext({
Expand All @@ -866,7 +866,7 @@ describe('prepareTargets', () => {
hinting: undefined,
instant: true,
refId: target.refId,
requestId: target.requestId,
requestId: panelId + target.refId,
start,
step: 1,
});
Expand All @@ -882,7 +882,7 @@ describe('prepareTargets', () => {
expr: 'up',
range: true,
instant: false,
requestId: 'request_id',
requestId: '2A',
};

const { queries, activeTargets, panelId, end, start } = getPrepareTargetsContext({
Expand All @@ -903,7 +903,7 @@ describe('prepareTargets', () => {
hinting: undefined,
instant: false,
refId: target.refId,
requestId: target.requestId,
requestId: panelId + target.refId,
start,
step: 1,
trace: undefined
Expand Down
4 changes: 2 additions & 2 deletions src/datasource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export class PrometheusDatasource
continue;
}

target.requestId = options.requestId
target.requestId = options.panelId + target.refId;
// const metricName = this.languageProvider.histogramMetrics.find((m) => target.expr.includes(m));

// In Explore, we run both (instant and range) queries if both are true (selected) or both are undefined (legacy Explore queries)
Expand Down Expand Up @@ -365,7 +365,7 @@ export class PrometheusDatasource
return {
...target,
queryType: PromQueryType.timeSeriesQuery,
requestId: request.requestId,
requestId: request.panelId + target.refId,
// We need to pass utcOffsetSec to backend to calculate aligned range
utcOffsetSec: this.timeSrv.timeRange().to.utcOffset() * 60,
};
Expand Down

0 comments on commit 2993c7b

Please sign in to comment.