Skip to content

Commit d998928

Browse files
JaydipGabanileewoobin789
authored andcommitted
fix: fixing metrics views (open-policy-agent#3307)
Signed-off-by: Jaydip Gabani <[email protected]>
1 parent 6879bb4 commit d998928

File tree

5 files changed

+66
-53
lines changed

5 files changed

+66
-53
lines changed

pkg/audit/stats_reporter.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ const (
2323

2424
var auditDurationM metric.Float64Histogram
2525

26+
func init() {
27+
view.Register(sdkmetric.NewView(
28+
sdkmetric.Instrument{Name: auditDurationMetricName},
29+
sdkmetric.Stream{
30+
Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
31+
Boundaries: []float64{1 * 60, 3 * 60, 5 * 60, 10 * 60, 15 * 60, 20 * 60, 40 * 60, 80 * 60, 160 * 60, 320 * 60},
32+
},
33+
},
34+
))
35+
}
36+
2637
func (r *reporter) observeTotalViolations(_ context.Context, o metric.Int64Observer) error {
2738
r.mu.RLock()
2839
defer r.mu.RUnlock()
@@ -116,14 +127,6 @@ func newStatsReporter() (*reporter, error) {
116127
return nil, err
117128
}
118129

119-
view.Register(sdkmetric.NewView(
120-
sdkmetric.Instrument{Name: auditDurationMetricName},
121-
sdkmetric.Stream{
122-
Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
123-
Boundaries: []float64{1 * 60, 3 * 60, 5 * 60, 10 * 60, 15 * 60, 20 * 60, 40 * 60, 80 * 60, 160 * 60, 320 * 60},
124-
},
125-
},
126-
))
127130
return r, nil
128131
}
129132

pkg/controller/constrainttemplate/stats_reporter.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ var (
2828
ingestDurationM metric.Float64Histogram
2929
)
3030

31+
func init() {
32+
view.Register(sdkmetric.NewView(
33+
sdkmetric.Instrument{Name: ingestDuration},
34+
sdkmetric.Stream{
35+
Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
36+
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},
37+
},
38+
},
39+
))
40+
}
41+
3142
func (r *reporter) reportIngestDuration(ctx context.Context, status metrics.Status, d time.Duration) error {
3243
ingestDurationM.Record(ctx, d.Seconds(), metric.WithAttributes(attribute.String(statusKey, string(status))))
3344
ingestCountM.Add(ctx, 1, metric.WithAttributes(attribute.String(statusKey, string(status))))
@@ -65,14 +76,6 @@ func newStatsReporter() *reporter {
6576
if err != nil {
6677
panic(err)
6778
}
68-
view.Register(sdkmetric.NewView(
69-
sdkmetric.Instrument{Name: ingestDuration},
70-
sdkmetric.Stream{
71-
Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
72-
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},
73-
},
74-
},
75-
))
7679
return r
7780
}
7881

pkg/controller/mutators/stats_reporter.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ type reporter struct {
4949
mutatorsInConflict int
5050
}
5151

52+
func init() {
53+
view.Register(sdkmetric.NewView(
54+
sdkmetric.Instrument{Name: mutatorIngestionDurationMetricName},
55+
sdkmetric.Stream{
56+
Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
57+
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},
58+
},
59+
},
60+
))
61+
}
62+
5263
// NewStatsReporter creates a reporter for webhook metrics.
5364
func NewStatsReporter() StatsReporter {
5465
r := &reporter{}
@@ -90,14 +101,6 @@ func NewStatsReporter() StatsReporter {
90101
panic(err)
91102
}
92103

93-
view.Register(sdkmetric.NewView(
94-
sdkmetric.Instrument{Name: mutatorIngestionDurationMetricName},
95-
sdkmetric.Stream{
96-
Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
97-
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},
98-
},
99-
},
100-
))
101104
return r
102105
}
103106

pkg/syncutil/stats_reporter.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,18 @@ type Reporter struct {
147147
now func() float64
148148
}
149149

150+
func init() {
151+
view.Register(
152+
sdkmetric.NewView(
153+
sdkmetric.Instrument{Name: syncDurationMetricName},
154+
sdkmetric.Stream{
155+
Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
156+
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},
157+
},
158+
},
159+
))
160+
}
161+
150162
// NewStatsReporter creates a reporter for sync metrics.
151163
func NewStatsReporter() (*Reporter, error) {
152164
if r == nil {
@@ -166,16 +178,6 @@ func NewStatsReporter() (*Reporter, error) {
166178
if err != nil {
167179
return nil, err
168180
}
169-
170-
view.Register(
171-
sdkmetric.NewView(
172-
sdkmetric.Instrument{Name: syncDurationMetricName},
173-
sdkmetric.Stream{
174-
Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
175-
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},
176-
},
177-
},
178-
))
179181
}
180182
return r, nil
181183
}

pkg/webhook/stats_reporter.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ type StatsReporter interface {
4040
// reporter implements StatsReporter interface.
4141
type reporter struct{}
4242

43+
func init() {
44+
view.Register(
45+
sdkmetric.NewView(
46+
sdkmetric.Instrument{Name: validationRequestDurationMetricName},
47+
sdkmetric.Stream{
48+
Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
49+
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},
50+
},
51+
},
52+
),
53+
sdkmetric.NewView(
54+
sdkmetric.Instrument{Name: mutationRequestDurationMetricName},
55+
sdkmetric.Stream{
56+
Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
57+
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},
58+
},
59+
},
60+
),
61+
)
62+
}
63+
4364
// newStatsReporter creaters a reporter for webhook metrics.
4465
func newStatsReporter() (StatsReporter, error) {
4566
if r == nil {
@@ -74,25 +95,6 @@ func newStatsReporter() (StatsReporter, error) {
7495
if err != nil {
7596
return nil, err
7697
}
77-
78-
view.Register(
79-
sdkmetric.NewView(
80-
sdkmetric.Instrument{Name: validationRequestDurationMetricName},
81-
sdkmetric.Stream{
82-
Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
83-
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},
84-
},
85-
},
86-
),
87-
sdkmetric.NewView(
88-
sdkmetric.Instrument{Name: mutationRequestDurationMetricName},
89-
sdkmetric.Stream{
90-
Aggregation: sdkmetric.AggregationExplicitBucketHistogram{
91-
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},
92-
},
93-
},
94-
),
95-
)
9698
}
9799
return r, nil
98100
}

0 commit comments

Comments
 (0)