|
|
|
@ -17,6 +17,7 @@ import { |
|
|
|
|
QueryResultMeta, |
|
|
|
|
TimeSeriesValue, |
|
|
|
|
ScopedVars, |
|
|
|
|
toDataFrame, |
|
|
|
|
} from '@grafana/data'; |
|
|
|
|
|
|
|
|
|
import { getTemplateSrv, getDataSourceSrv } from '@grafana/runtime'; |
|
|
|
@ -184,21 +185,16 @@ function lokiMatrixToTimeSeries(matrixResult: LokiMatrixResult, options: Transfo |
|
|
|
|
return { |
|
|
|
|
target: name, |
|
|
|
|
title: name, |
|
|
|
|
datapoints: lokiPointsToTimeseriesPoints(matrixResult.values, options), |
|
|
|
|
datapoints: lokiPointsToTimeseriesPoints(matrixResult.values), |
|
|
|
|
tags: matrixResult.metric, |
|
|
|
|
meta: options.meta, |
|
|
|
|
refId: options.refId, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function lokiPointsToTimeseriesPoints( |
|
|
|
|
data: Array<[number, string]>, |
|
|
|
|
options: TransformerOptions |
|
|
|
|
): TimeSeriesValue[][] { |
|
|
|
|
const stepMs = options.step * 1000; |
|
|
|
|
export function lokiPointsToTimeseriesPoints(data: Array<[number, string]>): TimeSeriesValue[][] { |
|
|
|
|
const datapoints: TimeSeriesValue[][] = []; |
|
|
|
|
|
|
|
|
|
let baseTimestampMs = options.start / 1e6; |
|
|
|
|
for (const [time, value] of data) { |
|
|
|
|
let datapointValue: TimeSeriesValue = parseFloat(value); |
|
|
|
|
|
|
|
|
@ -207,19 +203,10 @@ export function lokiPointsToTimeseriesPoints( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const timestamp = time * 1000; |
|
|
|
|
for (let t = baseTimestampMs; t < timestamp; t += stepMs) { |
|
|
|
|
datapoints.push([null, t]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
baseTimestampMs = timestamp + stepMs; |
|
|
|
|
datapoints.push([datapointValue, timestamp]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const endTimestamp = options.end / 1e6; |
|
|
|
|
for (let t = baseTimestampMs; t <= endTimestamp; t += stepMs) { |
|
|
|
|
datapoints.push([null, t]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return datapoints; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -454,7 +441,7 @@ function fieldFromDerivedFieldConfig(derivedFieldConfigs: DerivedFieldConfig[]): |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function rangeQueryResponseToTimeSeries( |
|
|
|
|
function rangeQueryResponseToTimeSeries( |
|
|
|
|
response: LokiResponse, |
|
|
|
|
query: LokiRangeQueryRequest, |
|
|
|
|
target: LokiQuery, |
|
|
|
@ -491,6 +478,33 @@ export function rangeQueryResponseToTimeSeries( |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function rangeQueryResponseToDataFrames( |
|
|
|
|
response: LokiResponse, |
|
|
|
|
query: LokiRangeQueryRequest, |
|
|
|
|
target: LokiQuery, |
|
|
|
|
responseListLength: number, |
|
|
|
|
scopedVars: ScopedVars |
|
|
|
|
): DataFrame[] { |
|
|
|
|
const series = rangeQueryResponseToTimeSeries(response, query, target, responseListLength, scopedVars); |
|
|
|
|
const frames = series.map((s) => toDataFrame(s)); |
|
|
|
|
|
|
|
|
|
const { step } = query; |
|
|
|
|
|
|
|
|
|
if (step != null) { |
|
|
|
|
const intervalMs = step * 1000; |
|
|
|
|
|
|
|
|
|
frames.forEach((frame) => { |
|
|
|
|
frame.fields.forEach((field) => { |
|
|
|
|
if (field.type === FieldType.time) { |
|
|
|
|
field.config.interval = intervalMs; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return frames; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function processRangeQueryResponse( |
|
|
|
|
response: LokiResponse, |
|
|
|
|
target: LokiQuery, |
|
|
|
@ -511,7 +525,7 @@ export function processRangeQueryResponse( |
|
|
|
|
case LokiResultType.Vector: |
|
|
|
|
case LokiResultType.Matrix: |
|
|
|
|
return of({ |
|
|
|
|
data: rangeQueryResponseToTimeSeries( |
|
|
|
|
data: rangeQueryResponseToDataFrames( |
|
|
|
|
response, |
|
|
|
|
query, |
|
|
|
|
{ |
|
|
|
|