|
| 1 | +/* |
| 2 | +Copyright 2025 Tim Ebert. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package metrics |
| 18 | + |
| 19 | +import ( |
| 20 | + "github.com/prometheus/client_golang/prometheus" |
| 21 | + |
| 22 | + shardingv1alpha1 "github.com/timebertt/kubernetes-controller-sharding/pkg/apis/sharding/v1alpha1" |
| 23 | + "github.com/timebertt/kubernetes-controller-sharding/pkg/metrics/exporter" |
| 24 | +) |
| 25 | + |
| 26 | +var ControllerRingExporter = exporter.Exporter[*shardingv1alpha1.ControllerRing, *shardingv1alpha1.ControllerRingList]{ |
| 27 | + Namespace: Namespace, |
| 28 | + Subsystem: "controllerring", |
| 29 | + |
| 30 | + StaticLabelKeys: []string{"controllerring", "uid"}, |
| 31 | + GenerateStaticLabelValues: func(controllerRing *shardingv1alpha1.ControllerRing) []string { |
| 32 | + return []string{controllerRing.Name, string(controllerRing.UID)} |
| 33 | + }, |
| 34 | + |
| 35 | + Metrics: []exporter.Metric[*shardingv1alpha1.ControllerRing]{ |
| 36 | + { |
| 37 | + Name: "metadata_generation", |
| 38 | + Help: "The generation of a ControllerRing", |
| 39 | + |
| 40 | + Generate: func(desc *prometheus.Desc, controllerRing *shardingv1alpha1.ControllerRing, staticLabelValues []string, ch chan<- prometheus.Metric) { |
| 41 | + ch <- prometheus.MustNewConstMetric( |
| 42 | + desc, |
| 43 | + prometheus.GaugeValue, |
| 44 | + float64(controllerRing.Generation), |
| 45 | + staticLabelValues..., |
| 46 | + ) |
| 47 | + }, |
| 48 | + }, |
| 49 | + { |
| 50 | + Name: "observed_generation", |
| 51 | + Help: "The latest generation observed by the ControllerRing controller", |
| 52 | + |
| 53 | + Generate: func(desc *prometheus.Desc, controllerRing *shardingv1alpha1.ControllerRing, staticLabelValues []string, ch chan<- prometheus.Metric) { |
| 54 | + ch <- prometheus.MustNewConstMetric( |
| 55 | + desc, |
| 56 | + prometheus.GaugeValue, |
| 57 | + float64(controllerRing.Status.ObservedGeneration), |
| 58 | + staticLabelValues..., |
| 59 | + ) |
| 60 | + }, |
| 61 | + }, |
| 62 | + { |
| 63 | + Name: "status_shards", |
| 64 | + Help: "The ControllerRing's total number of shards observed by the ControllerRing controller", |
| 65 | + |
| 66 | + Generate: func(desc *prometheus.Desc, controllerRing *shardingv1alpha1.ControllerRing, staticLabelValues []string, ch chan<- prometheus.Metric) { |
| 67 | + ch <- prometheus.MustNewConstMetric( |
| 68 | + desc, |
| 69 | + prometheus.GaugeValue, |
| 70 | + float64(controllerRing.Status.Shards), |
| 71 | + staticLabelValues..., |
| 72 | + ) |
| 73 | + }, |
| 74 | + }, |
| 75 | + { |
| 76 | + Name: "status_available_shards", |
| 77 | + Help: "The ControllerRing's number of available shards observed by the ControllerRing controller", |
| 78 | + |
| 79 | + Generate: func(desc *prometheus.Desc, controllerRing *shardingv1alpha1.ControllerRing, staticLabelValues []string, ch chan<- prometheus.Metric) { |
| 80 | + ch <- prometheus.MustNewConstMetric( |
| 81 | + desc, |
| 82 | + prometheus.GaugeValue, |
| 83 | + float64(controllerRing.Status.AvailableShards), |
| 84 | + staticLabelValues..., |
| 85 | + ) |
| 86 | + }, |
| 87 | + }, |
| 88 | + }, |
| 89 | +} |
0 commit comments