mirror of https://github.com/knative/pkg.git
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 <xuliuxl@cn.ibm.com> * remove tag key for OpenCensus Signed-off-by: Lance Liu <xuliuxl@cn.ibm.com>
This commit is contained in:
parent
cb1281d05c
commit
e863db0344
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue