Skip to content

Commit

Permalink
upgrade to latest dependencies (#1299)
Browse files Browse the repository at this point in the history
bumping knative.dev/networking e7cfc5b...75762ca:
  > 75762ca upgrade to latest dependencies (# 955)
bumping knative.dev/pkg 5fe2303...03bf3de:
  > 03bf3de webhook: add options to disable resource_namespace tag in metrics (# 2931)
  > 3f02478 Bump cloud.google.com/go/storage from 1.39.1 to 1.40.0 (# 3002)
  > 7d95d0f Bump google.golang.org/api from 0.171.0 to 0.172.0 (# 3003)
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)
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 google.golang.org/genproto/googleapis/rpc 6e1732d...94a12d6:
  > 94a12d6 chore(all): update all (# 1102)

Signed-off-by: Knative Automation <[email protected]>
  • Loading branch information
knative-automation authored Apr 2, 2024
1 parent 14309b0 commit 90c7573
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 58 deletions.
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ require (
k8s.io/apimachinery v0.29.2
k8s.io/client-go v0.29.2
knative.dev/hack v0.0.0-20240327150553-47368d631660
knative.dev/networking v0.0.0-20240328164909-e7cfc5b7276f
knative.dev/pkg v0.0.0-20240328165227-5fe230325f5a
knative.dev/networking v0.0.0-20240329112016-75762caf9e15
knative.dev/pkg v0.0.0-20240401190221-03bf3de6e2bc
sigs.k8s.io/yaml v1.4.0
)

Expand Down Expand Up @@ -76,10 +76,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
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,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=
Expand Down Expand Up @@ -608,10 +608,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.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
Expand Down Expand Up @@ -696,10 +696,10 @@ k8s.io/utils v0.0.0-20240102154912-e7106e64919e h1:eQ/4ljkx21sObifjzXwlPKpdGLrCf
k8s.io/utils v0.0.0-20240102154912-e7106e64919e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
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-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-20240328165227-5fe230325f5a h1:HYKynG9QjRuVxrXEYnSMWBXboyOqHBgoQZt0xe4+RMA=
knative.dev/pkg v0.0.0-20240328165227-5fe230325f5a/go.mod h1:LgcT4KPEcw24alWzzkFAN2acHq38au8NZqybU16TStI=
knative.dev/networking v0.0.0-20240329112016-75762caf9e15 h1:AXfadR7ULrSY10o8oaz2bEevGCg034rMb8c7Zdwc9Ac=
knative.dev/networking v0.0.0-20240329112016-75762caf9e15/go.mod h1:g/w0osd9bivSJjKwB0aL6KsjRBTQjk+bDFc9/qYUIQY=
knative.dev/pkg v0.0.0-20240401190221-03bf3de6e2bc h1:qgjjXNqWPaIfxO00DbbB+SaeaKiwvMTIB3BcBtuzoqc=
knative.dev/pkg v0.0.0-20240401190221-03bf3de6e2bc/go.mod h1:086p4jjTy1KCaL2uoznjgh+kKVp0Vk2hh4yagpbUhOA=
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=
Expand Down
7 changes: 6 additions & 1 deletion vendor/knative.dev/pkg/injection/sharedmain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
164 changes: 128 additions & 36 deletions vendor/knative.dev/pkg/webhook/stats_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -65,43 +66,128 @@ 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(),
)
if err != nil {
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
}
Expand All @@ -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
}
Expand All @@ -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{
Expand Down
5 changes: 4 additions & 1 deletion vendor/knative.dev/pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,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
Expand All @@ -287,12 +287,12 @@ 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
google.golang.org/genproto/googleapis/api/annotations
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
Expand Down Expand Up @@ -918,7 +918,7 @@ k8s.io/utils/trace
# knative.dev/hack v0.0.0-20240327150553-47368d631660
## explicit; go 1.18
knative.dev/hack
# knative.dev/networking v0.0.0-20240328164909-e7cfc5b7276f
# knative.dev/networking v0.0.0-20240329112016-75762caf9e15
## explicit; go 1.21
knative.dev/networking/config
knative.dev/networking/pkg
Expand Down Expand Up @@ -969,7 +969,7 @@ knative.dev/networking/test/test_images/runtime/handlers
knative.dev/networking/test/test_images/timeout
knative.dev/networking/test/test_images/wsserver
knative.dev/networking/test/types
# knative.dev/pkg v0.0.0-20240328165227-5fe230325f5a
# knative.dev/pkg v0.0.0-20240401190221-03bf3de6e2bc
## explicit; go 1.21
knative.dev/pkg/apis
knative.dev/pkg/apis/duck
Expand Down

0 comments on commit 90c7573

Please sign in to comment.