diff --git a/internal/api/handler_easyjson.go b/internal/api/handler_easyjson.go index 70cbd42c5..7a188e9fc 100644 --- a/internal/api/handler_easyjson.go +++ b/internal/api/handler_easyjson.go @@ -480,6 +480,8 @@ func easyjson888c126aDecodeGithubComVkcomStatshouseInternalFormat(in *jlexer.Lex out.SkipSumSquare = bool(in.Bool()) case "pre_key_only": out.PreKeyOnly = bool(in.Bool()) + case "metric_type": + out.MetricType = string(in.String()) default: in.SkipRecursive() } @@ -598,6 +600,11 @@ func easyjson888c126aEncodeGithubComVkcomStatshouseInternalFormat(out *jwriter.W out.RawString(prefix) out.Bool(bool(in.PreKeyOnly)) } + { + const prefix string = ",\"metric_type\":" + out.RawString(prefix) + out.String(string(in.MetricType)) + } out.RawByte('}') } func easyjson888c126aDecodeGithubComVkcomStatshouseInternalFormat1(in *jlexer.Lexer, out *format.MetricMetaTag) { diff --git a/internal/format/format.go b/internal/format/format.go index fa67df4ca..2078968db 100644 --- a/internal/format/format.go +++ b/internal/format/format.go @@ -68,6 +68,24 @@ const ( MetricKindMixedPercentiles = "mixed_p" ) +const ( + MetricSecond = "second" + MetricMillisecond = "millisecond" + MetricMicrosecond = "microsecond" + MetricNanosecond = "nanosecond" + + MetricByte = "byte" + /* + MetricBit = "bit" + MetricKilobyte = "kilobyte" + MetricMegabyte = "megabyte" + MetricGigabyte = "gigabyte" + + MetricKibibyte = "kibibyte" + MetricMebibyte = "mebibyte" + */ +) + // Legacy, left for API backward compatibility const ( LegacyStringTopTagID = "skey" @@ -187,6 +205,7 @@ type MetricMetaValue struct { SkipMinHost bool `json:"skip_min_host,omitempty"` SkipSumSquare bool `json:"skip_sum_square,omitempty"` PreKeyOnly bool `json:"pre_key_only,omitempty"` + MetricType string `json:"metric_type"` RawTagMask uint32 `json:"-"` // Should be restored from Tags after reading Name2Tag map[string]MetricMetaTag `json:"-"` // Should be restored from Tags after reading @@ -285,6 +304,10 @@ func (m *MetricMetaValue) RestoreCachedInfo() error { if !ValidMetricName(mem.S(m.Name)) { err = multierr.Append(err, fmt.Errorf("invalid metric name: %q", m.Name)) } + if !IsValidMetricType(m.MetricType) { + err = multierr.Append(err, fmt.Errorf("invalid metric type: %s", m.MetricType)) + m.MetricType = "" + } if m.Kind == legacyMetricKindStringTop { m.Kind = MetricKindCounter @@ -902,3 +925,11 @@ func ISO8601Date2BuildDateKey(str string) int32 { } return int32(n) // Will always fit } + +func IsValidMetricType(typ_ string) bool { + switch typ_ { + case MetricSecond, MetricMillisecond, MetricMicrosecond, MetricNanosecond, MetricByte, "": + return true + } + return false +}