From e863db03445ff6094e8f81b8ede724116d11dfdd Mon Sep 17 00:00:00 2001 From: Lance Liu Date: Wed, 15 Jul 2020 16:29:32 +0800 Subject: [PATCH] Remove key in tags to reduce metrics count (#1494) * Remove key in tags to reduce metrics count Issue: https://github.com/knative/serving/issues/8609 Signed-off-by: Lance Liu * remove tag key for OpenCensus Signed-off-by: Lance Liu --- controller/controller.go | 2 +- controller/stats_reporter.go | 10 ++++------ controller/stats_reporter_test.go | 5 ++--- controller/testing/fake_stats_reporter.go | 8 ++++---- controller/testing/fake_stats_reporter_test.go | 4 ++-- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/controller/controller.go b/controller/controller.go index 6024ec253..03f67b6ec 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -452,7 +452,7 @@ func (c *Impl) processNextWorkItem() bool { if err != nil { status = falseString } - c.statsReporter.ReportReconcile(time.Since(startTime), keyStr, status) + c.statsReporter.ReportReconcile(time.Since(startTime), status) }() // Embed the key into the logger and attach that to the context we pass diff --git a/controller/stats_reporter.go b/controller/stats_reporter.go index c3445ed3d..6efaeca0f 100644 --- a/controller/stats_reporter.go +++ b/controller/stats_reporter.go @@ -46,7 +46,6 @@ var ( // - length between 1 and 255 inclusive // - characters are printable US-ASCII reconcilerTagKey = tag.MustNewKey("reconciler") - keyTagKey = tag.MustNewKey("key") successTagKey = tag.MustNewKey("success") ) @@ -167,12 +166,12 @@ func init() { Description: "Number of reconcile operations", Measure: reconcileCountStat, Aggregation: view.Count(), - TagKeys: []tag.Key{reconcilerTagKey, keyTagKey, successTagKey}, + TagKeys: []tag.Key{reconcilerTagKey, successTagKey}, }, { Description: "Latency of reconcile operations", Measure: reconcileLatencyStat, Aggregation: reconcileDistribution, - TagKeys: []tag.Key{reconcilerTagKey, keyTagKey, successTagKey}, + TagKeys: []tag.Key{reconcilerTagKey, successTagKey}, }} views = append(views, wp.DefaultViews()...) views = append(views, rp.DefaultViews()...) @@ -192,7 +191,7 @@ type StatsReporter interface { ReportQueueDepth(v int64) error // ReportReconcile reports the count and latency metrics for a reconcile operation - ReportReconcile(duration time.Duration, key, success string) error + ReportReconcile(duration time.Duration, success string) error } // Reporter holds cached metric objects to report metrics @@ -234,11 +233,10 @@ func (r *reporter) ReportQueueDepth(v int64) error { } // ReportReconcile reports the count and latency metrics for a reconcile operation -func (r *reporter) ReportReconcile(duration time.Duration, key, success string) error { +func (r *reporter) ReportReconcile(duration time.Duration, success string) error { ctx, err := tag.New( context.Background(), tag.Insert(reconcilerTagKey, r.reconciler), - tag.Insert(keyTagKey, key), tag.Insert(successTagKey, success)) if err != nil { return err diff --git a/controller/stats_reporter_test.go b/controller/stats_reporter_test.go index d82e7fe35..ff56d99a3 100644 --- a/controller/stats_reporter_test.go +++ b/controller/stats_reporter_test.go @@ -68,7 +68,6 @@ func TestReportReconcile(t *testing.T) { r, _ := NewStatsReporter("testreconciler") wantTags := map[string]string{ "reconciler": "testreconciler", - "key": "test/key", "success": "true", } @@ -81,11 +80,11 @@ func TestReportReconcile(t *testing.T) { initialReconcileLatency = d[0].Data.(*view.DistributionData).Sum() } - expectSuccess(t, func() error { return r.ReportReconcile(10*time.Millisecond, "test/key", "true") }) + expectSuccess(t, func() error { return r.ReportReconcile(10*time.Millisecond, "true") }) metricstest.CheckCountData(t, "reconcile_count", wantTags, initialReconcileCount+1) metricstest.CheckDistributionData(t, "reconcile_latency", wantTags, 1, initialReconcileLatency+10, initialReconcileLatency+10) - expectSuccess(t, func() error { return r.ReportReconcile(15*time.Millisecond, "test/key", "true") }) + expectSuccess(t, func() error { return r.ReportReconcile(15*time.Millisecond, "true") }) metricstest.CheckCountData(t, "reconcile_count", wantTags, initialReconcileCount+2) metricstest.CheckDistributionData(t, "reconcile_latency", wantTags, 2, initialReconcileLatency+10, initialReconcileLatency+15) } diff --git a/controller/testing/fake_stats_reporter.go b/controller/testing/fake_stats_reporter.go index 506754dc1..528a854b3 100644 --- a/controller/testing/fake_stats_reporter.go +++ b/controller/testing/fake_stats_reporter.go @@ -30,8 +30,8 @@ type FakeStatsReporter struct { // FakeReconcileStatData is used to record the calls to ReportReconcile type FakeReconcileStatData struct { - Duration time.Duration - Key, Success string + Duration time.Duration + Success string } // ReportQueueDepth records the call and returns success. @@ -43,10 +43,10 @@ func (r *FakeStatsReporter) ReportQueueDepth(v int64) error { } // ReportReconcile records the call and returns success. -func (r *FakeStatsReporter) ReportReconcile(duration time.Duration, key, success string) error { +func (r *FakeStatsReporter) ReportReconcile(duration time.Duration, success string) error { r.Lock.Lock() defer r.Lock.Unlock() - r.reconcileData = append(r.reconcileData, FakeReconcileStatData{duration, key, success}) + r.reconcileData = append(r.reconcileData, FakeReconcileStatData{duration, success}) return nil } diff --git a/controller/testing/fake_stats_reporter_test.go b/controller/testing/fake_stats_reporter_test.go index dc2f894df..8fde1c7e4 100644 --- a/controller/testing/fake_stats_reporter_test.go +++ b/controller/testing/fake_stats_reporter_test.go @@ -38,8 +38,8 @@ func TestReportQueueDepth(t *testing.T) { func TestReportReconcile(t *testing.T) { r := &FakeStatsReporter{} - r.ReportReconcile(time.Duration(123), "testkey", "False") - if got, want := r.GetReconcileData(), []FakeReconcileStatData{{time.Duration(123), "testkey", "False"}}; !reflect.DeepEqual(want, got) { + r.ReportReconcile(time.Duration(123), "False") + if got, want := r.GetReconcileData(), []FakeReconcileStatData{{time.Duration(123), "False"}}; !reflect.DeepEqual(want, got) { t.Errorf("reconcile data len: want: %v, got: %v", want, got) } }