Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Prometheus histograms when keylabels and values sit at the same path #11759

Merged
merged 12 commits into from
Apr 12, 2019
22 changes: 21 additions & 1 deletion metricbeat/helper/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,30 @@ func (p *prometheus) GetProcessedMetrics(mapping *MetricsMapping) ([]common.MapS
}

if field != "" {
// Put it in the event if it's a common metric
event := getEvent(eventsMap, keyLabels)

// Case: histograms + keyLabels, whose labels are written at the same level as the
// histogram data
//
// if the path where the values are to be written exists, current fields will be overwritten
// if that happens we will keep the existingFields variable for restoring later
existingFields, _ := event.GetValue(field)

event.Put(field, value)
event.DeepUpdate(labels)

// If we overwrited metrics values on top of existing labels, let's restore.
// If there is a conflict (there shoudln't) we will keep values over labels
if existingFields != nil {
overwritten, _ := existingFields.(common.MapStr)
for k, v := range overwritten {
restorePath := field + "." + k
if exists, _ := event.GetValue(restorePath); exists == nil {
event.Put(field+"."+k, v)
}
}
}

odacremolbap marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
Loading