From 792dad3a760c83a6de8f21810340bb276399105e Mon Sep 17 00:00:00 2001 From: Martin Magakian Date: Mon, 13 Jan 2020 21:37:15 +0100 Subject: [PATCH] Discard Summary metrics --- cmd/prom-aggregation-gateway/main.go | 18 ++++++++++-------- cmd/prom-aggregation-gateway/main_test.go | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/cmd/prom-aggregation-gateway/main.go b/cmd/prom-aggregation-gateway/main.go index c27bec1..91fc65d 100644 --- a/cmd/prom-aggregation-gateway/main.go +++ b/cmd/prom-aggregation-gateway/main.go @@ -117,12 +117,10 @@ func mergeMetric(ty dto.MetricType, a, b *dto.Metric) *dto.Metric { }, } - case dto.MetricType_SUMMARY: - // No way of merging summaries, abort. + default: + // No way of merging other metrics types, discard. return nil } - - return nil } func mergeFamily(a, b *dto.MetricFamily) (*dto.MetricFamily, error) { @@ -206,15 +204,19 @@ func (a *aggate) parseAndMerge(r io.Reader) error { a.familiesLock.Lock() defer a.familiesLock.Unlock() for name, family := range inFamilies { - // Sort labels in case source sends them inconsistently - for _, m := range family.Metric { - sort.Sort(byName(m.Label)) + // Discard unsupported types + if *family.Type == dto.MetricType_SUMMARY { + continue } - if err := validateFamily(family); err != nil { return err } + // Sort labels in case source sends them inconsistently + for _, m := range family.Metric { + sort.Sort(byName(m.Label)) + } + // family must be sorted for the merge sort.Sort(byLabel(family.Metric)) diff --git a/cmd/prom-aggregation-gateway/main_test.go b/cmd/prom-aggregation-gateway/main_test.go index a205178..b034757 100644 --- a/cmd/prom-aggregation-gateway/main_test.go +++ b/cmd/prom-aggregation-gateway/main_test.go @@ -137,6 +137,20 @@ counter{b="b",a="a"} 2 reorderedLabelsResult = `# HELP counter A counter # TYPE counter counter counter{a="a",b="b"} 3 +` + + summaryInput = `# HELP cpu_temperature_celsius Current temperature of the CPU. +# TYPE cpu_temperature_celsius summary +cpu_temperature_celsius_sum 30.2 +cpu_temperature_celsius_count 1 +# HELP counter A counter +# TYPE counter counter +counter 1 +` + + summaryDiscardedOutput = `# HELP counter A counter +# TYPE counter counter +counter 2 ` ) @@ -153,6 +167,7 @@ func TestAggate(t *testing.T) { {labelFields1, labelFields2, labelFieldResult, nil, nil}, {duplicateLabels, "", "", fmt.Errorf("%s", duplicateError), nil}, {reorderedLabels1, reorderedLabels2, reorderedLabelsResult, nil, nil}, + {summaryInput, summaryInput, summaryDiscardedOutput, nil, nil}, } { a := newAggate()