Skip to content

Commit

Permalink
move primary IP count to separate metric to not affect the ipam math
Browse files Browse the repository at this point in the history
Signed-off-by: Evan Baker <[email protected]>
  • Loading branch information
rbtr committed Sep 8, 2022
1 parent 5750e0d commit 3010f64
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
10 changes: 10 additions & 0 deletions cns/ipampool/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -106,6 +114,7 @@ func init() {
ipamMaxIPCount,
ipamPendingProgramIPCount,
ipamPendingReleaseIPCount,
ipamPrimaryIPCount,
ipamRequestedIPConfigCount,
ipamTotalIPCount,
)
Expand All @@ -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))
}
18 changes: 9 additions & 9 deletions cns/ipampool/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -205,22 +205,22 @@ 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
meta.minFreeCount = 1
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:
Expand Down

0 comments on commit 3010f64

Please sign in to comment.