From 65dc9877f1516f20d59051d8c0dfd13420783a65 Mon Sep 17 00:00:00 2001 From: Evan Baker Date: Wed, 7 Sep 2022 01:59:38 +0000 Subject: [PATCH] move primary IP count to separate metric to not affect the ipam math Signed-off-by: Evan Baker --- cns/ipampool/metrics.go | 10 ++++++++++ cns/ipampool/monitor.go | 18 +++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/cns/ipampool/metrics.go b/cns/ipampool/metrics.go index 7c2737a1371..e8b75c05e96 100644 --- a/cns/ipampool/metrics.go +++ b/cns/ipampool/metrics.go @@ -78,6 +78,14 @@ var ( }, []string{subnetLabel, subnetCIDRLabel, podnetARMIDLabel}, ) + ipamPrimaryIPCount = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "cx_ipam_primary_ips", + Help: "NC Primary IP count.", + ConstLabels: prometheus.Labels{customerMetricLabel: customerMetricLabelValue}, + }, + []string{subnetLabel, subnetCIDRLabel, podnetARMIDLabel}, + ) ipamRequestedIPConfigCount = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "cx_ipam_requested_ips", @@ -106,6 +114,7 @@ func init() { ipamMaxIPCount, ipamPendingProgramIPCount, ipamPendingReleaseIPCount, + ipamPrimaryIPCount, ipamRequestedIPConfigCount, ipamTotalIPCount, ) @@ -120,6 +129,7 @@ func observeIPPoolState(state ipPoolState, meta metaState, labels []string) { ipamMaxIPCount.WithLabelValues(labels...).Set(float64(meta.max)) ipamPendingProgramIPCount.WithLabelValues(labels...).Set(float64(state.pendingProgramming)) ipamPendingReleaseIPCount.WithLabelValues(labels...).Set(float64(state.pendingRelease)) + ipamPrimaryIPCount.WithLabelValues(labels...).Set(float64(len(meta.primaryIPAddresses))) ipamRequestedIPConfigCount.WithLabelValues(labels...).Set(float64(state.requestedIPs)) ipamTotalIPCount.WithLabelValues(labels...).Set(float64(state.totalIPs)) } diff --git a/cns/ipampool/monitor.go b/cns/ipampool/monitor.go index f023e5515f8..0344128a3dc 100644 --- a/cns/ipampool/monitor.go +++ b/cns/ipampool/monitor.go @@ -178,9 +178,9 @@ type ipPoolState struct { totalIPs int64 } -func buildIPPoolState(ips map[string]cns.IPConfigurationStatus, spec v1alpha.NodeNetworkConfigSpec, primaryIPAddresses map[string]struct{}) ipPoolState { +func buildIPPoolState(ips map[string]cns.IPConfigurationStatus, spec v1alpha.NodeNetworkConfigSpec) ipPoolState { state := ipPoolState{ - totalIPs: int64(len(primaryIPAddresses) + len(ips)), + totalIPs: int64(len(ips)), requestedIPs: spec.RequestedIPCount, } for _, v := range ips { @@ -205,9 +205,15 @@ var statelogDownsample int func (pm *Monitor) reconcile(ctx context.Context) error { allocatedIPs := pm.httpService.GetPodIPConfigState() meta := pm.metastate - state := buildIPPoolState(allocatedIPs, pm.spec, meta.primaryIPAddresses) + state := buildIPPoolState(allocatedIPs, pm.spec) observeIPPoolState(state, meta, []string{subnet, subnetCIDR, subnetARMID}) + // log every 30th reconcile to reduce the AI load. we will always log when the monitor + // changes the pool, below. + if statelogDownsample = (statelogDownsample + 1) % 30; statelogDownsample == 0 { //nolint:gomnd //downsample by 30 + logger.Printf("ipam-pool-monitor state: %+v, meta: %+v", state, meta) + } + // if the subnet is exhausted, overwrite the batch/minfree/maxfree in the meta copy for this iteration if meta.exhausted { meta.batch = 1 @@ -215,12 +221,6 @@ func (pm *Monitor) reconcile(ctx context.Context) error { meta.maxFreeCount = 2 } - // log every 30th reconcile to reduce the AI load. we will always log when the monitor - // changes the pool, below. - if statelogDownsample = (statelogDownsample + 1) % 30; statelogDownsample == 0 { //nolint:gomnd //downsample by 30 - logger.Printf("ipam-pool-monitor state %+v", state) - } - switch { // pod count is increasing case state.expectedAvailableIPs < meta.minFreeCount: