@@ -22,19 +22,6 @@ import (
2222
2323var metricsLog = logf .Log .WithName ("metrics" )
2424
25- func SetupMetrics () error {
26- metricsLog .V (1 ).Info ("Setting up metrics" )
27- if err := RegisterMetrics (); err != nil {
28- return err
29- }
30-
31- if err := RegisterCollectors (); err != nil {
32- return err
33- }
34-
35- return nil
36- }
37-
3825func RegisterMetrics () error {
3926 metricsLog .V (1 ).Info ("Registering metrics" )
4027 for _ , metric := range metricsList {
@@ -50,15 +37,32 @@ func RegisterMetrics() error {
5037
5138var metricsList = []prometheus.Collector {
5239 operatorInfoMetric ,
40+ resourceInfoMetric ,
5341 resourceRejectionsTotalMetric ,
5442}
5543
56- var operatorInfoMetric = prometheus .NewGaugeVec (
57- prometheus.GaugeOpts {
58- Name : "cx_operator_info" ,
59- Help : "Coralogix Operator information." ,
60- },
61- []string {"go_version" , "operator_version" , "coralogix_url" },
44+ var (
45+ operatorInfoMetric = prometheus .NewGaugeVec (
46+ prometheus.GaugeOpts {
47+ Name : "cx_operator_info" ,
48+ Help : "Coralogix Operator information." ,
49+ },
50+ []string {"go_version" , "operator_version" , "coralogix_url" },
51+ )
52+ resourceInfoMetric = prometheus .NewGaugeVec (
53+ prometheus.GaugeOpts {
54+ Name : "cx_operator_resource_info" ,
55+ Help : "Coralogix Operator custom resource information." ,
56+ },
57+ []string {"kind" , "name" , "namespace" , "status" },
58+ )
59+ resourceRejectionsTotalMetric = prometheus .NewCounterVec (
60+ prometheus.CounterOpts {
61+ Name : "cx_operator_resource_rejections_total" ,
62+ Help : "The total count of rejections by Coralogix Operator validation webhook." ,
63+ },
64+ []string {"kind" , "name" , "namespace" },
65+ )
6266)
6367
6468func SetOperatorInfoMetric (goVersion , operatorVersion , url string ) {
@@ -70,15 +74,27 @@ func SetOperatorInfoMetric(goVersion, operatorVersion, url string) {
7074 operatorInfoMetric .WithLabelValues (goVersion , operatorVersion , url ).Set (1 )
7175}
7276
73- var resourceRejectionsTotalMetric = prometheus .NewCounterVec (
74- prometheus.CounterOpts {
75- Name : "cx_operator_resource_rejections_total" ,
76- Help : "The total count of rejections by Coralogix Operator validation webhook." ,
77- },
78- []string {"kind" , "name" , "namespace" },
79- )
80-
8177func IncResourceRejectionsTotalMetric (kind , name , namespace string ) {
8278 metricsLog .V (1 ).Info ("Incrementing resource total rejected metric" , "kind" , kind )
8379 resourceRejectionsTotalMetric .WithLabelValues (kind , name , namespace ).Inc ()
8480}
81+
82+ func SetResourceInfoMetric (kind , name , namespace , status string ) {
83+ metricsLog .V (1 ).Info ("Setting resource info metric" ,
84+ "kind" , kind ,
85+ "name" , name ,
86+ "namespace" , namespace ,
87+ "status" , status ,
88+ )
89+ resourceInfoMetric .WithLabelValues (kind , name , namespace , status ).Set (1 )
90+ }
91+
92+ func DeleteResourceInfoMetric (kind , name , namespace , status string ) {
93+ metricsLog .V (1 ).Info ("Deleting resource info metric" ,
94+ "kind" , kind ,
95+ "name" , name ,
96+ "namespace" , namespace ,
97+ "status" , status ,
98+ )
99+ resourceInfoMetric .DeleteLabelValues (kind , name , namespace , status )
100+ }
0 commit comments