Tempo: Add fixes for broken exemplars (#103298)

* Add fix for broken exemplars

* Update fix for frame length

* Remove blank line and fix merge issue?
pull/104489/head
Joey 9 months ago committed by GitHub
parent acf85504fc
commit 792a2b1e01
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      pkg/tsdb/tempo/traceql/exemplars.go
  2. 10
      public/app/plugins/datasource/tempo/streaming.ts

@ -43,6 +43,11 @@ func transformExemplarToFrame(name string, series *tempopb.TimeSeries) *data.Fra
traceId = strings.ReplaceAll(traceId, "\"", "")
}
// Skip exemplars with invalid data
if exemplar.GetValue() == 0 || exemplar.GetTimestampMs() <= 0 {
continue
}
// Add basic data
frame.AppendRow(time.UnixMilli(exemplar.GetTimestampMs()), exemplar.GetValue(), traceId)

@ -188,7 +188,6 @@ export function doTempoMetricsStreaming(
function mergeFrames(acc: DataQueryResponse, newResult: DataQueryResponse): DataQueryResponse {
const result = combineResponses(cloneQueryResponse(acc), newResult);
// Remove duplicate time field values for all frames
result.data = result.data.map((frame: DataFrame) => {
let newFrame = frame;
const timeFieldIndex = frame.fields.findIndex((f) => f.type === FieldType.time);
@ -227,6 +226,15 @@ function removeDuplicateTimeFieldValues(accFrame: DataFrame, timeFieldIndex: num
accFrame.fields.forEach((field) => {
field.values = field.values.filter((_, index) => !indexesToRemove.includes(index));
});
// This updates the length of the dataframe having already removed duplicate values.
// This is necessary because Tempo sends partial results to Grafana and
// this can result in duplicate values for the same timestamp so this removes
// older values and keeps the latest value, and ensures the length of the dataframe is updated,
// which would otherwise cause issues with rendering the exemplar data.
if (accFrame.name === 'exemplar' && accFrame.meta?.dataTopic === 'annotations' && indexesToRemove.length > 0) {
accFrame.length = accFrame.fields[timeFieldIndex].values.length;
}
}
function metricsDataFrame(metrics: SearchMetrics, state: SearchStreamingState, elapsedTime: number) {

Loading…
Cancel
Save