From 9b5fbb95d3c2a50d76ed630564c40e511137b725 Mon Sep 17 00:00:00 2001 From: shreyassrivatsan Date: Fri, 4 Dec 2020 08:58:48 -0800 Subject: [PATCH] [coordinator] add graphite names to aggregation types (#2970) --- .../downsample/downsampler_test.go | 8 ++--- .../downsample/metrics_appender.go | 2 +- src/metrics/aggregation/type.go | 34 +++++++++++++++++++ src/metrics/aggregation/types_options_test.go | 26 +------------- 4 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/cmd/services/m3coordinator/downsample/downsampler_test.go b/src/cmd/services/m3coordinator/downsample/downsampler_test.go index ddcfff7d23..25241157f3 100644 --- a/src/cmd/services/m3coordinator/downsample/downsampler_test.go +++ b/src/cmd/services/m3coordinator/downsample/downsampler_test.go @@ -601,7 +601,7 @@ func TestDownsamplerAggregationWithRulesConfigMappingRulesAggregationType(t *tes tags: map[string]string{ "__g0__": "nginx_edge", "__g1__": "health", - "__g2__": "Max", + "__g2__": "upper", }, values: []expectedValue{{value: 30}}, attributes: &storagemetadata.Attributes{ @@ -668,7 +668,7 @@ func TestDownsamplerAggregationWithRulesConfigMappingRulesMultipleAggregationTyp tags: map[string]string{ "__g0__": "nginx_edge", "__g1__": "health", - "__g2__": "Max", + "__g2__": "upper", }, values: []expectedValue{{value: 30}}, attributes: &storagemetadata.Attributes{ @@ -681,7 +681,7 @@ func TestDownsamplerAggregationWithRulesConfigMappingRulesMultipleAggregationTyp tags: map[string]string{ "__g0__": "nginx_edge", "__g1__": "health", - "__g2__": "Sum", + "__g2__": "sum", }, values: []expectedValue{{value: 60}}, attributes: &storagemetadata.Attributes{ @@ -742,7 +742,7 @@ func TestDownsamplerAggregationWithRulesConfigMappingRulesGraphitePrefixAndAggre "__g1__": "counter", "__g2__": "nginx_edge", "__g3__": "health", - "__g4__": "Max", + "__g4__": "upper", }, values: []expectedValue{{value: 30}}, attributes: &storagemetadata.Attributes{ diff --git a/src/cmd/services/m3coordinator/downsample/metrics_appender.go b/src/cmd/services/m3coordinator/downsample/metrics_appender.go index 9632e1f70d..d073e813ee 100644 --- a/src/cmd/services/m3coordinator/downsample/metrics_appender.go +++ b/src/cmd/services/m3coordinator/downsample/metrics_appender.go @@ -595,7 +595,7 @@ func (a *metricsAppender) augmentTags( var ( count = tags.countPrefix(graphite.Prefix) name = graphite.TagName(count) - value = types[0].Bytes() + value = types[0].Name() ) tags.append(name, value) } diff --git a/src/metrics/aggregation/type.go b/src/metrics/aggregation/type.go index 5c9913345e..db10e274ae 100644 --- a/src/metrics/aggregation/type.go +++ b/src/metrics/aggregation/type.go @@ -101,6 +101,31 @@ var ( } typeStringMap map[string]Type + + typeStringNames = map[Type][]byte{ + Last: []byte("last"), + Min: []byte("lower"), + Max: []byte("upper"), + Mean: []byte("mean"), + Median: []byte("median"), + Count: []byte("count"), + Sum: []byte("sum"), + SumSq: []byte("sum_sq"), + Stdev: []byte("stdev"), + P10: []byte("p10"), + P20: []byte("p20"), + P30: []byte("p30"), + P40: []byte("p40"), + P50: []byte("p50"), + P60: []byte("p60"), + P70: []byte("p70"), + P80: []byte("p80"), + P90: []byte("p90"), + P95: []byte("p95"), + P99: []byte("p99"), + P999: []byte("p999"), + P9999: []byte("p9999"), + } ) // Type defines an aggregation function. @@ -232,6 +257,15 @@ func (a *Type) UnmarshalText(data []byte) error { return nil } +// Name returns the name of the Type. +func (a Type) Name() []byte { + name, ok := typeStringNames[a] + if ok { + return name + } + return a.Bytes() +} + func validateProtoType(a aggregationpb.AggregationType) error { _, ok := aggregationpb.AggregationType_name[int32(a)] if !ok { diff --git a/src/metrics/aggregation/types_options_test.go b/src/metrics/aggregation/types_options_test.go index 00040366d5..ec7080c004 100644 --- a/src/metrics/aggregation/types_options_test.go +++ b/src/metrics/aggregation/types_options_test.go @@ -449,32 +449,8 @@ func validateQuantiles(t *testing.T, o TypesOptions) { } func typeStrings(overrides map[Type][]byte) [][]byte { - defaultTypeStrings := map[Type][]byte{ - Last: []byte("last"), - Min: []byte("lower"), - Max: []byte("upper"), - Mean: []byte("mean"), - Median: []byte("median"), - Count: []byte("count"), - Sum: []byte("sum"), - SumSq: []byte("sum_sq"), - Stdev: []byte("stdev"), - P10: []byte("p10"), - P20: []byte("p20"), - P30: []byte("p30"), - P40: []byte("p40"), - P50: []byte("p50"), - P60: []byte("p60"), - P70: []byte("p70"), - P80: []byte("p80"), - P90: []byte("p90"), - P95: []byte("p95"), - P99: []byte("p99"), - P999: []byte("p999"), - P9999: []byte("p9999"), - } res := make([][]byte, maxTypeID+1) - for t, bstr := range defaultTypeStrings { + for t, bstr := range typeStringNames { if override, exist := overrides[t]; exist { res[t.ID()] = override continue