44 "errors"
55 "fmt"
66 "net"
7+ "strconv"
78 "time"
89
910 "github.com/prometheus/client_golang/prometheus"
@@ -76,6 +77,16 @@ const (
7677 InstanceIDKey string = "instance_id"
7778)
7879
80+ const (
81+ // AllowedKey defines the key of the metric label indicating admission was allowed.
82+ AllowedKey string = "allowed"
83+ )
84+
85+ const (
86+ // AdmissionResourceKey defines the name of the metric label indicating which dataplane this time series is relevant for.
87+ AdmissionResourceKey string = "resource"
88+ )
89+
7990// Regular config push metrics names.
8091const (
8192 MetricNameConfigPushCount = "ingress_controller_configuration_push_count"
@@ -86,6 +97,7 @@ const (
8697 MetricNameTranslationBrokenResources = "ingress_controller_translation_broken_resource_count"
8798 MetricNameTranslationDuration = "ingress_controller_translation_duration_milliseconds"
8899 MetricNameConfigPushDuration = "ingress_controller_configuration_push_duration_milliseconds"
100+ MetricNameAdmissionCount = "ingress_controller_admission_count"
89101)
90102
91103// Fallback config push metrics names.
@@ -202,6 +214,20 @@ var (
202214 []string {SuccessKey , ProtocolKey , DataplaneKey , InstanceIDKey },
203215 )
204216
217+ admissionCount = prometheus .NewCounterVec (
218+ prometheus.CounterOpts {
219+ Name : MetricNameAdmissionCount ,
220+ Help : fmt .Sprintf (
221+ "Count of admissions processed by Kong. " +
222+ "`%s` describes whether an admission was allowed. " +
223+ "`%s` describes the resource under admission. " ,
224+ AllowedKey ,
225+ AdmissionResourceKey ,
226+ ),
227+ },
228+ []string {AllowedKey , AdmissionResourceKey },
229+ )
230+
205231 configPushSize = prometheus .NewGaugeVec (
206232 prometheus.GaugeOpts {
207233 Name : MetricNameConfigPushSize ,
@@ -407,6 +433,7 @@ func init() {
407433 configPushDuration ,
408434 configPushSize ,
409435 configPushSuccessTime ,
436+ admissionCount ,
410437 fallbackTranslationCount ,
411438 fallbackTranslationBrokenResources ,
412439 fallbackTranslationDuration ,
@@ -493,6 +520,14 @@ func (c *GlobalCtrlRuntimeMetricsRecorder) RecordTranslationBrokenResources(coun
493520 }).Set (float64 (count ))
494521}
495522
523+ // RecordAdmissionResult records an admission request result.
524+ func (c * GlobalCtrlRuntimeMetricsRecorder ) RecordAdmissionResult (allowed bool , resource string ) {
525+ admissionCount .With (prometheus.Labels {
526+ AllowedKey : strconv .FormatBool (allowed ),
527+ AdmissionResourceKey : resource ,
528+ }).Inc ()
529+ }
530+
496531// RecordFallbackTranslationFailure records a failed fallback configuration translation.
497532func (c * GlobalCtrlRuntimeMetricsRecorder ) RecordFallbackTranslationFailure (duration time.Duration ) {
498533 fallbackTranslationCount .With (prometheus.Labels {
0 commit comments