diff --git a/pkg/audit/stats_reporter.go b/pkg/audit/stats_reporter.go index d738df94ef3..ca759a2e0a2 100644 --- a/pkg/audit/stats_reporter.go +++ b/pkg/audit/stats_reporter.go @@ -23,6 +23,17 @@ const ( var auditDurationM metric.Float64Histogram +func init() { + view.Register(sdkmetric.NewView( + sdkmetric.Instrument{Name: auditDurationMetricName}, + sdkmetric.Stream{ + Aggregation: sdkmetric.AggregationExplicitBucketHistogram{ + Boundaries: []float64{1 * 60, 3 * 60, 5 * 60, 10 * 60, 15 * 60, 20 * 60, 40 * 60, 80 * 60, 160 * 60, 320 * 60}, + }, + }, + )) +} + func (r *reporter) observeTotalViolations(_ context.Context, o metric.Int64Observer) error { r.mu.RLock() defer r.mu.RUnlock() @@ -116,14 +127,6 @@ func newStatsReporter() (*reporter, error) { return nil, err } - view.Register(sdkmetric.NewView( - sdkmetric.Instrument{Name: auditDurationMetricName}, - sdkmetric.Stream{ - Aggregation: sdkmetric.AggregationExplicitBucketHistogram{ - Boundaries: []float64{1 * 60, 3 * 60, 5 * 60, 10 * 60, 15 * 60, 20 * 60, 40 * 60, 80 * 60, 160 * 60, 320 * 60}, - }, - }, - )) return r, nil } diff --git a/pkg/controller/constrainttemplate/stats_reporter.go b/pkg/controller/constrainttemplate/stats_reporter.go index 21a4eed29c7..68ac2781496 100644 --- a/pkg/controller/constrainttemplate/stats_reporter.go +++ b/pkg/controller/constrainttemplate/stats_reporter.go @@ -28,6 +28,17 @@ var ( ingestDurationM metric.Float64Histogram ) +func init() { + view.Register(sdkmetric.NewView( + sdkmetric.Instrument{Name: ingestDuration}, + sdkmetric.Stream{ + Aggregation: sdkmetric.AggregationExplicitBucketHistogram{ + Boundaries: []float64{0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.2, 0.3, 0.4, 0.5, 1, 2, 3, 4, 5}, + }, + }, + )) +} + func (r *reporter) reportIngestDuration(ctx context.Context, status metrics.Status, d time.Duration) error { ingestDurationM.Record(ctx, d.Seconds(), metric.WithAttributes(attribute.String(statusKey, string(status)))) ingestCountM.Add(ctx, 1, metric.WithAttributes(attribute.String(statusKey, string(status)))) @@ -65,14 +76,6 @@ func newStatsReporter() *reporter { if err != nil { panic(err) } - view.Register(sdkmetric.NewView( - sdkmetric.Instrument{Name: ingestDuration}, - sdkmetric.Stream{ - Aggregation: sdkmetric.AggregationExplicitBucketHistogram{ - Boundaries: []float64{0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.2, 0.3, 0.4, 0.5, 1, 2, 3, 4, 5}, - }, - }, - )) return r } diff --git a/pkg/controller/mutators/stats_reporter.go b/pkg/controller/mutators/stats_reporter.go index e1d060b724e..2d519aa9128 100644 --- a/pkg/controller/mutators/stats_reporter.go +++ b/pkg/controller/mutators/stats_reporter.go @@ -49,6 +49,17 @@ type reporter struct { mutatorsInConflict int } +func init() { + view.Register(sdkmetric.NewView( + sdkmetric.Instrument{Name: mutatorIngestionDurationMetricName}, + sdkmetric.Stream{ + Aggregation: sdkmetric.AggregationExplicitBucketHistogram{ + Boundaries: []float64{0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009, 0.01, 0.02, 0.03, 0.04, 0.05}, + }, + }, + )) +} + // NewStatsReporter creates a reporter for webhook metrics. func NewStatsReporter() StatsReporter { r := &reporter{} @@ -90,14 +101,6 @@ func NewStatsReporter() StatsReporter { panic(err) } - view.Register(sdkmetric.NewView( - sdkmetric.Instrument{Name: mutatorIngestionDurationMetricName}, - sdkmetric.Stream{ - Aggregation: sdkmetric.AggregationExplicitBucketHistogram{ - Boundaries: []float64{0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009, 0.01, 0.02, 0.03, 0.04, 0.05}, - }, - }, - )) return r } diff --git a/pkg/syncutil/stats_reporter.go b/pkg/syncutil/stats_reporter.go index 7ee24dacbcd..4ca80efa403 100644 --- a/pkg/syncutil/stats_reporter.go +++ b/pkg/syncutil/stats_reporter.go @@ -147,6 +147,18 @@ type Reporter struct { now func() float64 } +func init() { + view.Register( + sdkmetric.NewView( + sdkmetric.Instrument{Name: syncDurationMetricName}, + sdkmetric.Stream{ + Aggregation: sdkmetric.AggregationExplicitBucketHistogram{ + Boundaries: []float64{0.0001, 0.0002, 0.0003, 0.0004, 0.0005, 0.0006, 0.0007, 0.0008, 0.0009, 0.001, 0.002, 0.003, 0.004, 0.005, 0.01, 0.02, 0.03, 0.04, 0.05}, + }, + }, + )) +} + // NewStatsReporter creates a reporter for sync metrics. func NewStatsReporter() (*Reporter, error) { if r == nil { @@ -166,16 +178,6 @@ func NewStatsReporter() (*Reporter, error) { if err != nil { return nil, err } - - view.Register( - sdkmetric.NewView( - sdkmetric.Instrument{Name: syncDurationMetricName}, - sdkmetric.Stream{ - Aggregation: sdkmetric.AggregationExplicitBucketHistogram{ - Boundaries: []float64{0.0001, 0.0002, 0.0003, 0.0004, 0.0005, 0.0006, 0.0007, 0.0008, 0.0009, 0.001, 0.002, 0.003, 0.004, 0.005, 0.01, 0.02, 0.03, 0.04, 0.05}, - }, - }, - )) } return r, nil } diff --git a/pkg/webhook/stats_reporter.go b/pkg/webhook/stats_reporter.go index a770de54574..5a111615a8b 100644 --- a/pkg/webhook/stats_reporter.go +++ b/pkg/webhook/stats_reporter.go @@ -40,6 +40,27 @@ type StatsReporter interface { // reporter implements StatsReporter interface. type reporter struct{} +func init() { + view.Register( + sdkmetric.NewView( + sdkmetric.Instrument{Name: validationRequestDurationMetricName}, + sdkmetric.Stream{ + Aggregation: sdkmetric.AggregationExplicitBucketHistogram{ + Boundaries: []float64{0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.5, 2, 2.5, 3}, + }, + }, + ), + sdkmetric.NewView( + sdkmetric.Instrument{Name: mutationRequestDurationMetricName}, + sdkmetric.Stream{ + Aggregation: sdkmetric.AggregationExplicitBucketHistogram{ + Boundaries: []float64{0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.5, 2, 2.5, 3}, + }, + }, + ), + ) +} + // newStatsReporter creaters a reporter for webhook metrics. func newStatsReporter() (StatsReporter, error) { if r == nil { @@ -74,25 +95,6 @@ func newStatsReporter() (StatsReporter, error) { if err != nil { return nil, err } - - view.Register( - sdkmetric.NewView( - sdkmetric.Instrument{Name: validationRequestDurationMetricName}, - sdkmetric.Stream{ - Aggregation: sdkmetric.AggregationExplicitBucketHistogram{ - Boundaries: []float64{0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.5, 2, 2.5, 3}, - }, - }, - ), - sdkmetric.NewView( - sdkmetric.Instrument{Name: mutationRequestDurationMetricName}, - sdkmetric.Stream{ - Aggregation: sdkmetric.AggregationExplicitBucketHistogram{ - Boundaries: []float64{0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.5, 2, 2.5, 3}, - }, - }, - ), - ) } return r, nil }