From 2b100af8594275b789633a0b016c3c2753d638d7 Mon Sep 17 00:00:00 2001 From: Knative Automation Date: Tue, 2 Apr 2024 02:08:46 +0000 Subject: [PATCH] upgrade to latest dependencies bumping knative.dev/eventing e581d36...7e1c082: > 7e1c082 [main] Format Go code (# 7819) bumping google.golang.org/genproto/googleapis/api a219d84...6e1732d: > 6e1732d chore(all): auto-regenerate .pb.go files (# 1098) > 9694c77 chore(deps): bump google.golang.org/protobuf from 1.32.0 to 1.33.0 in /googleapis/api/apikeys (# 1099) > ace143d chore(deps): bump google.golang.org/protobuf from 1.32.0 to 1.33.0 in /googleapis/api/servicemanagement (# 1100) > c811ad7 chore(all): update all (# 1097) bumping knative.dev/networking ae03989...e7cfc5b: > e7cfc5b drop vendor licenses (# 954) > 8c13911 upgrade to latest dependencies (# 953) bumping google.golang.org/api a28dfbd...707b9b2: > 707b9b2 chore(main): release 0.172.0 (# 2486) > 77cc7d0 feat(all): auto-regenerate discovery clients (# 2492) > 18f643a chore(all): update all to 94a12d6 (# 2489) > 78ee47e feat(all): auto-regenerate discovery clients (# 2490) > 57e19b3 feat(all): auto-regenerate discovery clients (# 2488) > b0eaf37 feat(all): auto-regenerate discovery clients (# 2487) > 0398093 feat(all): auto-regenerate discovery clients (# 2485) Signed-off-by: Knative Automation --- go.mod | 14 +- go.sum | 28 +-- .../codegen/cmd/injection-gen/args/args.go | 3 + .../cmd/injection-gen/generators/informer.go | 6 +- .../cmd/injection-gen/generators/packages.go | 1 + .../pkg/injection/sharedmain/main.go | 7 +- .../knative.dev/pkg/webhook/stats_reporter.go | 164 ++++++++++++++---- vendor/knative.dev/pkg/webhook/webhook.go | 5 +- vendor/modules.txt | 14 +- 9 files changed, 175 insertions(+), 67 deletions(-) diff --git a/go.mod b/go.mod index c765f66de..20f02b009 100644 --- a/go.mod +++ b/go.mod @@ -14,10 +14,10 @@ require ( k8s.io/api v0.29.2 k8s.io/apimachinery v0.29.2 k8s.io/client-go v0.29.2 - knative.dev/eventing v0.40.1-0.20240327210418-e581d36f9f2a + knative.dev/eventing v0.40.1-0.20240328132724-7e1c08246ca3 knative.dev/hack v0.0.0-20240327150553-47368d631660 - knative.dev/pkg v0.0.0-20240327172111-b8b7ca1f7904 - knative.dev/serving v0.40.1-0.20240328120758-e779e28bbee1 + knative.dev/pkg v0.0.0-20240401190221-03bf3de6e2bc + knative.dev/serving v0.40.1-0.20240401154359-c2d0af1e4cc1 ) require ( @@ -88,10 +88,10 @@ require ( golang.org/x/time v0.5.0 // indirect golang.org/x/tools v0.19.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect - google.golang.org/api v0.171.0 // indirect + google.golang.org/api v0.172.0 // indirect google.golang.org/appengine v1.6.8 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240311132316-a219d84964c2 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240314234333-6e1732d8331c // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect google.golang.org/grpc v1.62.1 // indirect google.golang.org/protobuf v1.33.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect @@ -103,7 +103,7 @@ require ( k8s.io/klog/v2 v2.120.1 // indirect k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect k8s.io/utils v0.0.0-20240102154912-e7106e64919e // indirect - knative.dev/networking v0.0.0-20240327140628-ae039896b125 // indirect + knative.dev/networking v0.0.0-20240328164909-e7cfc5b7276f // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect diff --git a/go.sum b/go.sum index 37fbeaea1..cbffcaa35 100644 --- a/go.sum +++ b/go.sum @@ -598,8 +598,8 @@ google.golang.org/api v0.25.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0M google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= -google.golang.org/api v0.171.0 h1:w174hnBPqut76FzW5Qaupt7zY8Kql6fiVjgys4f58sU= -google.golang.org/api v0.171.0/go.mod h1:Hnq5AHm4OTMt2BUVjael2CWZFD6vksJdWCWiUAmjC9o= +google.golang.org/api v0.172.0 h1:/1OcMZGPmW1rX2LCu2CmGUD1KXK1+pfzxotxyRUCCdk= +google.golang.org/api v0.172.0/go.mod h1:+fJZq6QXWfa9pXhnIzsjx4yI22d4aI9ZpLb58gvXjis= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -639,10 +639,10 @@ google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7Fc google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto/googleapis/api v0.0.0-20240311132316-a219d84964c2 h1:rIo7ocm2roD9DcFIX67Ym8icoGCKSARAiPljFhh5suQ= -google.golang.org/genproto/googleapis/api v0.0.0-20240311132316-a219d84964c2/go.mod h1:O1cOfN1Cy6QEYr7VxtjOyP5AdAuR0aJ/MYZaaof623Y= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c h1:lfpJ/2rWPa/kJgxyyXM8PrNnfCzcmxJ265mADgwmvLI= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= +google.golang.org/genproto/googleapis/api v0.0.0-20240314234333-6e1732d8331c h1:kaI7oewGK5YnVwj+Y+EJBO/YN1ht8iTL9XkFHtVZLsc= +google.golang.org/genproto/googleapis/api v0.0.0-20240314234333-6e1732d8331c/go.mod h1:VQW3tUculP/D4B+xVCo+VgSq8As6wA9ZjHl//pmk+6s= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= @@ -724,16 +724,16 @@ k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/A k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA= k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCfRziVtos3ofG/sQ= k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -knative.dev/eventing v0.40.1-0.20240327210418-e581d36f9f2a h1:IcopvDTfpZ57wgJnWKvaLl1ob4E9xi49Azc5yhSwUTk= -knative.dev/eventing v0.40.1-0.20240327210418-e581d36f9f2a/go.mod h1:19sfPiy4dK2jBIHgszOTk43qOvfCXz1GTIncRY3trB8= +knative.dev/eventing v0.40.1-0.20240328132724-7e1c08246ca3 h1:+5XTIq9iJgk1Br0Ex5nEJBhy9wGMVaFY6HzW0/E0mrU= +knative.dev/eventing v0.40.1-0.20240328132724-7e1c08246ca3/go.mod h1:19sfPiy4dK2jBIHgszOTk43qOvfCXz1GTIncRY3trB8= knative.dev/hack v0.0.0-20240327150553-47368d631660 h1:tW6NgyjMnSXBS75+k+Xh5uNiLhJ9TFswS9hrkC3OQOc= knative.dev/hack v0.0.0-20240327150553-47368d631660/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q= -knative.dev/networking v0.0.0-20240327140628-ae039896b125 h1:w9XY50H8EmPj0C3QGeScCcCqt8Y3vjPEujf/LeH7RLY= -knative.dev/networking v0.0.0-20240327140628-ae039896b125/go.mod h1:YlLpTHRi0i/5XVD3QoqEfFhSmAfRj9sZR2NQEOF9dVc= -knative.dev/pkg v0.0.0-20240327172111-b8b7ca1f7904 h1:AT4AIwO3p1qZtmEzW5tWPftrUxts8Tlpra7EjNS/2PY= -knative.dev/pkg v0.0.0-20240327172111-b8b7ca1f7904/go.mod h1:LgcT4KPEcw24alWzzkFAN2acHq38au8NZqybU16TStI= -knative.dev/serving v0.40.1-0.20240328120758-e779e28bbee1 h1:IB/nBSRuX69rSlfHk5HtDJsQ+/+EkWyNjoKLGeMVrp8= -knative.dev/serving v0.40.1-0.20240328120758-e779e28bbee1/go.mod h1:emRubGwMhrtkaVc9HK8USf9EAPb6Lo3C+jmtJnbqkpA= +knative.dev/networking v0.0.0-20240328164909-e7cfc5b7276f h1:zUKDqyqgooQdd+g9JWXtbQBXdYfHnqbyMoIaTmQ43eQ= +knative.dev/networking v0.0.0-20240328164909-e7cfc5b7276f/go.mod h1:uCy8+UXsCtZyb9fmQWrZm7byeZtyGj1fpHxHVKn+prg= +knative.dev/pkg v0.0.0-20240401190221-03bf3de6e2bc h1:qgjjXNqWPaIfxO00DbbB+SaeaKiwvMTIB3BcBtuzoqc= +knative.dev/pkg v0.0.0-20240401190221-03bf3de6e2bc/go.mod h1:086p4jjTy1KCaL2uoznjgh+kKVp0Vk2hh4yagpbUhOA= +knative.dev/serving v0.40.1-0.20240401154359-c2d0af1e4cc1 h1:B8yCh04QlM/n77Rra85Cs0qdl8itUM2O0ZDsT8TfAGs= +knative.dev/serving v0.40.1-0.20240401154359-c2d0af1e4cc1/go.mod h1:1ZxBVWDLDQ979N7ON85aSMXCH+582Hlg80uH/xtd9UA= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/vendor/knative.dev/pkg/codegen/cmd/injection-gen/args/args.go b/vendor/knative.dev/pkg/codegen/cmd/injection-gen/args/args.go index 7cd8122d5..265b4e40a 100644 --- a/vendor/knative.dev/pkg/codegen/cmd/injection-gen/args/args.go +++ b/vendor/knative.dev/pkg/codegen/cmd/injection-gen/args/args.go @@ -30,6 +30,7 @@ type CustomArgs struct { ListersPackage string ForceKinds string ListerHasPointerElem bool + DisableInformerInit bool } // NewDefaults returns default arguments for the generator. @@ -49,6 +50,8 @@ func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) { fs.BoolVar(&ca.ListerHasPointerElem, "lister-has-pointer-elem", false, "") fs.MarkDeprecated("lister-has-pointer-elem", "this flag has no effect") + + fs.BoolVar(&ca.DisableInformerInit, "disable-informer-init", false, "disable generating the init function for the informer") } // Validate checks the given arguments. diff --git a/vendor/knative.dev/pkg/codegen/cmd/injection-gen/generators/informer.go b/vendor/knative.dev/pkg/codegen/cmd/injection-gen/generators/informer.go index c4fb215f1..c0b3bf3ea 100644 --- a/vendor/knative.dev/pkg/codegen/cmd/injection-gen/generators/informer.go +++ b/vendor/knative.dev/pkg/codegen/cmd/injection-gen/generators/informer.go @@ -37,6 +37,7 @@ type injectionGenerator struct { imports namer.ImportTracker typedInformerPackage string groupInformerFactoryPackage string + disableInformerInit bool } var _ generator.Generator = (*injectionGenerator)(nil) @@ -98,6 +99,7 @@ func (g *injectionGenerator) GenerateType(c *generator.Context, t *types.Type, w Package: "context", Name: "WithValue", }), + "disableInformerInit": g.disableInformerInit, } sw.Do(injectionInformer, m) @@ -106,14 +108,16 @@ func (g *injectionGenerator) GenerateType(c *generator.Context, t *types.Type, w } var injectionInformer = ` +{{ if not .disableInformerInit }} func init() { {{.injectionRegisterInformer|raw}}(withInformer) } +{{ end }} // Key is used for associating the Informer inside the context.Context. type Key struct{} -func withInformer(ctx {{.contextContext|raw}}) ({{.contextContext|raw}}, {{.controllerInformer|raw}}) { +{{ if .disableInformerInit }} func WithInformer {{ else }} func withInformer {{ end }} (ctx {{.contextContext|raw}}) ({{.contextContext|raw}}, {{.controllerInformer|raw}}) { f := {{.factoryGet|raw}}(ctx) inf := f.{{.groupGoName}}().{{.versionGoName}}().{{.type|publicPlural}}() return {{ .contextWithValue|raw }}(ctx, Key{}, inf), inf.Informer() diff --git a/vendor/knative.dev/pkg/codegen/cmd/injection-gen/generators/packages.go b/vendor/knative.dev/pkg/codegen/cmd/injection-gen/generators/packages.go index 43768927a..f0ca43f2b 100644 --- a/vendor/knative.dev/pkg/codegen/cmd/injection-gen/generators/packages.go +++ b/vendor/knative.dev/pkg/codegen/cmd/injection-gen/generators/packages.go @@ -412,6 +412,7 @@ func versionInformerPackages(basePackage string, groupPkgName string, gv clientg imports: generator.NewImportTracker(), typedInformerPackage: typedInformerPackage, groupInformerFactoryPackage: factoryPackagePath, + disableInformerInit: customArgs.DisableInformerInit, }) return generators }, diff --git a/vendor/knative.dev/pkg/injection/sharedmain/main.go b/vendor/knative.dev/pkg/injection/sharedmain/main.go index 25562e965..79c42c201 100644 --- a/vendor/knative.dev/pkg/injection/sharedmain/main.go +++ b/vendor/knative.dev/pkg/injection/sharedmain/main.go @@ -290,7 +290,12 @@ func MainWithConfig(ctx context.Context, component string, cfg *rest.Config, cto var wh *webhook.Webhook if len(webhooks) > 0 { // Register webhook metrics - webhook.RegisterMetrics() + opts := webhook.GetOptions(ctx) + if opts != nil { + webhook.RegisterMetrics(opts.StatsReporterOptions...) + } else { + webhook.RegisterMetrics() + } wh, err = webhook.New(ctx, webhooks) if err != nil { diff --git a/vendor/knative.dev/pkg/webhook/stats_reporter.go b/vendor/knative.dev/pkg/webhook/stats_reporter.go index 1fe30e8af..3f05d4a91 100644 --- a/vendor/knative.dev/pkg/webhook/stats_reporter.go +++ b/vendor/knative.dev/pkg/webhook/stats_reporter.go @@ -26,6 +26,7 @@ import ( "go.opencensus.io/tag" admissionv1 "k8s.io/api/admission/v1" apixv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + "k8s.io/apimachinery/pkg/util/sets" "knative.dev/pkg/metrics" ) @@ -65,19 +66,83 @@ var ( resultCodeKey = tag.MustNewKey("result_code") ) +type admissionToValue func(*admissionv1.AdmissionRequest, *admissionv1.AdmissionResponse) string +type conversionToValue func(*apixv1.ConversionRequest, *apixv1.ConversionResponse) string + +var ( + allAdmissionTags = map[tag.Key]admissionToValue{ + requestOperationKey: func(req *admissionv1.AdmissionRequest, _ *admissionv1.AdmissionResponse) string { + return string(req.Operation) + }, + kindGroupKey: func(req *admissionv1.AdmissionRequest, _ *admissionv1.AdmissionResponse) string { + return req.Kind.Group + }, + kindVersionKey: func(req *admissionv1.AdmissionRequest, _ *admissionv1.AdmissionResponse) string { + return req.Kind.Version + }, + kindKindKey: func(req *admissionv1.AdmissionRequest, _ *admissionv1.AdmissionResponse) string { + return req.Kind.Kind + }, + resourceGroupKey: func(req *admissionv1.AdmissionRequest, _ *admissionv1.AdmissionResponse) string { + return req.Resource.Group + }, + resourceVersionKey: func(req *admissionv1.AdmissionRequest, _ *admissionv1.AdmissionResponse) string { + return req.Resource.Version + }, + resourceResourceKey: func(req *admissionv1.AdmissionRequest, _ *admissionv1.AdmissionResponse) string { + return req.Resource.Resource + }, + resourceNamespaceKey: func(req *admissionv1.AdmissionRequest, _ *admissionv1.AdmissionResponse) string { + return req.Namespace + }, + admissionAllowedKey: func(_ *admissionv1.AdmissionRequest, resp *admissionv1.AdmissionResponse) string { + return strconv.FormatBool(resp.Allowed) + }, + } + allConversionTags = map[tag.Key]conversionToValue{ + desiredAPIVersionKey: func(req *apixv1.ConversionRequest, _ *apixv1.ConversionResponse) string { + return req.DesiredAPIVersion + }, + resultStatusKey: func(_ *apixv1.ConversionRequest, resp *apixv1.ConversionResponse) string { + return resp.Result.Status + }, + resultReasonKey: func(_ *apixv1.ConversionRequest, resp *apixv1.ConversionResponse) string { + return string(resp.Result.Reason) + }, + resultCodeKey: func(_ *apixv1.ConversionRequest, resp *apixv1.ConversionResponse) string { + return strconv.Itoa(int(resp.Result.Code)) + }, + } +) + // StatsReporter reports webhook metrics type StatsReporter interface { ReportAdmissionRequest(request *admissionv1.AdmissionRequest, response *admissionv1.AdmissionResponse, d time.Duration) error ReportConversionRequest(request *apixv1.ConversionRequest, response *apixv1.ConversionResponse, d time.Duration) error } +type statsReporterOptions struct { + tagsToExclude sets.Set[string] +} + +type StatsReporterOption func(_ *statsReporterOptions) + +func WithoutTags(tags ...string) StatsReporterOption { + return func(opts *statsReporterOptions) { + opts.tagsToExclude.Insert(tags...) + } +} + // reporter implements StatsReporter interface type reporter struct { ctx context.Context + + admissionTags map[tag.Key]admissionToValue + conversionTags map[tag.Key]conversionToValue } // NewStatsReporter creates a reporter for webhook metrics -func NewStatsReporter() (StatsReporter, error) { +func NewStatsReporter(opts ...StatsReporterOption) (StatsReporter, error) { ctx, err := tag.New( context.Background(), ) @@ -85,23 +150,44 @@ func NewStatsReporter() (StatsReporter, error) { return nil, err } - return &reporter{ctx: ctx}, nil + options := statsReporterOptions{ + tagsToExclude: sets.New[string](), + } + for _, opt := range opts { + opt(&options) + } + + admissionTags := make(map[tag.Key]admissionToValue) + for key, f := range allAdmissionTags { + if options.tagsToExclude.Has(key.Name()) { + continue + } + admissionTags[key] = f + } + conversionTags := make(map[tag.Key]conversionToValue) + for key, f := range allConversionTags { + if options.tagsToExclude.Has(key.Name()) { + continue + } + conversionTags[key] = f + } + + return &reporter{ + ctx: ctx, + admissionTags: admissionTags, + conversionTags: conversionTags, + }, nil } // Captures req count metric, recording the count and the duration func (r *reporter) ReportAdmissionRequest(req *admissionv1.AdmissionRequest, resp *admissionv1.AdmissionResponse, d time.Duration) error { - ctx, err := tag.New( - r.ctx, - tag.Insert(requestOperationKey, string(req.Operation)), - tag.Insert(kindGroupKey, req.Kind.Group), - tag.Insert(kindVersionKey, req.Kind.Version), - tag.Insert(kindKindKey, req.Kind.Kind), - tag.Insert(resourceGroupKey, req.Resource.Group), - tag.Insert(resourceVersionKey, req.Resource.Version), - tag.Insert(resourceResourceKey, req.Resource.Resource), - tag.Insert(resourceNamespaceKey, req.Namespace), - tag.Insert(admissionAllowedKey, strconv.FormatBool(resp.Allowed)), - ) + mutators := make([]tag.Mutator, 0, len(r.admissionTags)) + + for key, f := range r.admissionTags { + mutators = append(mutators, tag.Insert(key, f(req, resp))) + } + + ctx, err := tag.New(r.ctx, mutators...) if err != nil { return err } @@ -114,13 +200,13 @@ func (r *reporter) ReportAdmissionRequest(req *admissionv1.AdmissionRequest, res // Captures req count metric, recording the count and the duration func (r *reporter) ReportConversionRequest(req *apixv1.ConversionRequest, resp *apixv1.ConversionResponse, d time.Duration) error { - ctx, err := tag.New( - r.ctx, - tag.Insert(desiredAPIVersionKey, req.DesiredAPIVersion), - tag.Insert(resultStatusKey, resp.Result.Status), - tag.Insert(resultReasonKey, string(resp.Result.Reason)), - tag.Insert(resultCodeKey, strconv.Itoa(int(resp.Result.Code))), - ) + mutators := make([]tag.Mutator, 0, len(r.conversionTags)) + + for key, f := range r.conversionTags { + mutators = append(mutators, tag.Insert(key, f(req, resp))) + } + + ctx, err := tag.New(r.ctx, mutators...) if err != nil { return err } @@ -131,21 +217,27 @@ func (r *reporter) ReportConversionRequest(req *apixv1.ConversionRequest, resp * return nil } -func RegisterMetrics() { - tagKeys := []tag.Key{ - requestOperationKey, - kindGroupKey, - kindVersionKey, - kindKindKey, - resourceGroupKey, - resourceVersionKey, - resourceResourceKey, - resourceNamespaceKey, - admissionAllowedKey, - desiredAPIVersionKey, - resultStatusKey, - resultReasonKey, - resultCodeKey} +func RegisterMetrics(opts ...StatsReporterOption) { + options := statsReporterOptions{ + tagsToExclude: sets.New[string](), + } + for _, opt := range opts { + opt(&options) + } + + tagKeys := []tag.Key{} + for tag := range allAdmissionTags { + if options.tagsToExclude.Has(tag.Name()) { + continue + } + tagKeys = append(tagKeys, tag) + } + for tag := range allConversionTags { + if options.tagsToExclude.Has(tag.Name()) { + continue + } + tagKeys = append(tagKeys, tag) + } if err := view.Register( &view.View{ diff --git a/vendor/knative.dev/pkg/webhook/webhook.go b/vendor/knative.dev/pkg/webhook/webhook.go index eff693e80..d8842df35 100644 --- a/vendor/knative.dev/pkg/webhook/webhook.go +++ b/vendor/knative.dev/pkg/webhook/webhook.go @@ -70,6 +70,9 @@ type Options struct { // only a single port for the service. Port int + // StatsReporterOptions are the options used to initialize the default StatsReporter + StatsReporterOptions []StatsReporterOption + // StatsReporter reports metrics about the webhook. // This will be automatically initialized by the constructor if left uninitialized. StatsReporter StatsReporter @@ -144,7 +147,7 @@ func New( logger := logging.FromContext(ctx) if opts.StatsReporter == nil { - reporter, err := NewStatsReporter() + reporter, err := NewStatsReporter(opts.StatsReporterOptions...) if err != nil { return nil, err } diff --git a/vendor/modules.txt b/vendor/modules.txt index 29d455947..8a542825f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -347,7 +347,7 @@ golang.org/x/tools/internal/imports # gomodules.xyz/jsonpatch/v2 v2.4.0 ## explicit; go 1.20 gomodules.xyz/jsonpatch/v2 -# google.golang.org/api v0.171.0 +# google.golang.org/api v0.172.0 ## explicit; go 1.19 google.golang.org/api/support/bundler # google.golang.org/appengine v1.6.8 @@ -359,10 +359,10 @@ google.golang.org/appengine/internal/log google.golang.org/appengine/internal/remote_api google.golang.org/appengine/internal/urlfetch google.golang.org/appengine/urlfetch -# google.golang.org/genproto/googleapis/api v0.0.0-20240311132316-a219d84964c2 +# google.golang.org/genproto/googleapis/api v0.0.0-20240314234333-6e1732d8331c ## explicit; go 1.19 google.golang.org/genproto/googleapis/api/httpbody -# google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c +# google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 ## explicit; go 1.19 google.golang.org/genproto/googleapis/rpc/status # google.golang.org/grpc v1.62.1 @@ -974,7 +974,7 @@ k8s.io/utils/pointer k8s.io/utils/ptr k8s.io/utils/strings/slices k8s.io/utils/trace -# knative.dev/eventing v0.40.1-0.20240327210418-e581d36f9f2a +# knative.dev/eventing v0.40.1-0.20240328132724-7e1c08246ca3 ## explicit; go 1.21 knative.dev/eventing/pkg/adapter/v2 knative.dev/eventing/pkg/adapter/v2/test @@ -1028,12 +1028,12 @@ knative.dev/eventing/pkg/observability/client # knative.dev/hack v0.0.0-20240327150553-47368d631660 ## explicit; go 1.18 knative.dev/hack -# knative.dev/networking v0.0.0-20240327140628-ae039896b125 +# knative.dev/networking v0.0.0-20240328164909-e7cfc5b7276f ## explicit; go 1.21 knative.dev/networking/pkg/apis/networking knative.dev/networking/pkg/apis/networking/v1alpha1 knative.dev/networking/pkg/config -# knative.dev/pkg v0.0.0-20240327172111-b8b7ca1f7904 +# knative.dev/pkg v0.0.0-20240401190221-03bf3de6e2bc ## explicit; go 1.21 knative.dev/pkg/apis knative.dev/pkg/apis/duck @@ -1097,7 +1097,7 @@ knative.dev/pkg/webhook/psbinding knative.dev/pkg/webhook/resourcesemantics knative.dev/pkg/webhook/resourcesemantics/defaulting knative.dev/pkg/webhook/resourcesemantics/validation -# knative.dev/serving v0.40.1-0.20240328120758-e779e28bbee1 +# knative.dev/serving v0.40.1-0.20240401154359-c2d0af1e4cc1 ## explicit; go 1.21 knative.dev/serving/pkg/apis/autoscaling knative.dev/serving/pkg/apis/autoscaling/v1alpha1