Skip to content

Commit 569c946

Browse files
authored
Subnet labels (#1238)
* 12622609: Dimensions to metrics. * Modified the constants declaration. * Made a slight change to make the observeIPPoolState() method inline and remove a whitespace. * Modified label values to stay consistent with other prometheus labels.
1 parent 8f9d6b3 commit 569c946

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

cns/ipampool/metrics.go

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,81 @@ import (
55
"sigs.k8s.io/controller-runtime/pkg/metrics"
66
)
77

8+
const (
9+
subnetLabel = "subnet"
10+
subnetCIDRLabel = "subnet_cidr"
11+
)
12+
813
var (
9-
ipamAllocatedIPCount = prometheus.NewGauge(
14+
ipamAllocatedIPCount = prometheus.NewGaugeVec(
1015
prometheus.GaugeOpts{
1116
Name: "ipam_pod_allocated_ips",
1217
Help: "Count of IPs CNS has allocated to Pods.",
1318
},
19+
[]string{subnetLabel, subnetCIDRLabel},
1420
)
15-
ipamAvailableIPCount = prometheus.NewGauge(
21+
ipamAvailableIPCount = prometheus.NewGaugeVec(
1622
prometheus.GaugeOpts{
1723
Name: "ipam_available_ips",
1824
Help: "Available IP count.",
1925
},
26+
[]string{subnetLabel, subnetCIDRLabel},
2027
)
21-
ipamBatchSize = prometheus.NewGauge(
28+
ipamBatchSize = prometheus.NewGaugeVec(
2229
prometheus.GaugeOpts{
2330
Name: "ipam_batch_size",
2431
Help: "IPAM IP pool batch size.",
2532
},
33+
[]string{subnetLabel, subnetCIDRLabel},
2634
)
27-
ipamCurrentAvailableIPcount = prometheus.NewGauge(
35+
ipamCurrentAvailableIPcount = prometheus.NewGaugeVec(
2836
prometheus.GaugeOpts{
2937
Name: "ipam_current_available_ips",
3038
Help: "Current available IP count.",
3139
},
40+
[]string{subnetLabel, subnetCIDRLabel},
3241
)
33-
ipamExpectedAvailableIPCount = prometheus.NewGauge(
42+
ipamExpectedAvailableIPCount = prometheus.NewGaugeVec(
3443
prometheus.GaugeOpts{
3544
Name: "ipam_expect_available_ips",
3645
Help: "Expected future available IP count assuming the Requested IP count is honored.",
3746
},
47+
[]string{subnetLabel, subnetCIDRLabel},
3848
)
39-
ipamMaxIPCount = prometheus.NewGauge(
49+
ipamMaxIPCount = prometheus.NewGaugeVec(
4050
prometheus.GaugeOpts{
4151
Name: "ipam_max_ips",
4252
Help: "Maximum IP count.",
4353
},
54+
[]string{subnetLabel, subnetCIDRLabel},
4455
)
45-
ipamPendingProgramIPCount = prometheus.NewGauge(
56+
ipamPendingProgramIPCount = prometheus.NewGaugeVec(
4657
prometheus.GaugeOpts{
4758
Name: "ipam_pending_programming_ips",
4859
Help: "Pending programming IP count.",
4960
},
61+
[]string{subnetLabel, subnetCIDRLabel},
5062
)
51-
ipamPendingReleaseIPCount = prometheus.NewGauge(
63+
ipamPendingReleaseIPCount = prometheus.NewGaugeVec(
5264
prometheus.GaugeOpts{
5365
Name: "ipam_pending_release_ips",
5466
Help: "Pending release IP count.",
5567
},
68+
[]string{subnetLabel, subnetCIDRLabel},
5669
)
57-
ipamRequestedIPConfigCount = prometheus.NewGauge(
70+
ipamRequestedIPConfigCount = prometheus.NewGaugeVec(
5871
prometheus.GaugeOpts{
5972
Name: "ipam_requested_ips",
6073
Help: "Requested IP count.",
6174
},
75+
[]string{subnetLabel, subnetCIDRLabel},
6276
)
63-
ipamTotalIPCount = prometheus.NewGauge(
77+
ipamTotalIPCount = prometheus.NewGaugeVec(
6478
prometheus.GaugeOpts{
6579
Name: "ipam_total_ips",
6680
Help: "Count of total IP pool size allocated to CNS by DNC.",
6781
},
82+
[]string{subnetLabel, subnetCIDRLabel},
6883
)
6984
)
7085

@@ -83,15 +98,15 @@ func init() {
8398
)
8499
}
85100

86-
func observeIPPoolState(state ipPoolState, meta metaState) {
87-
ipamAllocatedIPCount.Set(float64(state.allocatedToPods))
88-
ipamAvailableIPCount.Set(float64(state.available))
89-
ipamBatchSize.Set(float64(meta.batch))
90-
ipamCurrentAvailableIPcount.Set(float64(state.currentAvailableIPs))
91-
ipamExpectedAvailableIPCount.Set(float64(state.expectedAvailableIPs))
92-
ipamMaxIPCount.Set(float64(meta.max))
93-
ipamPendingProgramIPCount.Set(float64(state.pendingProgramming))
94-
ipamPendingReleaseIPCount.Set(float64(state.pendingRelease))
95-
ipamRequestedIPConfigCount.Set(float64(state.requestedIPs))
96-
ipamTotalIPCount.Set(float64(state.totalIPs))
101+
func observeIPPoolState(state ipPoolState, meta metaState, labels []string) {
102+
ipamAllocatedIPCount.WithLabelValues(labels...).Set(float64(state.allocatedToPods))
103+
ipamAvailableIPCount.WithLabelValues(labels...).Set(float64(state.available))
104+
ipamBatchSize.WithLabelValues(labels...).Set(float64(meta.batch))
105+
ipamCurrentAvailableIPcount.WithLabelValues(labels...).Set(float64(state.currentAvailableIPs))
106+
ipamExpectedAvailableIPCount.WithLabelValues(labels...).Set(float64(state.expectedAvailableIPs))
107+
ipamMaxIPCount.WithLabelValues(labels...).Set(float64(meta.max))
108+
ipamPendingProgramIPCount.WithLabelValues(labels...).Set(float64(state.pendingProgramming))
109+
ipamPendingReleaseIPCount.WithLabelValues(labels...).Set(float64(state.pendingRelease))
110+
ipamRequestedIPConfigCount.WithLabelValues(labels...).Set(float64(state.requestedIPs))
111+
ipamTotalIPCount.WithLabelValues(labels...).Set(float64(state.totalIPs))
97112
}

cns/ipampool/monitor.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ type Monitor struct {
4949
once sync.Once
5050
}
5151

52+
// Global Variables for Subnet and SubnetAddressSpace
53+
var subnet, subnetCIDR string
54+
5255
func NewMonitor(httpService cns.HTTPService, nnccli nodeNetworkConfigSpecUpdater, opts *Options) *Monitor {
5356
if opts.RefreshDelay < 1 {
5457
opts.RefreshDelay = DefaultRefreshDelay
@@ -90,6 +93,11 @@ func (pm *Monitor) Start(ctx context.Context) error {
9093
case nnc := <-pm.nncSource: // received a new NodeNetworkConfig, extract the data from it and re-reconcile.
9194
pm.spec = nnc.Spec
9295
scaler := nnc.Status.Scaler
96+
97+
// Set SubnetName and SubnetAddressSpace values to the global subnet and subnetCIDR variables.
98+
subnet = nnc.Status.NetworkContainers[0].SubnetName
99+
subnetCIDR = nnc.Status.NetworkContainers[0].SubnetAddressSpace
100+
93101
pm.metastate.batch = scaler.BatchSize
94102
pm.metastate.max = scaler.MaxIPCount
95103
pm.metastate.minFreeCount, pm.metastate.maxFreeCount = CalculateMinFreeIPs(scaler), CalculateMaxFreeIPs(scaler)
@@ -149,7 +157,7 @@ func (pm *Monitor) reconcile(ctx context.Context) error {
149157
allocatedIPs := pm.httpService.GetPodIPConfigState()
150158
state := buildIPPoolState(allocatedIPs, pm.spec)
151159
logger.Printf("ipam-pool-monitor state %+v", state)
152-
observeIPPoolState(state, pm.metastate)
160+
observeIPPoolState(state, pm.metastate, []string{subnet, subnetCIDR})
153161

154162
switch {
155163
// pod count is increasing

0 commit comments

Comments
 (0)