Skip to content
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
16 changes: 9 additions & 7 deletions cns/ipampool/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ var (
Help: "IPAM IP pool batch size.",
},
)
ipamFreeIPCount = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "ipam_free_ips",
Help: "Free IP count.",
},
)
ipamIPPool = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "ipam_ip_pool_size",
Expand Down Expand Up @@ -66,17 +60,25 @@ var (
Help: "Unallocated IP count.",
},
)
ipamRequestedUnallocatedIPCount = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "ipam_requested_unallocated_ips",
Help: "Unallocated IP count using total requested IPs.",
},
)
)

func init() {
metrics.Registry.MustRegister(
ipamAllocatedIPCount,
ipamAvailableIPCount,
ipamBatchSize,
ipamFreeIPCount,
ipamIPPool,
ipamMaxIPCount,
ipamPendingProgramIPCount,
ipamPendingReleaseIPCount,
ipamRequestedIPConfigCount,
ipamRequestedUnallocatedIPCount,
ipamUnallocatedIPCount,
)
}
18 changes: 9 additions & 9 deletions cns/ipampool/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,29 @@ func (pm *Monitor) reconcile(ctx context.Context) error {
allocatedPodIPCount := len(pm.httpService.GetAllocatedIPConfigs())
pendingReleaseIPCount := len(pm.httpService.GetPendingReleaseIPConfigs())
availableIPConfigCount := len(pm.httpService.GetAvailableIPConfigs()) // TODO: add pending allocation count to real cns
requestedIPConfigCount := pm.spec.RequestedIPCount
unallocatedIPConfigCount := cnsPodIPConfigCount - allocatedPodIPCount
freeIPConfigCount := requestedIPConfigCount - int64(allocatedPodIPCount)
requestedIPConfigCount := int(pm.spec.RequestedIPCount)
unallocated := cnsPodIPConfigCount - allocatedPodIPCount
requestedUnallocated := requestedIPConfigCount - allocatedPodIPCount
batchSize := pm.scaler.BatchSize
maxIPCount := pm.scaler.MaxIPCount

msg := fmt.Sprintf("[ipam-pool-monitor] Pool Size: %v, Goal Size: %v, BatchSize: %v, MaxIPCount: %v, Allocated: %v, Available: %v, Pending Release: %v, Free: %v, Pending Program: %v",
cnsPodIPConfigCount, pm.spec.RequestedIPCount, batchSize, maxIPCount, allocatedPodIPCount, availableIPConfigCount, pendingReleaseIPCount, freeIPConfigCount, pendingProgramCount)
msg := fmt.Sprintf("[ipam-pool-monitor] Pool Size: %d, Goal Size: %d, BatchSize: %d, MaxIPCount: %d, Allocated: %d, Available: %d, Pending Release: %d, Unallocated: %d, Requested Unallocated: %d Pending Program: %d", //nolint:lll // ignore
cnsPodIPConfigCount, pm.spec.RequestedIPCount, batchSize, maxIPCount, allocatedPodIPCount, availableIPConfigCount, pendingReleaseIPCount, unallocated, requestedUnallocated, pendingProgramCount)

ipamAllocatedIPCount.Set(float64(allocatedPodIPCount))
ipamAvailableIPCount.Set(float64(availableIPConfigCount))
ipamBatchSize.Set(float64(batchSize))
ipamFreeIPCount.Set(float64(freeIPConfigCount))
ipamIPPool.Set(float64(cnsPodIPConfigCount))
ipamMaxIPCount.Set(float64(maxIPCount))
ipamPendingProgramIPCount.Set(float64(pendingProgramCount))
ipamPendingReleaseIPCount.Set(float64(pendingReleaseIPCount))
ipamRequestedIPConfigCount.Set(float64(requestedIPConfigCount))
ipamUnallocatedIPCount.Set(float64(unallocatedIPConfigCount))
ipamUnallocatedIPCount.Set(float64(unallocated))
ipamRequestedUnallocatedIPCount.Set(float64(requestedUnallocated))

switch {
// pod count is increasing
case freeIPConfigCount < int64(pm.state.minFreeCount):
case requestedUnallocated < pm.state.minFreeCount:
if pm.spec.RequestedIPCount == maxIPCount {
// If we're already at the maxIPCount, don't try to increase
return nil
Expand All @@ -135,7 +135,7 @@ func (pm *Monitor) reconcile(ctx context.Context) error {
return pm.increasePoolSize(ctx)

// pod count is decreasing
case freeIPConfigCount >= int64(pm.state.maxFreeCount):
case unallocated >= pm.state.maxFreeCount:
logger.Printf("[ipam-pool-monitor] Decreasing pool size...%s ", msg)
return pm.decreasePoolSize(ctx, pendingReleaseIPCount)

Expand Down