4
4
"errors"
5
5
"fmt"
6
6
"net"
7
+ "strconv"
7
8
"sync"
8
9
"time"
9
10
@@ -23,6 +24,7 @@ type CtrlFuncMetrics struct {
23
24
TranslationBrokenResources prometheus.Gauge
24
25
ConfigPushDuration * prometheus.HistogramVec
25
26
ConfigPushSuccessTime * prometheus.GaugeVec
27
+ AdmissionCount * prometheus.CounterVec
26
28
27
29
// Fallback config push metrics.
28
30
FallbackTranslationCount * prometheus.CounterVec
@@ -77,6 +79,17 @@ const (
77
79
DataplaneKey string = "dataplane"
78
80
)
79
81
82
+ // Regular config push metrics names.
83
+ const (
84
+ // AllowedKey defines the key of the metric label indicating admission was allowed.
85
+ AllowedKey string = "allowed"
86
+ )
87
+
88
+ const (
89
+ // AdmissionResourceKey defines the name of the metric label indicating which dataplane this time series is relevant for.
90
+ AdmissionResourceKey string = "resource"
91
+ )
92
+
80
93
// Regular config push metrics names.
81
94
const (
82
95
MetricNameConfigPushCount = "ingress_controller_configuration_push_count"
@@ -85,6 +98,7 @@ const (
85
98
MetricNameTranslationCount = "ingress_controller_translation_count"
86
99
MetricNameTranslationBrokenResources = "ingress_controller_translation_broken_resource_count"
87
100
MetricNameConfigPushDuration = "ingress_controller_configuration_push_duration_milliseconds"
101
+ MetricNameAdmissionCount = "ingress_controller_admission_count"
88
102
)
89
103
90
104
// Fallback config push metrics names.
@@ -189,6 +203,20 @@ func NewCtrlFuncMetrics() *CtrlFuncMetrics {
189
203
[]string {DataplaneKey },
190
204
)
191
205
206
+ controllerMetrics .AdmissionCount = prometheus .NewCounterVec (
207
+ prometheus.CounterOpts {
208
+ Name : MetricNameAdmissionCount ,
209
+ Help : fmt .Sprintf (
210
+ "Count of admissions processed by Kong. " +
211
+ "`%s` describes whether an admission was allowed. " +
212
+ "`%s` describes the resource under admission. " ,
213
+ AllowedKey ,
214
+ AdmissionResourceKey ,
215
+ ),
216
+ },
217
+ []string {AllowedKey , AdmissionResourceKey },
218
+ )
219
+
192
220
controllerMetrics .FallbackTranslationCount = prometheus .NewCounterVec (
193
221
prometheus.CounterOpts {
194
222
Name : MetricNameFallbackTranslationCount ,
@@ -302,6 +330,7 @@ func NewCtrlFuncMetrics() *CtrlFuncMetrics {
302
330
controllerMetrics .TranslationBrokenResources ,
303
331
controllerMetrics .ConfigPushDuration ,
304
332
controllerMetrics .ConfigPushSuccessTime ,
333
+ controllerMetrics .AdmissionCount ,
305
334
controllerMetrics .FallbackTranslationBrokenResources ,
306
335
controllerMetrics .FallbackTranslationCount ,
307
336
controllerMetrics .FallbackConfigPushCount ,
@@ -356,6 +385,13 @@ func (c *CtrlFuncMetrics) RecordTranslationBrokenResources(count int) {
356
385
c .TranslationBrokenResources .Set (float64 (count ))
357
386
}
358
387
388
+ func (c * CtrlFuncMetrics ) RecordAdmissionCount (allowed bool , resource string ) {
389
+ c .ConfigPushCount .With (prometheus.Labels {
390
+ AllowedKey : strconv .FormatBool (allowed ),
391
+ AdmissionResourceKey : resource ,
392
+ }).Inc ()
393
+ }
394
+
359
395
// RecordFallbackTranslationFailure records a failed fallback configuration translation.
360
396
func (c * CtrlFuncMetrics ) RecordFallbackTranslationFailure () {
361
397
c .FallbackTranslationCount .With (prometheus.Labels {
0 commit comments