Skip to content

Commit 99ce6ae

Browse files
authored
Move primary IP count to separate metric to not affect the IPAM math (#1579)
move primary IP count to separate metric to not affect the ipam math Signed-off-by: Evan Baker <[email protected]> Signed-off-by: Evan Baker <[email protected]>
1 parent 5750e0d commit 99ce6ae

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

cns/ipampool/metrics.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ var (
7878
},
7979
[]string{subnetLabel, subnetCIDRLabel, podnetARMIDLabel},
8080
)
81+
ipamPrimaryIPCount = prometheus.NewGaugeVec(
82+
prometheus.GaugeOpts{
83+
Name: "cx_ipam_primary_ips",
84+
Help: "NC Primary IP count.",
85+
ConstLabels: prometheus.Labels{customerMetricLabel: customerMetricLabelValue},
86+
},
87+
[]string{subnetLabel, subnetCIDRLabel, podnetARMIDLabel},
88+
)
8189
ipamRequestedIPConfigCount = prometheus.NewGaugeVec(
8290
prometheus.GaugeOpts{
8391
Name: "cx_ipam_requested_ips",
@@ -106,6 +114,7 @@ func init() {
106114
ipamMaxIPCount,
107115
ipamPendingProgramIPCount,
108116
ipamPendingReleaseIPCount,
117+
ipamPrimaryIPCount,
109118
ipamRequestedIPConfigCount,
110119
ipamTotalIPCount,
111120
)
@@ -120,6 +129,7 @@ func observeIPPoolState(state ipPoolState, meta metaState, labels []string) {
120129
ipamMaxIPCount.WithLabelValues(labels...).Set(float64(meta.max))
121130
ipamPendingProgramIPCount.WithLabelValues(labels...).Set(float64(state.pendingProgramming))
122131
ipamPendingReleaseIPCount.WithLabelValues(labels...).Set(float64(state.pendingRelease))
132+
ipamPrimaryIPCount.WithLabelValues(labels...).Set(float64(len(meta.primaryIPAddresses)))
123133
ipamRequestedIPConfigCount.WithLabelValues(labels...).Set(float64(state.requestedIPs))
124134
ipamTotalIPCount.WithLabelValues(labels...).Set(float64(state.totalIPs))
125135
}

cns/ipampool/monitor.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ type ipPoolState struct {
178178
totalIPs int64
179179
}
180180

181-
func buildIPPoolState(ips map[string]cns.IPConfigurationStatus, spec v1alpha.NodeNetworkConfigSpec, primaryIPAddresses map[string]struct{}) ipPoolState {
181+
func buildIPPoolState(ips map[string]cns.IPConfigurationStatus, spec v1alpha.NodeNetworkConfigSpec) ipPoolState {
182182
state := ipPoolState{
183-
totalIPs: int64(len(primaryIPAddresses) + len(ips)),
183+
totalIPs: int64(len(ips)),
184184
requestedIPs: spec.RequestedIPCount,
185185
}
186186
for _, v := range ips {
@@ -205,22 +205,22 @@ var statelogDownsample int
205205
func (pm *Monitor) reconcile(ctx context.Context) error {
206206
allocatedIPs := pm.httpService.GetPodIPConfigState()
207207
meta := pm.metastate
208-
state := buildIPPoolState(allocatedIPs, pm.spec, meta.primaryIPAddresses)
208+
state := buildIPPoolState(allocatedIPs, pm.spec)
209209
observeIPPoolState(state, meta, []string{subnet, subnetCIDR, subnetARMID})
210210

211+
// log every 30th reconcile to reduce the AI load. we will always log when the monitor
212+
// changes the pool, below.
213+
if statelogDownsample = (statelogDownsample + 1) % 30; statelogDownsample == 0 { //nolint:gomnd //downsample by 30
214+
logger.Printf("ipam-pool-monitor state: %+v, meta: %+v", state, meta)
215+
}
216+
211217
// if the subnet is exhausted, overwrite the batch/minfree/maxfree in the meta copy for this iteration
212218
if meta.exhausted {
213219
meta.batch = 1
214220
meta.minFreeCount = 1
215221
meta.maxFreeCount = 2
216222
}
217223

218-
// log every 30th reconcile to reduce the AI load. we will always log when the monitor
219-
// changes the pool, below.
220-
if statelogDownsample = (statelogDownsample + 1) % 30; statelogDownsample == 0 { //nolint:gomnd //downsample by 30
221-
logger.Printf("ipam-pool-monitor state %+v", state)
222-
}
223-
224224
switch {
225225
// pod count is increasing
226226
case state.expectedAvailableIPs < meta.minFreeCount:

0 commit comments

Comments
 (0)