From b08c31d5c34c35ae34e048b55f49b5af29904474 Mon Sep 17 00:00:00 2001 From: Yevgeniy Miretskiy Date: Sat, 30 Oct 2021 08:27:40 -0400 Subject: [PATCH] changefeedccl: Move metrics scope library under changefeedccl package. Move metrics scope library out of cdcutil directly under changefeedccl. Metrics scope is not much of a library since it's specific to changefeedccl. Note: this is a move only refactoring, but it is structured as 2 changes (one to add new files, and one to remove cdcutils files) so that it can be easily backported. Release Notes: None --- pkg/ccl/changefeedccl/BUILD.bazel | 3 + pkg/ccl/changefeedccl/metrics_scope.go | 77 +++++++++++++++++++++ pkg/ccl/changefeedccl/metrics_scope_test.go | 57 +++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 pkg/ccl/changefeedccl/metrics_scope.go create mode 100644 pkg/ccl/changefeedccl/metrics_scope_test.go diff --git a/pkg/ccl/changefeedccl/BUILD.bazel b/pkg/ccl/changefeedccl/BUILD.bazel index 14bbc91e56f3..ad6d298d400f 100644 --- a/pkg/ccl/changefeedccl/BUILD.bazel +++ b/pkg/ccl/changefeedccl/BUILD.bazel @@ -11,6 +11,7 @@ go_library( "doc.go", "encoder.go", "metrics.go", + "metrics_scope.go", "name.go", "rowfetcher_cache.go", "schema_registry.go", @@ -122,6 +123,7 @@ go_test( "helpers_tenant_shim_test.go", "helpers_test.go", "main_test.go", + "metrics_scope_test.go", "name_test.go", "nemeses_test.go", "schema_registry_test.go", @@ -200,6 +202,7 @@ go_test( "//pkg/util/json", "//pkg/util/leaktest", "//pkg/util/log", + "//pkg/util/metric", "//pkg/util/mon", "//pkg/util/protoutil", "//pkg/util/randutil", diff --git a/pkg/ccl/changefeedccl/metrics_scope.go b/pkg/ccl/changefeedccl/metrics_scope.go new file mode 100644 index 000000000000..3feeaf2db71a --- /dev/null +++ b/pkg/ccl/changefeedccl/metrics_scope.go @@ -0,0 +1,77 @@ +// Copyright 2021 The Cockroach Authors. +// +// Licensed as a CockroachDB Enterprise file under the Cockroach Community +// License (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt + +package changefeedccl + +import ( + "fmt" + + "github.com/cockroachdb/cockroach/pkg/util/metric" +) + +// maxSLIScopes is a static limit on the number of SLI scopes -- that is the number +// of SLI metrics we will keep track of. +// The limit is static due to metric.Registry limitations. +const maxSLIScopes = 8 + +// SLIMetrics is the list of SLI related metrics for changefeeds. +type SLIMetrics struct { + ErrorRetries *metric.Counter + // TODO(yevgeniy): Add more SLI related metrics. +} + +// MetricStruct implements metric.Struct interface +func (*SLIMetrics) MetricStruct() {} + +func makeSLIMetrics(prefix string) *SLIMetrics { + withPrefix := func(meta metric.Metadata) metric.Metadata { + meta.Name = fmt.Sprintf("%s.%s", prefix, meta.Name) + return meta + } + + return &SLIMetrics{ + ErrorRetries: metric.NewCounter(withPrefix(metric.Metadata{ + Name: "error_retries", + Help: "Total retryable errors encountered this SLI", + Measurement: "Errors", + Unit: metric.Unit_COUNT, + })), + } +} + +// SLIScopes represents a set of SLI related metrics for a particular "scope". +type SLIScopes struct { + Scopes [maxSLIScopes]*SLIMetrics // Exported so that we can register w/ metrics registry. + names map[string]*SLIMetrics +} + +// MetricStruct implements metric.Struct interface +func (*SLIScopes) MetricStruct() {} + +// CreateSLIScopes creates changefeed specific SLI scope: a metric.Struct containing +// SLI specific metrics for each scope. +// The scopes are statically named "tier", and each metric name +// contained in SLIMetrics will be prefixed by "changefeed.tier