Skip to content

Commit

Permalink
Tempo: Fix get label values based on CoreApp type (#68463)
Browse files Browse the repository at this point in the history
Fix and update test
  • Loading branch information
joey-grafana committed May 15, 2023
1 parent 47b7b05 commit a1f76af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion public/app/plugins/datasource/tempo/datasource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
LoadingState,
createDataFrame,
PluginType,
CoreApp,
} from '@grafana/data';
import {
BackendDataSourceResponse,
Expand Down Expand Up @@ -449,7 +450,7 @@ describe('Tempo service graph view', () => {
});
setDataSourceSrv(backendSrvWithPrometheus as any);
const response = await lastValueFrom(
ds.query({ targets: [{ queryType: 'serviceMap' }], range: getDefaultTimeRange() } as any)
ds.query({ targets: [{ queryType: 'serviceMap' }], range: getDefaultTimeRange(), app: CoreApp.Explore } as any)
);

expect(response.data).toHaveLength(3);
Expand Down
17 changes: 16 additions & 1 deletion public/app/plugins/datasource/tempo/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { EMPTY, from, lastValueFrom, merge, Observable, of, throwError } from 'r
import { catchError, concatMap, map, mergeMap, toArray } from 'rxjs/operators';

import {
CoreApp,
DataFrame,
DataQueryRequest,
DataQueryResponse,
DataQueryResponseData,
Expand Down Expand Up @@ -597,7 +599,20 @@ function errorAndDurationQuery(
let serviceGraphViewMetrics = [];
let errorRateBySpanName = '';
let durationsBySpanName: string[] = [];
const spanNames = getEscapedSpanNames(rateResponse.data[0][0]?.fields[1]?.values ?? []);

let labels = [];
if (request.app === CoreApp.Explore) {
if (rateResponse.data[0][0]?.fields[1]?.values) {
labels = rateResponse.data[0][0]?.fields[1]?.values;
}
} else if (rateResponse.data[0]) {
rateResponse.data[0].map((df: DataFrame) => {
if (df.fields[1]?.labels && df.fields[1]?.labels['span_name']) {
labels.push(df.fields[1]?.labels['span_name']);
}
});
}
const spanNames = getEscapedSpanNames(labels);

if (spanNames.length > 0) {
errorRateBySpanName = buildExpr(errorRateMetric, 'span_name=~"' + spanNames.join('|') + '"', request);
Expand Down

0 comments on commit a1f76af

Please sign in to comment.