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

fix: fixing metrics views #3307

Merged
merged 1 commit into from
Mar 15, 2024
Merged
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
19 changes: 11 additions & 8 deletions pkg/audit/stats_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}

Expand Down
19 changes: 11 additions & 8 deletions pkg/controller/constrainttemplate/stats_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down Expand Up @@ -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
}

Expand Down
19 changes: 11 additions & 8 deletions pkg/controller/mutators/stats_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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
}

Expand Down
22 changes: 12 additions & 10 deletions pkg/syncutil/stats_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
40 changes: 21 additions & 19 deletions pkg/webhook/stats_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down