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
57 changes: 36 additions & 21 deletions cns/ipampool/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,81 @@ import (
"sigs.k8s.io/controller-runtime/pkg/metrics"
)

const (
subnetLabel = "subnet"
subnetCIDRLabel = "subnet_cidr"
)

var (
ipamAllocatedIPCount = prometheus.NewGauge(
ipamAllocatedIPCount = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "ipam_pod_allocated_ips",
Help: "Count of IPs CNS has allocated to Pods.",
},
[]string{subnetLabel, subnetCIDRLabel},
)
ipamAvailableIPCount = prometheus.NewGauge(
ipamAvailableIPCount = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "ipam_available_ips",
Help: "Available IP count.",
},
[]string{subnetLabel, subnetCIDRLabel},
)
ipamBatchSize = prometheus.NewGauge(
ipamBatchSize = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "ipam_batch_size",
Help: "IPAM IP pool batch size.",
},
[]string{subnetLabel, subnetCIDRLabel},
)
ipamCurrentAvailableIPcount = prometheus.NewGauge(
ipamCurrentAvailableIPcount = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "ipam_current_available_ips",
Help: "Current available IP count.",
},
[]string{subnetLabel, subnetCIDRLabel},
)
ipamExpectedAvailableIPCount = prometheus.NewGauge(
ipamExpectedAvailableIPCount = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "ipam_expect_available_ips",
Help: "Expected future available IP count assuming the Requested IP count is honored.",
},
[]string{subnetLabel, subnetCIDRLabel},
)
ipamMaxIPCount = prometheus.NewGauge(
ipamMaxIPCount = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "ipam_max_ips",
Help: "Maximum IP count.",
},
[]string{subnetLabel, subnetCIDRLabel},
)
ipamPendingProgramIPCount = prometheus.NewGauge(
ipamPendingProgramIPCount = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "ipam_pending_programming_ips",
Help: "Pending programming IP count.",
},
[]string{subnetLabel, subnetCIDRLabel},
)
ipamPendingReleaseIPCount = prometheus.NewGauge(
ipamPendingReleaseIPCount = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "ipam_pending_release_ips",
Help: "Pending release IP count.",
},
[]string{subnetLabel, subnetCIDRLabel},
)
ipamRequestedIPConfigCount = prometheus.NewGauge(
ipamRequestedIPConfigCount = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "ipam_requested_ips",
Help: "Requested IP count.",
},
[]string{subnetLabel, subnetCIDRLabel},
)
ipamTotalIPCount = prometheus.NewGauge(
ipamTotalIPCount = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "ipam_total_ips",
Help: "Count of total IP pool size allocated to CNS by DNC.",
},
[]string{subnetLabel, subnetCIDRLabel},
)
)

Expand All @@ -83,15 +98,15 @@ func init() {
)
}

func observeIPPoolState(state ipPoolState, meta metaState) {
ipamAllocatedIPCount.Set(float64(state.allocatedToPods))
ipamAvailableIPCount.Set(float64(state.available))
ipamBatchSize.Set(float64(meta.batch))
ipamCurrentAvailableIPcount.Set(float64(state.currentAvailableIPs))
ipamExpectedAvailableIPCount.Set(float64(state.expectedAvailableIPs))
ipamMaxIPCount.Set(float64(meta.max))
ipamPendingProgramIPCount.Set(float64(state.pendingProgramming))
ipamPendingReleaseIPCount.Set(float64(state.pendingRelease))
ipamRequestedIPConfigCount.Set(float64(state.requestedIPs))
ipamTotalIPCount.Set(float64(state.totalIPs))
func observeIPPoolState(state ipPoolState, meta metaState, labels []string) {
ipamAllocatedIPCount.WithLabelValues(labels...).Set(float64(state.allocatedToPods))
ipamAvailableIPCount.WithLabelValues(labels...).Set(float64(state.available))
ipamBatchSize.WithLabelValues(labels...).Set(float64(meta.batch))
ipamCurrentAvailableIPcount.WithLabelValues(labels...).Set(float64(state.currentAvailableIPs))
ipamExpectedAvailableIPCount.WithLabelValues(labels...).Set(float64(state.expectedAvailableIPs))
ipamMaxIPCount.WithLabelValues(labels...).Set(float64(meta.max))
ipamPendingProgramIPCount.WithLabelValues(labels...).Set(float64(state.pendingProgramming))
ipamPendingReleaseIPCount.WithLabelValues(labels...).Set(float64(state.pendingRelease))
ipamRequestedIPConfigCount.WithLabelValues(labels...).Set(float64(state.requestedIPs))
ipamTotalIPCount.WithLabelValues(labels...).Set(float64(state.totalIPs))
}
10 changes: 9 additions & 1 deletion cns/ipampool/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ type Monitor struct {
once sync.Once
}

// Global Variables for Subnet and SubnetAddressSpace
var subnet, subnetCIDR string

func NewMonitor(httpService cns.HTTPService, nnccli nodeNetworkConfigSpecUpdater, opts *Options) *Monitor {
if opts.RefreshDelay < 1 {
opts.RefreshDelay = DefaultRefreshDelay
Expand Down Expand Up @@ -87,6 +90,11 @@ func (pm *Monitor) Start(ctx context.Context) error {
case nnc := <-pm.nncSource: // received a new NodeNetworkConfig, extract the data from it and re-reconcile.
pm.spec = nnc.Spec
scaler := nnc.Status.Scaler

// Set SubnetName and SubnetAddressSpace values to the global subnet and subnetCIDR variables.
subnet = nnc.Status.NetworkContainers[0].SubnetName
subnetCIDR = nnc.Status.NetworkContainers[0].SubnetAddressSpace

pm.metastate.batch = scaler.BatchSize
pm.metastate.max = scaler.MaxIPCount
pm.metastate.minFreeCount, pm.metastate.maxFreeCount = CalculateMinFreeIPs(scaler), CalculateMaxFreeIPs(scaler)
Expand Down Expand Up @@ -146,7 +154,7 @@ func (pm *Monitor) reconcile(ctx context.Context) error {
allocatedIPs := pm.httpService.GetPodIPConfigState()
state := buildIPPoolState(allocatedIPs, pm.spec)
logger.Printf("ipam-pool-monitor state %+v", state)
observeIPPoolState(state, pm.metastate)
observeIPPoolState(state, pm.metastate, []string{subnet, subnetCIDR})

switch {
// pod count is increasing
Expand Down