Merge pull request #195 from giesselmann/prometheus_missing_metrics

Prometheus backend: omit metrics with empty series
This commit is contained in:
Jan Eitzinger 2023-08-09 08:56:38 +02:00 committed by GitHub
commit bc6e6250e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -326,7 +326,6 @@ func (pdb *PrometheusDataRepository) LoadData(
Timestep: metricConfig.Timestep, Timestep: metricConfig.Timestep,
Series: make([]schema.Series, 0), Series: make([]schema.Series, 0),
} }
jobData[metric][scope] = jobMetric
} }
step := int64(metricConfig.Timestep) step := int64(metricConfig.Timestep)
steps := int64(to.Sub(from).Seconds()) / step steps := int64(to.Sub(from).Seconds()) / step
@ -335,6 +334,10 @@ func (pdb *PrometheusDataRepository) LoadData(
jobMetric.Series = append(jobMetric.Series, jobMetric.Series = append(jobMetric.Series,
pdb.RowToSeries(from, step, steps, row)) pdb.RowToSeries(from, step, steps, row))
} }
// only add metric if at least one host returned data
if !ok && len(jobMetric.Series) > 0{
jobData[metric][scope] = jobMetric
}
// sort by hostname to get uniform coloring // sort by hostname to get uniform coloring
sort.Slice(jobMetric.Series, func(i, j int) bool { sort.Slice(jobMetric.Series, func(i, j int) bool {
return (jobMetric.Series[i].Hostname < jobMetric.Series[j].Hostname) return (jobMetric.Series[i].Hostname < jobMetric.Series[j].Hostname)