Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api] add metric_type #729

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}