Skip to content

Commit

Permalink
[coordinator] add graphite names to aggregation types (#2970)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyassrivatsan authored Dec 4, 2020
1 parent 25b1196 commit 9b5fbb9
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
8 changes: 4 additions & 4 deletions src/cmd/services/m3coordinator/downsample/downsampler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -742,7 +742,7 @@ func TestDownsamplerAggregationWithRulesConfigMappingRulesGraphitePrefixAndAggre
"__g1__": "counter",
"__g2__": "nginx_edge",
"__g3__": "health",
"__g4__": "Max",
"__g4__": "upper",
},
values: []expectedValue{{value: 30}},
attributes: &storagemetadata.Attributes{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
34 changes: 34 additions & 0 deletions src/metrics/aggregation/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
26 changes: 1 addition & 25 deletions src/metrics/aggregation/types_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9b5fbb9

Please sign in to comment.