Skip to content

Commit

Permalink
[api] add miltierr (#729)
Browse files Browse the repository at this point in the history
  • Loading branch information
nevgeny authored Sep 1, 2023
1 parent 202f014 commit fde5fe2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/api/handler_easyjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions internal/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit fde5fe2

Please sign in to comment.