From 68aeb9a954d0d2dd2d613e042614513a91847512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Thu, 11 May 2023 12:16:48 +0200 Subject: [PATCH] chore: bump otel deps (#7152) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: bump otel deps Signed-off-by: Charles-Edouard Brétéché * fix Signed-off-by: Charles-Edouard Brétéché --------- Signed-off-by: Charles-Edouard Brétéché --- .../handlers/cleanup/handlers.go | 16 +++--- go.mod | 26 +++++----- go.sum | 52 +++++++++---------- pkg/controllers/metrics/policy/controller.go | 7 ++- pkg/engine/engine.go | 10 ++-- pkg/engine/metrics.go | 5 +- pkg/metrics/metrics.go | 13 +++-- pkg/utils/controller/run.go | 26 ++++++---- pkg/webhooks/handlers/metrics.go | 18 +++---- 9 files changed, 88 insertions(+), 85 deletions(-) diff --git a/cmd/cleanup-controller/handlers/cleanup/handlers.go b/cmd/cleanup-controller/handlers/cleanup/handlers.go index 3f5342f920..cfc136bce2 100644 --- a/cmd/cleanup-controller/handlers/cleanup/handlers.go +++ b/cmd/cleanup-controller/handlers/cleanup/handlers.go @@ -18,8 +18,8 @@ import ( controllerutils "github.com/kyverno/kyverno/pkg/utils/controller" "github.com/kyverno/kyverno/pkg/utils/match" "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/global" - "go.opentelemetry.io/otel/metric/instrument" "go.uber.org/multierr" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -41,22 +41,22 @@ type handlers struct { } type cleanupMetrics struct { - deletedObjectsTotal instrument.Int64Counter - cleanupFailuresTotal instrument.Int64Counter + deletedObjectsTotal metric.Int64Counter + cleanupFailuresTotal metric.Int64Counter } func newCleanupMetrics(logger logr.Logger) cleanupMetrics { meter := global.MeterProvider().Meter(metrics.MeterName) deletedObjectsTotal, err := meter.Int64Counter( "cleanup_controller_deletedobjects", - instrument.WithDescription("can be used to track number of deleted objects."), + metric.WithDescription("can be used to track number of deleted objects."), ) if err != nil { logger.Error(err, "Failed to create instrument, cleanup_controller_deletedobjects_total") } cleanupFailuresTotal, err := meter.Int64Counter( "cleanup_controller_errors", - instrument.WithDescription("can be used to track number of cleanup failures."), + metric.WithDescription("can be used to track number of cleanup failures."), ) if err != nil { logger.Error(err, "Failed to create instrument, cleanup_controller_errors_total") @@ -143,7 +143,7 @@ func (h *handlers) executePolicy(ctx context.Context, logger logr.Logger, policy debug.Error(err, "failed to list resources") errs = append(errs, err) if h.metrics.cleanupFailuresTotal != nil { - h.metrics.cleanupFailuresTotal.Add(ctx, 1, commonLabels...) + h.metrics.cleanupFailuresTotal.Add(ctx, 1, metric.WithAttributes(commonLabels...)) } } else { for i := range list.Items { @@ -233,14 +233,14 @@ func (h *handlers) executePolicy(ctx context.Context, logger logr.Logger, policy logger.WithValues("name", name, "namespace", namespace).Info("resource matched, it will be deleted...") if err := h.client.DeleteResource(ctx, resource.GetAPIVersion(), resource.GetKind(), namespace, name, false); err != nil { if h.metrics.cleanupFailuresTotal != nil { - h.metrics.cleanupFailuresTotal.Add(ctx, 1, labels...) + h.metrics.cleanupFailuresTotal.Add(ctx, 1, metric.WithAttributes(labels...)) } debug.Error(err, "failed to delete resource") errs = append(errs, err) h.createEvent(policy, resource, err) } else { if h.metrics.deletedObjectsTotal != nil { - h.metrics.deletedObjectsTotal.Add(ctx, 1, labels...) + h.metrics.deletedObjectsTotal.Add(ctx, 1, metric.WithAttributes(labels...)) } debug.Info("deleted") h.createEvent(policy, resource, nil) diff --git a/go.mod b/go.mod index 4ea7ee6eb8..ed58d6a4c6 100644 --- a/go.mod +++ b/go.mod @@ -44,16 +44,16 @@ require ( github.com/spf13/cobra v1.7.0 github.com/stretchr/testify v1.8.2 github.com/zach-klippenstein/goregen v0.0.0-20160303162051-795b5e3961ea - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.40.0 - go.opentelemetry.io/otel v1.14.0 - go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.37.0 - go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.14.0 - go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.14.0 - go.opentelemetry.io/otel/exporters/prometheus v0.37.0 - go.opentelemetry.io/otel/metric v0.37.0 - go.opentelemetry.io/otel/sdk v1.14.0 - go.opentelemetry.io/otel/sdk/metric v0.37.0 - go.opentelemetry.io/otel/trace v1.14.0 + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.41.1 + go.opentelemetry.io/otel v1.15.1 + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.38.1 + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.15.1 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.15.1 + go.opentelemetry.io/otel/exporters/prometheus v0.38.1 + go.opentelemetry.io/otel/metric v0.38.1 + go.opentelemetry.io/otel/sdk v1.15.1 + go.opentelemetry.io/otel/sdk/metric v0.38.1 + go.opentelemetry.io/otel/trace v1.15.1 go.uber.org/automaxprocs v1.5.2 go.uber.org/multierr v1.11.0 go.uber.org/zap v1.24.0 @@ -139,7 +139,7 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/blang/semver v3.5.1+incompatible // indirect github.com/cenkalti/backoff/v3 v3.2.2 // indirect - github.com/cenkalti/backoff/v4 v4.2.0 // indirect + github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/clbanning/mxj/v2 v2.5.7 // indirect github.com/cloudflare/circl v1.3.2 // indirect @@ -303,8 +303,8 @@ require ( github.com/zeebo/errs v1.3.0 // indirect go.mongodb.org/mongo-driver v1.11.3 // indirect go.opencensus.io v0.24.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.14.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.37.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.15.1 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.38.1 // indirect go.opentelemetry.io/proto/otlp v0.19.0 // indirect go.starlark.net v0.0.0-20230302034142-4b1e35fe2254 // indirect go.uber.org/atomic v1.10.0 // indirect diff --git a/go.sum b/go.sum index b42177049e..e3a5f2cede 100644 --- a/go.sum +++ b/go.sum @@ -273,8 +273,8 @@ github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEe github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/cenkalti/backoff/v3 v3.2.2 h1:cfUAAO3yvKMYKPrvhDuHSwQnhZNk/RMHKdZqKTxfm6M= github.com/cenkalti/backoff/v3 v3.2.2/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs= -github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4= -github.com/cenkalti/backoff/v4 v4.2.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= +github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= @@ -1469,30 +1469,30 @@ go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.40.0 h1:lE9EJyw3/JhrjWH/hEy9FptnalDQgj7vpbgC2KCCCxE= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.40.0/go.mod h1:pcQ3MM3SWvrA71U4GDqv9UFDJ3HQsW7y5ZO3tDTlUdI= -go.opentelemetry.io/otel v1.14.0 h1:/79Huy8wbf5DnIPhemGB+zEPVwnN6fuQybr/SRXa6hM= -go.opentelemetry.io/otel v1.14.0/go.mod h1:o4buv+dJzx8rohcUeRmWUZhqupFvzWis188WlggnNeU= -go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.14.0 h1:/fXHZHGvro6MVqV34fJzDhi7sHGpX3Ej/Qjmfn003ho= -go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.14.0/go.mod h1:UFG7EBMRdXyFstOwH028U0sVf+AvukSGhF0g8+dmNG8= -go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.37.0 h1:22J9c9mxNAZugv86zhwjBnER0DbO0VVpW9Oo/j3jBBQ= -go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.37.0/go.mod h1:QD8SSO9fgtBOvXYpcX5NXW+YnDJByTnh7a/9enQWFmw= -go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.37.0 h1:CI6DSdsSkJxX1rsfPSQ0SciKx6klhdDRBXqKb+FwXG8= -go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.37.0/go.mod h1:WLBYPrz8srktckhCjFaau4VHSfGaMuqoKSXwpzaiRZg= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.14.0 h1:TKf2uAs2ueguzLaxOCBXNpHxfO/aC7PAdDsSH0IbeRQ= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.14.0/go.mod h1:HrbCVv40OOLTABmOn1ZWty6CHXkU8DK/Urc43tHug70= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.14.0 h1:ap+y8RXX3Mu9apKVtOkM6WSFESLM8K3wNQyOU8sWHcc= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.14.0/go.mod h1:5w41DY6S9gZrbjuq6Y+753e96WfPha5IcsOSZTtullM= -go.opentelemetry.io/otel/exporters/prometheus v0.37.0 h1:NQc0epfL0xItsmGgSXgfbH2C1fq2VLXkZoDFsfRNHpc= -go.opentelemetry.io/otel/exporters/prometheus v0.37.0/go.mod h1:hB8qWjsStK36t50/R0V2ULFb4u95X/Q6zupXLgvjTh8= -go.opentelemetry.io/otel/metric v0.37.0 h1:pHDQuLQOZwYD+Km0eb657A25NaRzy0a+eLyKfDXedEs= -go.opentelemetry.io/otel/metric v0.37.0/go.mod h1:DmdaHfGt54iV6UKxsV9slj2bBRJcKC1B1uvDLIioc1s= -go.opentelemetry.io/otel/sdk v1.14.0 h1:PDCppFRDq8A1jL9v6KMI6dYesaq+DFcDZvjsoGvxGzY= -go.opentelemetry.io/otel/sdk v1.14.0/go.mod h1:bwIC5TjrNG6QDCHNWvW4HLHtUQ4I+VQDsnjhvyZCALM= -go.opentelemetry.io/otel/sdk/metric v0.37.0 h1:haYBBtZZxiI3ROwSmkZnI+d0+AVzBWeviuYQDeBWosU= -go.opentelemetry.io/otel/sdk/metric v0.37.0/go.mod h1:mO2WV1AZKKwhwHTV3AKOoIEb9LbUaENZDuGUQd+j4A0= -go.opentelemetry.io/otel/trace v1.14.0 h1:wp2Mmvj41tDsyAJXiWDWpfNsOiIyd38fy85pyKcFq/M= -go.opentelemetry.io/otel/trace v1.14.0/go.mod h1:8avnQLK+CG77yNLUae4ea2JDQ6iT+gozhnZjy/rw9G8= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.41.1 h1:pX+lppB8PArapyhS6nBStyQmkaDUPWdQf0UmEGRCQ54= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.41.1/go.mod h1:2FmkXne0k9nkp27LD/m+uoh8dNlstsiCJ7PLc/S72aI= +go.opentelemetry.io/otel v1.15.1 h1:3Iwq3lfRByPaws0f6bU3naAqOR1n5IeDWd9390kWHa8= +go.opentelemetry.io/otel v1.15.1/go.mod h1:mHHGEHVDLal6YrKMmk9LqC4a3sF5g+fHfrttQIB1NTc= +go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.15.1 h1:XYDQtNzdb2T4uM1pku2m76eSMDJgqhJ+6KzkqgQBALc= +go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.15.1/go.mod h1:uOTV75+LOzV+ODmL8ahRLWkFA3eQcSC2aAsbxIu4duk= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.38.1 h1:MSGZwWn8Ji4b6UWkB7pYPgTiTmWM3S4lro9Y+5c3WmE= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.38.1/go.mod h1:GFYZ2ebv/Bwont+pVaXHTGncGz93MjvTgZrskegEOUI= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.38.1 h1:lIhD5oa2k9Lw4oxtl1ECNOrPaX61NjRo8hp+8lDEn4w= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.38.1/go.mod h1:1z3PiBAi38sdOEIVrjCYtDy5kW2hPWXdF8jJolsSBKg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.15.1 h1:tyoeaUh8REKay72DVYsSEBYV18+fGONe+YYPaOxgLoE= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.15.1/go.mod h1:HUSnrjQQ19KX9ECjpQxufsF+3ioD3zISPMlauTPZu2g= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.15.1 h1:pIfoG5IAZFzp9EUlJzdSkpUwpaUAAnD+Ru1nBLTACIQ= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.15.1/go.mod h1:poNKBqF5+nR/6ke2oGTDjHfksrsHDOHXAl2g4+9ONsY= +go.opentelemetry.io/otel/exporters/prometheus v0.38.1 h1:GwalIvFIx91qIA8qyAyqYj9lql5Ba2Oxj/jDG6+3UoU= +go.opentelemetry.io/otel/exporters/prometheus v0.38.1/go.mod h1:6K7aBvWHXRUcNYFSj6Hi5hHwzA1jYflG/T8snrX4dYM= +go.opentelemetry.io/otel/metric v0.38.1 h1:2MM7m6wPw9B8Qv8iHygoAgkbejed59uUR6ezR5T3X2s= +go.opentelemetry.io/otel/metric v0.38.1/go.mod h1:FwqNHD3I/5iX9pfrRGZIlYICrJv0rHEUl2Ln5vdIVnQ= +go.opentelemetry.io/otel/sdk v1.15.1 h1:5FKR+skgpzvhPQHIEfcwMYjCBr14LWzs3uSqKiQzETI= +go.opentelemetry.io/otel/sdk v1.15.1/go.mod h1:8rVtxQfrbmbHKfqzpQkT5EzZMcbMBwTzNAggbEAM0KA= +go.opentelemetry.io/otel/sdk/metric v0.38.1 h1:EkO5wI4NT/fUaoPMGc0fKV28JaWe7q4vfVpEVasGb+8= +go.opentelemetry.io/otel/sdk/metric v0.38.1/go.mod h1:Rn4kSXFF9ZQZ5lL1pxQjCbK4seiO+U7s0ncmIFJaj34= +go.opentelemetry.io/otel/trace v1.15.1 h1:uXLo6iHJEzDfrNC0L0mNjItIp06SyaBQxu5t3xMlngY= +go.opentelemetry.io/otel/trace v1.15.1/go.mod h1:IWdQG/5N1x7f6YUlmdLeJvH9yxtuJAfc4VW5Agv9r/8= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.opentelemetry.io/proto/otlp v0.19.0 h1:IVN6GR+mhC4s5yfcTbmzHYODqvWAp3ZedA2SJPI1Nnw= go.opentelemetry.io/proto/otlp v0.19.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U= diff --git a/pkg/controllers/metrics/policy/controller.go b/pkg/controllers/metrics/policy/controller.go index 1e5ff42a52..7c1c62f6e2 100644 --- a/pkg/controllers/metrics/policy/controller.go +++ b/pkg/controllers/metrics/policy/controller.go @@ -14,14 +14,13 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/global" - "go.opentelemetry.io/otel/metric/instrument" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" ) type controller struct { metricsConfig metrics.MetricsConfigManager - ruleInfo instrument.Float64ObservableGauge + ruleInfo metric.Float64ObservableGauge // listers cpolLister kyvernov1listers.ClusterPolicyLister @@ -41,7 +40,7 @@ func NewController( meter := meterProvider.Meter(metrics.MeterName) policyRuleInfoMetric, err := meter.Float64ObservableGauge( "kyverno_policy_rule_info_total", - instrument.WithDescription("can be used to track the info of the rules or/and policies present in the cluster. 0 means the rule doesn't exist and has been deleted, 1 means the rule is currently existent in the cluster"), + metric.WithDescription("can be used to track the info of the rules or/and policies present in the cluster. 0 means the rule doesn't exist and has been deleted, 1 means the rule is currently existent in the cluster"), ) if err != nil { logger.Error(err, "Failed to create instrument, kyverno_policy_rule_info_total") @@ -114,7 +113,7 @@ func (c *controller) reportPolicy(ctx context.Context, policy kyvernov1.PolicyIn attribute.String("rule_name", rule.Name), attribute.String("rule_type", string(ruleType)), } - observer.ObserveFloat64(c.ruleInfo, 1, append(ruleAttributes, policyAttributes...)...) + observer.ObserveFloat64(c.ruleInfo, 1, metric.WithAttributes(append(ruleAttributes, policyAttributes...)...)) } } return nil diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index f29753a58b..0e5a35a46f 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -21,8 +21,8 @@ import ( "github.com/kyverno/kyverno/pkg/registryclient" "github.com/kyverno/kyverno/pkg/tracing" stringutils "github.com/kyverno/kyverno/pkg/utils/strings" + "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/global" - "go.opentelemetry.io/otel/metric/instrument" "go.opentelemetry.io/otel/trace" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) @@ -36,8 +36,8 @@ type engine struct { contextLoader engineapi.ContextLoaderFactory exceptionSelector engineapi.PolicyExceptionSelector // metrics - resultCounter instrument.Int64Counter - durationHistogram instrument.Float64Histogram + resultCounter metric.Int64Counter + durationHistogram metric.Float64Histogram } type handlerFactory = func() (handlers.Handler, error) @@ -54,14 +54,14 @@ func NewEngine( meter := global.MeterProvider().Meter(metrics.MeterName) resultCounter, err := meter.Int64Counter( "kyverno_policy_results", - instrument.WithDescription("can be used to track the results associated with the policies applied in the user's cluster, at the level from rule to policy to admission requests"), + metric.WithDescription("can be used to track the results associated with the policies applied in the user's cluster, at the level from rule to policy to admission requests"), ) if err != nil { logging.Error(err, "failed to register metric kyverno_policy_results") } durationHistogram, err := meter.Float64Histogram( "kyverno_policy_execution_duration_seconds", - instrument.WithDescription("can be used to track the latencies (in seconds) associated with the execution/processing of the individual rules under Kyverno policies whenever they evaluate incoming resource requests"), + metric.WithDescription("can be used to track the latencies (in seconds) associated with the execution/processing of the individual rules under Kyverno policies whenever they evaluate incoming resource requests"), ) if err != nil { logging.Error(err, "failed to register metric kyverno_policy_execution_duration_seconds") diff --git a/pkg/engine/metrics.go b/pkg/engine/metrics.go index 93aedc62f6..455f15e9af 100644 --- a/pkg/engine/metrics.go +++ b/pkg/engine/metrics.go @@ -9,6 +9,7 @@ import ( engineapi "github.com/kyverno/kyverno/pkg/engine/api" "github.com/kyverno/kyverno/pkg/metrics" "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/metric" ) func (e *engine) reportMetrics( @@ -71,7 +72,7 @@ func (e *engine) reportMetrics( attribute.String("rule_type", string(ruleType)), attribute.String("rule_execution_cause", string(executionCause)), } - e.resultCounter.Add(ctx, 1, commonLabels...) + e.resultCounter.Add(ctx, 1, metric.WithAttributes(commonLabels...)) } if e.durationHistogram != nil { commonLabels := []attribute.KeyValue{ @@ -88,7 +89,7 @@ func (e *engine) reportMetrics( attribute.String("rule_type", string(ruleType)), attribute.String("rule_execution_cause", string(executionCause)), } - e.durationHistogram.Record(ctx, rule.Stats().ProcessingTime().Seconds(), commonLabels...) + e.durationHistogram.Record(ctx, rule.Stats().ProcessingTime().Seconds(), metric.WithAttributes(commonLabels...)) } } } diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index 729a0386f4..e98c4982f9 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -16,7 +16,6 @@ import ( "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" "go.opentelemetry.io/otel/exporters/prometheus" "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/metric/instrument" sdkmetric "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/metric/aggregation" "go.opentelemetry.io/otel/sdk/resource" @@ -30,8 +29,8 @@ const ( type MetricsConfig struct { // instruments - policyChangesMetric instrument.Int64Counter - clientQueriesMetric instrument.Int64Counter + policyChangesMetric metric.Int64Counter + clientQueriesMetric metric.Int64Counter // config config kconfig.MetricsConfiguration @@ -51,12 +50,12 @@ func (m *MetricsConfig) Config() kconfig.MetricsConfiguration { func (m *MetricsConfig) initializeMetrics(meterProvider metric.MeterProvider) error { var err error meter := meterProvider.Meter(MeterName) - m.policyChangesMetric, err = meter.Int64Counter("kyverno_policy_changes", instrument.WithDescription("can be used to track all the changes associated with the Kyverno policies present on the cluster such as creation, updates and deletions")) + m.policyChangesMetric, err = meter.Int64Counter("kyverno_policy_changes", metric.WithDescription("can be used to track all the changes associated with the Kyverno policies present on the cluster such as creation, updates and deletions")) if err != nil { m.Log.Error(err, "Failed to create instrument, kyverno_policy_changes") return err } - m.clientQueriesMetric, err = meter.Int64Counter("kyverno_client_queries", instrument.WithDescription("can be used to track the number of client queries sent from Kyverno to the API-server")) + m.clientQueriesMetric, err = meter.Int64Counter("kyverno_client_queries", metric.WithDescription("can be used to track the number of client queries sent from Kyverno to the API-server")) if err != nil { m.Log.Error(err, "Failed to create instrument, kyverno_client_queries") return err @@ -194,7 +193,7 @@ func (m *MetricsConfig) RecordPolicyChanges(ctx context.Context, policyValidatio attribute.String("policy_name", policyName), attribute.String("policy_change_type", policyChangeType), } - m.policyChangesMetric.Add(ctx, 1, commonLabels...) + m.policyChangesMetric.Add(ctx, 1, metric.WithAttributes(commonLabels...)) } func (m *MetricsConfig) RecordClientQueries(ctx context.Context, clientQueryOperation ClientQueryOperation, clientType ClientType, resourceKind string, resourceNamespace string) { @@ -204,5 +203,5 @@ func (m *MetricsConfig) RecordClientQueries(ctx context.Context, clientQueryOper attribute.String("resource_kind", resourceKind), attribute.String("resource_namespace", resourceNamespace), } - m.clientQueriesMetric.Add(ctx, 1, commonLabels...) + m.clientQueriesMetric.Add(ctx, 1, metric.WithAttributes(commonLabels...)) } diff --git a/pkg/utils/controller/run.go b/pkg/utils/controller/run.go index a2654d3744..eba1767783 100644 --- a/pkg/utils/controller/run.go +++ b/pkg/utils/controller/run.go @@ -8,8 +8,8 @@ import ( "github.com/go-logr/logr" "github.com/kyverno/kyverno/pkg/metrics" "go.opentelemetry.io/otel/attribute" + sdkmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/global" - "go.opentelemetry.io/otel/metric/instrument" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" @@ -21,28 +21,28 @@ type reconcileFunc func(ctx context.Context, logger logr.Logger, key string, nam type controllerMetrics struct { controllerName string - reconcileTotal instrument.Int64Counter - requeueTotal instrument.Int64Counter - queueDropTotal instrument.Int64Counter + reconcileTotal sdkmetric.Int64Counter + requeueTotal sdkmetric.Int64Counter + queueDropTotal sdkmetric.Int64Counter } func newControllerMetrics(logger logr.Logger, controllerName string) *controllerMetrics { meter := global.MeterProvider().Meter(metrics.MeterName) reconcileTotal, err := meter.Int64Counter( "kyverno_controller_reconcile", - instrument.WithDescription("can be used to track number of reconciliation cycles")) + sdkmetric.WithDescription("can be used to track number of reconciliation cycles")) if err != nil { logger.Error(err, "Failed to create instrument, kyverno_controller_reconcile_total") } requeueTotal, err := meter.Int64Counter( "kyverno_controller_requeue", - instrument.WithDescription("can be used to track number of reconciliation errors")) + sdkmetric.WithDescription("can be used to track number of reconciliation errors")) if err != nil { logger.Error(err, "Failed to create instrument, kyverno_controller_requeue_total") } queueDropTotal, err := meter.Int64Counter( "kyverno_controller_drop", - instrument.WithDescription("can be used to track number of queue drops")) + sdkmetric.WithDescription("can be used to track number of queue drops")) if err != nil { logger.Error(err, "Failed to create instrument, kyverno_controller_drop_total") } @@ -104,7 +104,7 @@ func processNextWorkItem(ctx context.Context, logger logr.Logger, metric *contro func handleErr(ctx context.Context, logger logr.Logger, metric *controllerMetrics, queue workqueue.RateLimitingInterface, maxRetries int, err error, obj interface{}) { if metric.reconcileTotal != nil { - metric.reconcileTotal.Add(ctx, 1, attribute.String("controller_name", metric.controllerName)) + metric.reconcileTotal.Add(ctx, 1, sdkmetric.WithAttributes(attribute.String("controller_name", metric.controllerName))) } if err == nil { queue.Forget(obj) @@ -118,8 +118,10 @@ func handleErr(ctx context.Context, logger logr.Logger, metric *controllerMetric metric.requeueTotal.Add( ctx, 1, - attribute.String("controller_name", metric.controllerName), - attribute.Int("num_requeues", queue.NumRequeues(obj)), + sdkmetric.WithAttributes( + attribute.String("controller_name", metric.controllerName), + attribute.Int("num_requeues", queue.NumRequeues(obj)), + ), ) } } else { @@ -129,7 +131,9 @@ func handleErr(ctx context.Context, logger logr.Logger, metric *controllerMetric metric.queueDropTotal.Add( ctx, 1, - attribute.String("controller_name", metric.controllerName), + sdkmetric.WithAttributes( + attribute.String("controller_name", metric.controllerName), + ), ) } } diff --git a/pkg/webhooks/handlers/metrics.go b/pkg/webhooks/handlers/metrics.go index 52a9f3fdc4..b2d6b1d2b4 100644 --- a/pkg/webhooks/handlers/metrics.go +++ b/pkg/webhooks/handlers/metrics.go @@ -10,8 +10,8 @@ import ( "github.com/kyverno/kyverno/pkg/config" "github.com/kyverno/kyverno/pkg/metrics" "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/metric/global" - "go.opentelemetry.io/otel/metric/instrument" semconv "go.opentelemetry.io/otel/semconv/v1.17.0" ) @@ -23,14 +23,14 @@ func (inner AdmissionHandler) withMetrics(logger logr.Logger, metricsConfig conf meter := global.MeterProvider().Meter(metrics.MeterName) requestsMetric, err := meter.Int64Counter( "kyverno_admission_requests", - instrument.WithDescription("can be used to track the number of admission requests encountered by Kyverno in the cluster"), + metric.WithDescription("can be used to track the number of admission requests encountered by Kyverno in the cluster"), ) if err != nil { logger.Error(err, "Failed to create instrument, kyverno_admission_requests_total") } durationMetric, err := meter.Float64Histogram( "kyverno_admission_review_duration_seconds", - instrument.WithDescription("can be used to track the latencies (in seconds) associated with the entire individual admission review. For example, if an incoming request trigger, say, five policies, this metric will track the e2e latency associated with the execution of all those policies"), + metric.WithDescription("can be used to track the latencies (in seconds) associated with the entire individual admission review. For example, if an incoming request trigger, say, five policies, this metric will track the e2e latency associated with the execution of all those policies"), ) if err != nil { logger.Error(err, "Failed to create instrument, kyverno_admission_review_duration_seconds") @@ -51,11 +51,11 @@ func (inner AdmissionHandler) withMetrics(logger logr.Logger, metricsConfig conf defer func() { latency := int64(time.Since(startTime)) durationInSeconds := float64(latency) / float64(1000*1000*1000) - durationMetric.Record(ctx, durationInSeconds, attributes...) + durationMetric.Record(ctx, durationInSeconds, metric.WithAttributes(attributes...)) }() } if requestsMetric != nil { - requestsMetric.Add(ctx, 1, attributes...) + requestsMetric.Add(ctx, 1, metric.WithAttributes(attributes...)) } } return response @@ -70,14 +70,14 @@ func (inner HttpHandler) withMetrics(logger logr.Logger, attrs ...attribute.KeyV meter := global.MeterProvider().Meter(metrics.MeterName) requestsMetric, err := meter.Int64Counter( "kyverno_http_requests_total", - instrument.WithDescription("can be used to track the number of http requests"), + metric.WithDescription("can be used to track the number of http requests"), ) if err != nil { logger.Error(err, "Failed to create instrument, kyverno_http_requests_total") } durationMetric, err := meter.Float64Histogram( "kyverno_http_requests_duration_seconds", - instrument.WithDescription("can be used to track the latencies (in seconds) associated with the entire individual http request."), + metric.WithDescription("can be used to track the latencies (in seconds) associated with the entire individual http request."), ) if err != nil { logger.Error(err, "Failed to create instrument, kyverno_http_requests_duration_seconds") @@ -92,13 +92,13 @@ func (inner HttpHandler) withMetrics(logger logr.Logger, attrs ...attribute.KeyV } attributes = append(attributes, attrs...) if requestsMetric != nil { - requestsMetric.Add(request.Context(), 1, attributes...) + requestsMetric.Add(request.Context(), 1, metric.WithAttributes(attributes...)) } if durationMetric != nil { defer func() { latency := int64(time.Since(startTime)) durationInSeconds := float64(latency) / float64(1000*1000*1000) - durationMetric.Record(request.Context(), durationInSeconds, attributes...) + durationMetric.Record(request.Context(), durationInSeconds, metric.WithAttributes(attributes...)) }() } inner(writer, request)