Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move primary IP count to separate metric to not affect the IPAM math #1579

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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