Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webhook: register metrics only with default stats reporter #3005

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions injection/sharedmain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,6 @@ func MainWithConfig(ctx context.Context, component string, cfg *rest.Config, cto
// and pass them in.
var wh *webhook.Webhook
if len(webhooks) > 0 {
// Register webhook metrics
opts := webhook.GetOptions(ctx)
if opts != nil {
webhook.RegisterMetrics(opts.StatsReporterOptions...)
} else {
webhook.RegisterMetrics()
}

wh, err = webhook.New(ctx, webhooks)
if err != nil {
logger.Fatalw("Failed to create webhook", zap.Error(err))
Expand Down
7 changes: 7 additions & 0 deletions webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"log"
"net"
"net/http"
"sync"
"time"

// Injection stuff
Expand All @@ -40,6 +41,10 @@ import (
"knative.dev/pkg/system"
)

var (
metricsOnce sync.Once
)

// Options contains the configuration for the webhook
type Options struct {
// TLSMinVersion contains the minimum TLS version that is acceptable to communicate with the API server.
Expand Down Expand Up @@ -147,6 +152,8 @@ func New(
logger := logging.FromContext(ctx)

if opts.StatsReporter == nil {
// Register webhook metrics
metricsOnce.Do(func() { RegisterMetrics(opts.StatsReporterOptions...) })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before RegisterMetrics would always be called. Now it's only being invokved when the opts.StatsReporter isnt' set.

This seems like a breaking change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your assessment. It might break users who specify StatsReporter yet still rely on RegisterMetrics to register views properly.

However I consider this as an unpleasant situation when users want to use a different StatsReporter but register the same view with slightly different tags.

To be fair, this is not something that I need anymore since the default StatsReporter can be customized already.

As it is today, webhook.NewStatsReporter() and webhook.RegisterMetrics() seems to be independent interfaces while they actually share the same data structure (tracks the same metrics tags, and relies on the same opts.StatsReporterOptions to initialize).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skonto do you have any opinions?

reporter, err := NewStatsReporter(opts.StatsReporterOptions...)
if err != nil {
return nil, err
Expand Down