4
4
"errors"
5
5
"fmt"
6
6
"net"
7
+ "strconv"
7
8
"sync"
8
9
"time"
9
10
@@ -27,6 +28,8 @@ type CtrlFuncMetrics struct {
27
28
ConfigPushDuration * prometheus.HistogramVec
28
29
29
30
ConfigPushSuccessTime * prometheus.GaugeVec
31
+
32
+ AdmissionCount * prometheus.CounterVec
30
33
}
31
34
32
35
const (
@@ -70,13 +73,24 @@ const (
70
73
DataplaneKey string = "dataplane"
71
74
)
72
75
76
+ const (
77
+ // AllowedKey defines the key of the metric label indicating admission was allowed.
78
+ AllowedKey string = "allowed"
79
+ )
80
+
81
+ const (
82
+ // AdmissionResourceKey defines the name of the metric label indicating which dataplane this time series is relevant for.
83
+ AdmissionResourceKey string = "resource"
84
+ )
85
+
73
86
const (
74
87
MetricNameConfigPushCount = "ingress_controller_configuration_push_count"
75
88
MetricNameConfigPushBrokenResources = "ingress_controller_configuration_push_broken_resource_count"
76
89
MetricNameConfigPushSuccessTime = "ingress_controller_configuration_push_last_successful"
77
90
MetricNameTranslationCount = "ingress_controller_translation_count"
78
91
MetricNameTranslationBrokenResources = "ingress_controller_translation_broken_resource_count"
79
92
MetricNameConfigPushDuration = "ingress_controller_configuration_push_duration_milliseconds"
93
+ MetricNameAdmissionCount = "ingress_controller_admission_count"
80
94
)
81
95
82
96
var _lock sync.Mutex
@@ -168,12 +182,27 @@ func NewCtrlFuncMetrics() *CtrlFuncMetrics {
168
182
[]string {DataplaneKey },
169
183
)
170
184
185
+ controllerMetrics .AdmissionCount = prometheus .NewCounterVec (
186
+ prometheus.CounterOpts {
187
+ Name : MetricNameAdmissionCount ,
188
+ Help : fmt .Sprintf (
189
+ "Count of admissions processed by Kong. " +
190
+ "`%s` describes whether an admission was allowed. " +
191
+ "`%s` describes the resource under admission. " ,
192
+ AllowedKey ,
193
+ AdmissionResourceKey ,
194
+ ),
195
+ },
196
+ []string {AllowedKey , AdmissionResourceKey },
197
+ )
198
+
171
199
metrics .Registry .Unregister (controllerMetrics .ConfigPushCount )
172
200
metrics .Registry .Unregister (controllerMetrics .ConfigPushBrokenResources )
173
201
metrics .Registry .Unregister (controllerMetrics .TranslationCount )
174
202
metrics .Registry .Unregister (controllerMetrics .TranslationBrokenResources )
175
203
metrics .Registry .Unregister (controllerMetrics .ConfigPushDuration )
176
204
metrics .Registry .Unregister (controllerMetrics .ConfigPushSuccessTime )
205
+ metrics .Registry .Unregister (controllerMetrics .AdmissionCount )
177
206
178
207
metrics .Registry .MustRegister (
179
208
controllerMetrics .ConfigPushCount ,
@@ -182,6 +211,7 @@ func NewCtrlFuncMetrics() *CtrlFuncMetrics {
182
211
controllerMetrics .TranslationBrokenResources ,
183
212
controllerMetrics .ConfigPushDuration ,
184
213
controllerMetrics .ConfigPushSuccessTime ,
214
+ controllerMetrics .AdmissionCount ,
185
215
)
186
216
187
217
return controllerMetrics
@@ -223,6 +253,13 @@ func (c *CtrlFuncMetrics) RecordTranslationBrokenResources(count int) {
223
253
c .TranslationBrokenResources .Set (float64 (count ))
224
254
}
225
255
256
+ func (c * CtrlFuncMetrics ) RecordAdmissionCount (allowed bool , resource string ) {
257
+ c .ConfigPushCount .With (prometheus.Labels {
258
+ AllowedKey : strconv .FormatBool (allowed ),
259
+ AdmissionResourceKey : resource ,
260
+ }).Inc ()
261
+ }
262
+
226
263
type recordOption func (prometheus.Labels ) prometheus.Labels
227
264
228
265
func withError (err error ) recordOption {
0 commit comments