Loki: Show loki datasource stats in panel inspector (#24190)

* Loki: Show loki datasource stats in panel inspector

- puts the loki query result stats into the query results meta stat API
of Grafana, this allows the display of all backend loki stats in the
panel inspector in the dashboards
- added a hack to also display one of those values in Explore as a meta
label using the dataframe meta `custom` mechanims to point to a single
stat entry for each series which is then added together to show total
bytes processed across all query row results (this should be changed for
7.1 to make full use of the panel inspector in Explore)

* Fix test

* nicer stats labels for loki stats with units
This commit is contained in:
David
2020-05-04 18:06:21 +02:00
committed by GitHub
parent 2fc2a7c3f5
commit 9420873e6c
4 changed files with 87 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
import { CircularDataFrame, FieldCache, FieldType, MutableDataFrame } from '@grafana/data';
import { LokiStreamResult, LokiTailResponse } from './types';
import { LokiStreamResult, LokiTailResponse, LokiStreamResponse, LokiResultType } from './types';
import * as ResultTransformer from './result_transformer';
import { enhanceDataFrame } from './result_transformer';
@@ -18,6 +18,19 @@ const streamResult: LokiStreamResult[] = [
},
];
const lokiResponse: LokiStreamResponse = {
status: 'success',
data: {
result: streamResult,
resultType: LokiResultType.Stream,
stats: {
summary: {
bytesTotal: 900,
},
},
},
};
describe('loki result transformer', () => {
afterAll(() => {
jest.restoreAllMocks();
@@ -45,7 +58,7 @@ describe('loki result transformer', () => {
describe('lokiStreamsToDataframes', () => {
it('should enhance data frames', () => {
jest.spyOn(ResultTransformer, 'enhanceDataFrame');
const dataFrames = ResultTransformer.lokiStreamsToDataframes(streamResult, { refId: 'B' }, 500, {
const dataFrames = ResultTransformer.lokiStreamsToDataframes(lokiResponse, { refId: 'B' }, 500, {
derivedFields: [
{
matcherRegex: 'trace=(w+)',