From 2498a0dc9e7370c10e54d24ff5ee307845bcea73 Mon Sep 17 00:00:00 2001 From: brawndou <112038567+brawndou@users.noreply.github.com> Date: Tue, 16 Jan 2024 16:12:11 -0800 Subject: [PATCH] Revise internal cardinality metrics (#241) * update internal metrics impl * change scope counter name --- m3/example/m3_main.go | 5 +- m3/reporter.go | 8 ++- m3/reporter_integration_test.go | 1 + m3/reporter_test.go | 6 +-- m3/scope_test.go | 8 +-- scope.go | 33 +++++------- scope_registry.go | 69 +++++++++++++++++------- scope_registry_test.go | 94 +++++++++++++++++++++++---------- scope_test.go | 76 +++++++++++++------------- 9 files changed, 180 insertions(+), 120 deletions(-) diff --git a/m3/example/m3_main.go b/m3/example/m3_main.go index 34f11cb6..24bc64d3 100644 --- a/m3/example/m3_main.go +++ b/m3/example/m3_main.go @@ -1,4 +1,4 @@ -// Copyright (c) 2021 Uber Technologies, Inc. +// Copyright (c) 2024 Uber Technologies, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -87,7 +87,8 @@ func main() { } scope, closer := tally.NewRootScope(tally.ScopeOptions{ - CachedReporter: r, + CachedReporter: r, + CardinalityMetricsTags: cfg.M3.InternalTags, }, 1*time.Second) defer closer.Close() diff --git a/m3/reporter.go b/m3/reporter.go index 8b4f8f8f..32c0d429 100644 --- a/m3/reporter.go +++ b/m3/reporter.go @@ -1,4 +1,4 @@ -// Copyright (c) 2021 Uber Technologies, Inc. +// Copyright (c) 2024 Uber Technologies, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -66,8 +66,6 @@ const ( DefaultHistogramBucketIDName = "bucketid" // DefaultHistogramBucketName is the default histogram bucket name tag name DefaultHistogramBucketName = "bucket" - // DefaultTagRedactValue is the default tag value to use when redacting - DefaultTagRedactValue = "global" // DefaultHistogramBucketTagPrecision is the default // precision to use when formatting the metric tag // with the histogram bucket bound values. @@ -290,8 +288,8 @@ func NewReporter(opts Options) (Reporter, error) { internalTags := map[string]string{ "version": tally.Version, - "host": DefaultTagRedactValue, - "instance": DefaultTagRedactValue, + "host": tally.DefaultTagRedactValue, + "instance": tally.DefaultTagRedactValue, } for k, v := range opts.InternalTags { diff --git a/m3/reporter_integration_test.go b/m3/reporter_integration_test.go index 4ccfe586..bd4724b7 100644 --- a/m3/reporter_integration_test.go +++ b/m3/reporter_integration_test.go @@ -55,6 +55,7 @@ func main() { scope, closer := tally.NewRootScope(tally.ScopeOptions{ CachedReporter: r, + OmitCardinalityMetrics: true, }, 5 * time.Second) defer closer.Close() diff --git a/m3/reporter_test.go b/m3/reporter_test.go index 308debad..dc98060c 100644 --- a/m3/reporter_test.go +++ b/m3/reporter_test.go @@ -57,7 +57,7 @@ var ( var protocols = []Protocol{Compact, Binary} const internalMetrics = 5 // Additional metrics the reporter sends in a batch - use this, not a magic number. -const cardinalityMetrics = 3 // Additional metrics emitted by the scope registry. +const cardinalityMetrics = 4 // Additional metrics emitted by the scope registry. // TestReporter tests the reporter works as expected with both compact and binary protocols func TestReporter(t *testing.T) { @@ -601,8 +601,8 @@ func TestReporterCommmonTagsInternal(t *testing.T) { } // The following tags should be redacted. - require.True(t, tagEquals(metric.Tags, "host", DefaultTagRedactValue)) - require.True(t, tagEquals(metric.Tags, "instance", DefaultTagRedactValue)) + require.True(t, tagEquals(metric.Tags, "host", tally.DefaultTagRedactValue)) + require.True(t, tagEquals(metric.Tags, "instance", tally.DefaultTagRedactValue)) } else { require.Equal(t, "testCounter1", metric.Name) require.False(t, tagIncluded(metric.Tags, "internal1")) diff --git a/m3/scope_test.go b/m3/scope_test.go index 23bbaf99..a925019b 100644 --- a/m3/scope_test.go +++ b/m3/scope_test.go @@ -50,10 +50,10 @@ func newTestReporterScope( require.NoError(t, err) scope, closer := tally.NewRootScope(tally.ScopeOptions{ - Prefix: scopePrefix, - Tags: scopeTags, - CachedReporter: r, - MetricsOption: tally.SendInternalMetrics, + Prefix: scopePrefix, + Tags: scopeTags, + CachedReporter: r, + OmitCardinalityMetrics: false, }, shortInterval) return r, scope, func() { diff --git a/scope.go b/scope.go index 0b301040..9a6ee673 100644 --- a/scope.go +++ b/scope.go @@ -1,4 +1,4 @@ -// Copyright (c) 2023 Uber Technologies, Inc. +// Copyright (c) 2024 Uber Technologies, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -28,17 +28,7 @@ import ( "go.uber.org/atomic" ) -// InternalMetricOption is used to configure internal metrics. -type InternalMetricOption int - const ( - // Unset is the "no-op" config, which turns off internal metrics. - Unset InternalMetricOption = iota - // SendInternalMetrics turns on internal metrics submission. - SendInternalMetrics - // OmitInternalMetrics turns off internal metrics submission. - OmitInternalMetrics - _defaultInitialSliceSize = 16 _defaultReportingInterval = 2 * time.Second ) @@ -106,15 +96,16 @@ type scope struct { // ScopeOptions is a set of options to construct a scope. type ScopeOptions struct { - Tags map[string]string - Prefix string - Reporter StatsReporter - CachedReporter CachedStatsReporter - Separator string - DefaultBuckets Buckets - SanitizeOptions *SanitizeOptions - registryShardCount uint - MetricsOption InternalMetricOption + Tags map[string]string + Prefix string + Reporter StatsReporter + CachedReporter CachedStatsReporter + Separator string + DefaultBuckets Buckets + SanitizeOptions *SanitizeOptions + registryShardCount uint + OmitCardinalityMetrics bool + CardinalityMetricsTags map[string]string } // NewRootScope creates a new root Scope with a set of options and @@ -190,7 +181,7 @@ func newRootScope(opts ScopeOptions, interval time.Duration) *scope { s.tags = s.copyAndSanitizeMap(opts.Tags) // Register the root scope - s.registry = newScopeRegistryWithShardCount(s, opts.registryShardCount, opts.MetricsOption) + s.registry = newScopeRegistryWithShardCount(s, opts.registryShardCount, opts.OmitCardinalityMetrics, opts.CardinalityMetricsTags) if interval > 0 { s.wg.Add(1) diff --git a/scope_registry.go b/scope_registry.go index c52514db..ffa341da 100644 --- a/scope_registry.go +++ b/scope_registry.go @@ -1,4 +1,4 @@ -// Copyright (c) 2023 Uber Technologies, Inc. +// Copyright (c) 2024 Uber Technologies, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -33,10 +33,15 @@ var ( scopeRegistryKey = keyForPrefixedStringMaps // Metrics related. - internalTags = map[string]string{"version": Version} - counterCardinalityName = "tally_internal_counter_cardinality" - gaugeCardinalityName = "tally_internal_gauge_cardinality" - histogramCardinalityName = "tally_internal_histogram_cardinality" + counterCardinalityName = "tally.internal.counter_cardinality" + gaugeCardinalityName = "tally.internal.gauge_cardinality" + histogramCardinalityName = "tally.internal.histogram_cardinality" + scopeCardinalityName = "tally.internal.num_active_scopes" +) + +const ( + // DefaultTagRedactValue is the default tag value to use when redacting + DefaultTagRedactValue = "global" ) type scopeRegistry struct { @@ -45,10 +50,16 @@ type scopeRegistry struct { // We need a subscope per GOPROC so that we can take advantage of all the cpu available to the application. subscopes []*scopeBucket // Internal metrics related. - internalMetricsOption InternalMetricOption + omitCardinalityMetrics bool + cardinalityMetricsTags map[string]string sanitizedCounterCardinalityName string sanitizedGaugeCardinalityName string sanitizedHistogramCardinalityName string + sanitizedScopeCardinalityName string + cachedCounterCardinalityGauge CachedGauge + cachedGaugeCardinalityGauge CachedGauge + cachedHistogramCardinalityGauge CachedGauge + cachedScopeCardinalityGauge CachedGauge } type scopeBucket struct { @@ -59,7 +70,8 @@ type scopeBucket struct { func newScopeRegistryWithShardCount( root *scope, shardCount uint, - internalMetricsOption InternalMetricOption, + omitCardinalityMetrics bool, + cardinalityMetricsTags map[string]string, ) *scopeRegistry { if shardCount == 0 { shardCount = uint(runtime.GOMAXPROCS(-1)) @@ -69,17 +81,34 @@ func newScopeRegistryWithShardCount( root: root, subscopes: make([]*scopeBucket, shardCount), seed: maphash.MakeSeed(), - internalMetricsOption: internalMetricsOption, + omitCardinalityMetrics: omitCardinalityMetrics, sanitizedCounterCardinalityName: root.sanitizer.Name(counterCardinalityName), sanitizedGaugeCardinalityName: root.sanitizer.Name(gaugeCardinalityName), sanitizedHistogramCardinalityName: root.sanitizer.Name(histogramCardinalityName), + sanitizedScopeCardinalityName: root.sanitizer.Name(scopeCardinalityName), + cardinalityMetricsTags: map[string]string{ + "version": Version, + "host": DefaultTagRedactValue, + "instance": DefaultTagRedactValue, + }, + } + + for k, v := range cardinalityMetricsTags { + r.cardinalityMetricsTags[root.sanitizer.Key(k)] = root.sanitizer.Value(v) } + for i := uint(0); i < shardCount; i++ { r.subscopes[i] = &scopeBucket{ s: make(map[string]*scope), } r.subscopes[i].s[scopeRegistryKey(root.prefix, root.tags)] = root } + if r.root.cachedReporter != nil { + r.cachedCounterCardinalityGauge = r.root.cachedReporter.AllocateGauge(r.sanitizedCounterCardinalityName, r.cardinalityMetricsTags) + r.cachedGaugeCardinalityGauge = r.root.cachedReporter.AllocateGauge(r.sanitizedGaugeCardinalityName, r.cardinalityMetricsTags) + r.cachedHistogramCardinalityGauge = r.root.cachedReporter.AllocateGauge(r.sanitizedHistogramCardinalityName, r.cardinalityMetricsTags) + r.cachedScopeCardinalityGauge = r.root.cachedReporter.AllocateGauge(r.sanitizedScopeCardinalityName, r.cardinalityMetricsTags) + } return r } @@ -237,12 +266,13 @@ func (r *scopeRegistry) removeWithRLock(subscopeBucket *scopeBucket, key string) // Records internal Metrics' cardinalities. func (r *scopeRegistry) reportInternalMetrics() { - if r.internalMetricsOption != SendInternalMetrics { + if r.omitCardinalityMetrics { return } - counters, gauges, histograms := atomic.Int64{}, atomic.Int64{}, atomic.Int64{} + counters, gauges, histograms, scopes := atomic.Int64{}, atomic.Int64{}, atomic.Int64{}, atomic.Int64{} rootCounters, rootGauges, rootHistograms := atomic.Int64{}, atomic.Int64{}, atomic.Int64{} + scopes.Inc() // Account for root scope. r.ForEachScope( func(ss *scope) { counterSliceLen, gaugeSliceLen, histogramSliceLen := int64(len(ss.countersSlice)), int64(len(ss.gaugesSlice)), int64(len(ss.histogramsSlice)) @@ -255,25 +285,24 @@ func (r *scopeRegistry) reportInternalMetrics() { counters.Add(counterSliceLen) gauges.Add(gaugeSliceLen) histograms.Add(histogramSliceLen) + scopes.Inc() }, ) counters.Add(rootCounters.Load()) gauges.Add(rootGauges.Load()) histograms.Add(rootHistograms.Load()) - if r.root.reporter != nil { - r.root.reporter.ReportCounter(r.sanitizedCounterCardinalityName, internalTags, counters.Load()) - r.root.reporter.ReportCounter(r.sanitizedGaugeCardinalityName, internalTags, gauges.Load()) - r.root.reporter.ReportCounter(r.sanitizedHistogramCardinalityName, internalTags, histograms.Load()) + r.root.reporter.ReportGauge(r.sanitizedCounterCardinalityName, r.cardinalityMetricsTags, float64(counters.Load())) + r.root.reporter.ReportGauge(r.sanitizedGaugeCardinalityName, r.cardinalityMetricsTags, float64(gauges.Load())) + r.root.reporter.ReportGauge(r.sanitizedHistogramCardinalityName, r.cardinalityMetricsTags, float64(histograms.Load())) + r.root.reporter.ReportGauge(r.sanitizedScopeCardinalityName, r.cardinalityMetricsTags, float64(scopes.Load())) } if r.root.cachedReporter != nil { - numCounters := r.root.cachedReporter.AllocateCounter(r.sanitizedCounterCardinalityName, internalTags) - numGauges := r.root.cachedReporter.AllocateCounter(r.sanitizedGaugeCardinalityName, internalTags) - numHistograms := r.root.cachedReporter.AllocateCounter(r.sanitizedHistogramCardinalityName, internalTags) - numCounters.ReportCount(counters.Load()) - numGauges.ReportCount(gauges.Load()) - numHistograms.ReportCount(histograms.Load()) + r.cachedCounterCardinalityGauge.ReportGauge(float64(counters.Load())) + r.cachedGaugeCardinalityGauge.ReportGauge(float64(gauges.Load())) + r.cachedHistogramCardinalityGauge.ReportGauge(float64(histograms.Load())) + r.cachedScopeCardinalityGauge.ReportGauge(float64(scopes.Load())) } } diff --git a/scope_registry_test.go b/scope_registry_test.go index 63bea579..0a36d0c1 100644 --- a/scope_registry_test.go +++ b/scope_registry_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2023 Uber Technologies, Inc. +// Copyright (c) 2024 Uber Technologies, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -28,7 +28,7 @@ import ( ) var ( - numInternalMetrics = 3 + numInternalMetrics = 4 ) func TestVerifyCachedTaggedScopesAlloc(t *testing.T) { @@ -53,21 +53,49 @@ func TestVerifyCachedTaggedScopesAlloc(t *testing.T) { assert.True(t, allocs <= expected, "the cached tagged scopes should allocate at most %.0f allocations, but did allocate %.0f", expected, allocs) } +func TestVerifyOmitCardinalityMetricsTags(t *testing.T) { + r := newTestStatsReporter() + _, closer := NewRootScope(ScopeOptions{ + Reporter: r, + OmitCardinalityMetrics: false, + CardinalityMetricsTags: map[string]string{ + "cardinality_tag_key": "cardinality_tag_value", + }, + }, 0) + wantOmitCardinalityMetricsTags := map[string]string{ + "cardinality_tag_key": "cardinality_tag_value", + "version": Version, + "host": "global", + "instance": "global", + } + + r.gg.Add(numInternalMetrics) + closer.Close() + r.WaitAll() + + assert.NotNil(t, r.gauges[counterCardinalityName], "counter cardinality should not be nil") + assert.Equal( + t, wantOmitCardinalityMetricsTags, r.gauges[counterCardinalityName].tags, "expected tags %v, got tags %v", + wantOmitCardinalityMetricsTags, r.gauges[counterCardinalityName].tags, + ) +} + func TestNewTestStatsReporterOneScope(t *testing.T) { r := newTestStatsReporter() - root, closer := NewRootScope(ScopeOptions{Reporter: r, MetricsOption: SendInternalMetrics}, 0) + root, closer := NewRootScope(ScopeOptions{Reporter: r, OmitCardinalityMetrics: false}, 0) s := root.(*scope) numFakeCounters := 3 numFakeGauges := 5 numFakeHistograms := 11 + numScopes := 1 - r.cg.Add(numFakeCounters + numInternalMetrics) + r.cg.Add(numFakeCounters) for c := 1; c <= numFakeCounters; c++ { s.Counter(fmt.Sprintf("counter-%d", c)).Inc(int64(c)) } - r.gg.Add(numFakeGauges) + r.gg.Add(numFakeGauges + numInternalMetrics) for g := 1; g <= numFakeGauges; g++ { s.Gauge(fmt.Sprintf("gauge_%d", g)).Update(float64(g)) } @@ -80,35 +108,41 @@ func TestNewTestStatsReporterOneScope(t *testing.T) { closer.Close() r.WaitAll() - assert.NotNil(t, r.counters[counterCardinalityName], "counter cardinality should not be nil") + assert.NotNil(t, r.gauges[counterCardinalityName], "counter cardinality should not be nil") + assert.Equal( + t, numFakeCounters, int(r.gauges[counterCardinalityName].val), "expected %d counters, got %d counters", + numFakeCounters, r.gauges[counterCardinalityName].val, + ) + + assert.NotNil(t, r.gauges[gaugeCardinalityName], "gauge cardinality should not be nil") assert.Equal( - t, int64(numFakeCounters), r.counters[counterCardinalityName].val, "expected %d counters, got %d counters", - numFakeCounters, r.counters[counterCardinalityName].val, + t, numFakeGauges, int(r.gauges[gaugeCardinalityName].val), "expected %d gauges, got %d gauges", + numFakeGauges, r.gauges[gaugeCardinalityName].val, ) - assert.NotNil(t, r.counters[gaugeCardinalityName], "gauge cardinality should not be nil") + assert.NotNil(t, r.gauges[histogramCardinalityName], "histogram cardinality should not be nil") assert.Equal( - t, int64(numFakeGauges), r.counters[gaugeCardinalityName].val, "expected %d gauges, got %d gauges", - numFakeGauges, r.counters[gaugeCardinalityName].val, + t, numFakeHistograms, int(r.gauges[histogramCardinalityName].val), + "expected %d histograms, got %d histograms", numFakeHistograms, r.gauges[histogramCardinalityName].val, ) - assert.NotNil(t, r.counters[histogramCardinalityName], "histogram cardinality should not be nil") + assert.NotNil(t, r.gauges[scopeCardinalityName], "scope cardinality should not be nil") assert.Equal( - t, int64(numFakeHistograms), r.counters[histogramCardinalityName].val, - "expected %d histograms, got %d histograms", numFakeHistograms, r.counters[histogramCardinalityName].val, + t, numScopes, int(r.gauges[scopeCardinalityName].val), "expected %d scopes, got %d scopes", + numScopes, r.gauges[scopeCardinalityName].val, ) } func TestNewTestStatsReporterManyScopes(t *testing.T) { r := newTestStatsReporter() - root, closer := NewRootScope(ScopeOptions{Reporter: r, MetricsOption: SendInternalMetrics}, 0) - wantCounters, wantGauges, wantHistograms := int64(3), int64(2), int64(1) + root, closer := NewRootScope(ScopeOptions{Reporter: r, OmitCardinalityMetrics: false}, 0) + wantCounters, wantGauges, wantHistograms, wantScopes := 3, 2, 1, 2 s := root.(*scope) - r.cg.Add(2 + numInternalMetrics) + r.cg.Add(2) s.Counter("counter-foo").Inc(1) s.Counter("counter-bar").Inc(2) - r.gg.Add(1) + r.gg.Add(1 + numInternalMetrics) s.Gauge("gauge-foo").Update(3) r.hg.Add(1) s.Histogram("histogram-foo", MustMakeLinearValueBuckets(0, 1, 10)).RecordValue(4) @@ -122,22 +156,28 @@ func TestNewTestStatsReporterManyScopes(t *testing.T) { closer.Close() r.WaitAll() - assert.NotNil(t, r.counters[counterCardinalityName], "counter cardinality should not be nil") + assert.NotNil(t, r.gauges[counterCardinalityName], "counter cardinality should not be nil") + assert.Equal( + t, wantCounters, int(r.gauges[counterCardinalityName].val), "expected %d counters, got %d counters", wantCounters, + r.gauges[counterCardinalityName].val, + ) + + assert.NotNil(t, r.gauges[gaugeCardinalityName], "gauge cardinality should not be nil") assert.Equal( - t, wantCounters, r.counters[counterCardinalityName].val, "expected %d counters, got %d counters", wantCounters, - r.counters[counterCardinalityName].val, + t, wantGauges, int(r.gauges[gaugeCardinalityName].val), "expected %d gauges, got %d gauges", wantGauges, + r.gauges[gaugeCardinalityName].val, ) - assert.NotNil(t, r.counters[gaugeCardinalityName], "gauge cardinality should not be nil") + assert.NotNil(t, r.gauges[histogramCardinalityName], "histogram cardinality should not be nil") assert.Equal( - t, wantGauges, r.counters[gaugeCardinalityName].val, "expected %d counters, got %d gauges", wantGauges, - r.counters[gaugeCardinalityName].val, + t, wantHistograms, int(r.gauges[histogramCardinalityName].val), "expected %d histograms, got %d histograms", + wantHistograms, r.gauges[histogramCardinalityName].val, ) - assert.NotNil(t, r.counters[histogramCardinalityName], "histogram cardinality should not be nil") + assert.NotNil(t, r.gauges[scopeCardinalityName], "scope cardinality should not be nil") assert.Equal( - t, wantHistograms, r.counters[histogramCardinalityName].val, "expected %d counters, got %d histograms", - wantHistograms, r.counters[histogramCardinalityName].val, + t, wantScopes, int(r.gauges[scopeCardinalityName].val), "expected %d scopes, got %d scopes", + wantScopes, r.gauges[scopeCardinalityName].val, ) } diff --git a/scope_test.go b/scope_test.go index a439576d..eb1a8797 100644 --- a/scope_test.go +++ b/scope_test.go @@ -360,7 +360,7 @@ func (r *testStatsReporter) Flush() { func TestWriteTimerImmediately(t *testing.T) { r := newTestStatsReporter() - s, closer := NewRootScope(ScopeOptions{Reporter: r, MetricsOption: OmitInternalMetrics}, 0) + s, closer := NewRootScope(ScopeOptions{Reporter: r, OmitCardinalityMetrics: true}, 0) defer closer.Close() r.tg.Add(1) s.Timer("ticky").Record(time.Millisecond * 175) @@ -369,7 +369,7 @@ func TestWriteTimerImmediately(t *testing.T) { func TestWriteTimerClosureImmediately(t *testing.T) { r := newTestStatsReporter() - s, closer := NewRootScope(ScopeOptions{Reporter: r, MetricsOption: OmitInternalMetrics}, 0) + s, closer := NewRootScope(ScopeOptions{Reporter: r, OmitCardinalityMetrics: true}, 0) defer closer.Close() r.tg.Add(1) tm := s.Timer("ticky") @@ -379,7 +379,7 @@ func TestWriteTimerClosureImmediately(t *testing.T) { func TestWriteReportLoop(t *testing.T) { r := newTestStatsReporter() - s, closer := NewRootScope(ScopeOptions{Reporter: r, MetricsOption: OmitInternalMetrics}, 10) + s, closer := NewRootScope(ScopeOptions{Reporter: r, OmitCardinalityMetrics: true}, 10) defer closer.Close() r.cg.Add(1) @@ -398,7 +398,7 @@ func TestWriteReportLoop(t *testing.T) { func TestWriteReportLoopDefaultInterval(t *testing.T) { r := newTestStatsReporter() s, closer := NewRootScopeWithDefaultInterval( - ScopeOptions{Reporter: r, MetricsOption: OmitInternalMetrics}, + ScopeOptions{Reporter: r, OmitCardinalityMetrics: true}, ) defer closer.Close() @@ -417,7 +417,7 @@ func TestWriteReportLoopDefaultInterval(t *testing.T) { func TestCachedReportLoop(t *testing.T) { r := newTestStatsReporter() - s, closer := NewRootScope(ScopeOptions{CachedReporter: r, MetricsOption: OmitInternalMetrics}, 10) + s, closer := NewRootScope(ScopeOptions{CachedReporter: r, OmitCardinalityMetrics: true}, 10) defer closer.Close() r.cg.Add(1) @@ -435,9 +435,9 @@ func TestCachedReportLoop(t *testing.T) { func testReportLoopFlushOnce(t *testing.T, cached bool) { r := newTestStatsReporter() - scopeOpts := ScopeOptions{CachedReporter: r, MetricsOption: OmitInternalMetrics} + scopeOpts := ScopeOptions{CachedReporter: r, OmitCardinalityMetrics: true} if !cached { - scopeOpts = ScopeOptions{Reporter: r, MetricsOption: OmitInternalMetrics} + scopeOpts = ScopeOptions{Reporter: r, OmitCardinalityMetrics: true} } s, closer := NewRootScope(scopeOpts, 10*time.Minute) @@ -475,7 +475,7 @@ func TestReporterFlushOnce(t *testing.T) { func TestWriteOnce(t *testing.T) { r := newTestStatsReporter() - root, closer := NewRootScope(ScopeOptions{Reporter: r, MetricsOption: OmitInternalMetrics}, 0) + root, closer := NewRootScope(ScopeOptions{Reporter: r, OmitCardinalityMetrics: true}, 0) defer closer.Close() s := root.(*scope) @@ -546,10 +546,10 @@ func TestHistogramSharedBucketMetrics(t *testing.T) { var ( r = newTestStatsReporter() scope = newRootScope(ScopeOptions{ - Prefix: "", - Tags: nil, - CachedReporter: r, - MetricsOption: OmitInternalMetrics, + Prefix: "", + Tags: nil, + CachedReporter: r, + OmitCardinalityMetrics: true, }, 0) builder = func(s Scope) func(map[string]string) { buckets := MustMakeLinearValueBuckets(10, 10, 3) @@ -620,10 +620,10 @@ func TestConcurrentUpdates(t *testing.T) { counterIncrs = 5000 rs = newRootScope( ScopeOptions{ - Prefix: "", - Tags: nil, - CachedReporter: r, - MetricsOption: OmitInternalMetrics, + Prefix: "", + Tags: nil, + CachedReporter: r, + OmitCardinalityMetrics: true, }, 0, ) scopes = []Scope{rs} @@ -669,9 +669,9 @@ func TestCounterSanitized(t *testing.T) { r := newTestStatsReporter() root, closer := NewRootScope(ScopeOptions{ - Reporter: r, - SanitizeOptions: &alphanumericSanitizerOpts, - MetricsOption: OmitInternalMetrics, + Reporter: r, + SanitizeOptions: &alphanumericSanitizerOpts, + OmitCardinalityMetrics: true, }, 0) defer closer.Close() @@ -727,7 +727,7 @@ func TestCounterSanitized(t *testing.T) { func TestCachedReporter(t *testing.T) { r := newTestStatsReporter() - root, closer := NewRootScope(ScopeOptions{CachedReporter: r, MetricsOption: OmitInternalMetrics}, 0) + root, closer := NewRootScope(ScopeOptions{CachedReporter: r, OmitCardinalityMetrics: true}, 0) defer closer.Close() s := root.(*scope) @@ -764,7 +764,7 @@ func TestCachedReporter(t *testing.T) { func TestRootScopeWithoutPrefix(t *testing.T) { r := newTestStatsReporter() - root, closer := NewRootScope(ScopeOptions{Reporter: r, MetricsOption: OmitInternalMetrics}, 0) + root, closer := NewRootScope(ScopeOptions{Reporter: r, OmitCardinalityMetrics: true}, 0) defer closer.Close() s := root.(*scope) @@ -799,7 +799,7 @@ func TestRootScopeWithPrefix(t *testing.T) { r := newTestStatsReporter() root, closer := NewRootScope( - ScopeOptions{Prefix: "foo", Reporter: r, MetricsOption: OmitInternalMetrics}, 0, + ScopeOptions{Prefix: "foo", Reporter: r, OmitCardinalityMetrics: true}, 0, ) defer closer.Close() @@ -836,7 +836,7 @@ func TestRootScopeWithDifferentSeparator(t *testing.T) { root, closer := NewRootScope( ScopeOptions{ - Prefix: "foo", Separator: "_", Reporter: r, MetricsOption: OmitInternalMetrics, + Prefix: "foo", Separator: "_", Reporter: r, OmitCardinalityMetrics: true, }, 0, ) defer closer.Close() @@ -873,7 +873,7 @@ func TestSubScope(t *testing.T) { r := newTestStatsReporter() root, closer := NewRootScope( - ScopeOptions{Prefix: "foo", Reporter: r, MetricsOption: OmitInternalMetrics}, 0, + ScopeOptions{Prefix: "foo", Reporter: r, OmitCardinalityMetrics: true}, 0, ) defer closer.Close() @@ -916,7 +916,7 @@ func TestSubScope(t *testing.T) { func TestSubScopeClose(t *testing.T) { r := newTestStatsReporter() - rs, closer := NewRootScope(ScopeOptions{Prefix: "foo", Reporter: r, MetricsOption: OmitInternalMetrics}, 0) + rs, closer := NewRootScope(ScopeOptions{Prefix: "foo", Reporter: r, OmitCardinalityMetrics: true}, 0) // defer closer.Close() _ = closer @@ -1009,7 +1009,7 @@ func TestTaggedSubScope(t *testing.T) { ts := map[string]string{"env": "test"} root, closer := NewRootScope( ScopeOptions{ - Prefix: "foo", Tags: ts, Reporter: r, MetricsOption: OmitInternalMetrics, + Prefix: "foo", Tags: ts, Reporter: r, OmitCardinalityMetrics: true, }, 0, ) defer closer.Close() @@ -1067,11 +1067,11 @@ func TestTaggedSanitizedSubScope(t *testing.T) { ts := map[string]string{"env": "test:env"} root, closer := NewRootScope(ScopeOptions{ - Prefix: "foo", - Tags: ts, - Reporter: r, - SanitizeOptions: &alphanumericSanitizerOpts, - MetricsOption: OmitInternalMetrics, + Prefix: "foo", + Tags: ts, + Reporter: r, + SanitizeOptions: &alphanumericSanitizerOpts, + OmitCardinalityMetrics: true, }, 0) defer closer.Close() s := root.(*scope) @@ -1104,7 +1104,7 @@ func TestTaggedExistingReturnsSameScope(t *testing.T) { } { root, closer := NewRootScope( ScopeOptions{ - Prefix: "foo", Tags: initialTags, Reporter: r, MetricsOption: OmitInternalMetrics, + Prefix: "foo", Tags: initialTags, Reporter: r, OmitCardinalityMetrics: true, }, 0, ) defer closer.Close() @@ -1224,7 +1224,7 @@ func TestSnapshotConcurrent(t *testing.T) { func TestCapabilities(t *testing.T) { r := newTestStatsReporter() - s, closer := NewRootScope(ScopeOptions{Reporter: r, MetricsOption: OmitInternalMetrics}, 0) + s, closer := NewRootScope(ScopeOptions{Reporter: r, OmitCardinalityMetrics: true}, 0) defer closer.Close() assert.True(t, s.Capabilities().Reporting()) assert.False(t, s.Capabilities().Tagging()) @@ -1252,8 +1252,8 @@ func TestScopeDefaultBuckets(t *testing.T) { 90 * time.Millisecond, 120 * time.Millisecond, }, - Reporter: r, - MetricsOption: OmitInternalMetrics, + Reporter: r, + OmitCardinalityMetrics: true, }, 0) defer closer.Close() @@ -1284,7 +1284,7 @@ func newTestMets(scope Scope) testMets { func TestReturnByValue(t *testing.T) { r := newTestStatsReporter() - root, closer := NewRootScope(ScopeOptions{Reporter: r, MetricsOption: OmitInternalMetrics}, 0) + root, closer := NewRootScope(ScopeOptions{Reporter: r, OmitCardinalityMetrics: true}, 0) defer closer.Close() s := root.(*scope) @@ -1301,7 +1301,7 @@ func TestReturnByValue(t *testing.T) { func TestScopeAvoidReportLoopRunOnClose(t *testing.T) { r := newTestStatsReporter() - root, closer := NewRootScope(ScopeOptions{Reporter: r, MetricsOption: OmitInternalMetrics}, 0) + root, closer := NewRootScope(ScopeOptions{Reporter: r, OmitCardinalityMetrics: true}, 0) s := root.(*scope) s.reportLoopRun() @@ -1316,7 +1316,7 @@ func TestScopeAvoidReportLoopRunOnClose(t *testing.T) { func TestScopeFlushOnClose(t *testing.T) { r := newTestStatsReporter() - root, closer := NewRootScope(ScopeOptions{Reporter: r, MetricsOption: OmitInternalMetrics}, time.Hour) + root, closer := NewRootScope(ScopeOptions{Reporter: r, OmitCardinalityMetrics: true}, time.Hour) r.cg.Add(1) root.Counter("foo").Inc(1)