@@ -122,6 +122,19 @@ var (
122
122
},
123
123
[]string {"cidr" },
124
124
)
125
+ noAvailableIPAddrs = prometheus .NewCounter (
126
+ prometheus.CounterOpts {
127
+ Name : "awscni_err_no_avail_addrs" ,
128
+ Help : "The number of pod IP assignments that fail due to no available IP addresses" ,
129
+ },
130
+ )
131
+ eniIPsInUse = prometheus .NewGaugeVec (
132
+ prometheus.GaugeOpts {
133
+ Name : "awscni_eni_util" ,
134
+ Help : "The number of allocated ips partitioned by eni" ,
135
+ },
136
+ []string {"eni" },
137
+ )
125
138
prometheusRegistered = false
126
139
)
127
140
@@ -344,6 +357,8 @@ func prometheusRegister() {
344
357
prometheus .MustRegister (forceRemovedIPs )
345
358
prometheus .MustRegister (totalPrefixes )
346
359
prometheus .MustRegister (ipsPerCidr )
360
+ prometheus .MustRegister (noAvailableIPAddrs )
361
+ prometheus .MustRegister (eniIPsInUse )
347
362
prometheusRegistered = true
348
363
}
349
364
}
@@ -437,6 +452,8 @@ func (ds *DataStore) ReadBackingStore(isv6Enabled bool) error {
437
452
cidr .IPAddresses [ipAddr .String ()] = addr
438
453
ds .assignPodIPAddressUnsafe (addr , allocation .IPAMKey , allocation .Metadata , time .Unix (0 , allocation .AllocationTimestamp ))
439
454
ds .log .Debugf ("Recovered %s => %s/%s" , allocation .IPAMKey , eni .ID , addr .Address )
455
+ // Increment ENI IP usage upon finding assigned ips
456
+ eniIPsInUse .WithLabelValues (eni .ID ).Inc ()
440
457
// Update prometheus for ips per cidr
441
458
// Secondary IP mode will have /32:1 and Prefix mode will have /28:<number of /32s>
442
459
ipsPerCidr .With (prometheus.Labels {"cidr" : cidr .Cidr .String ()}).Inc ()
@@ -522,6 +539,8 @@ func (ds *DataStore) AddENI(eniID string, deviceNumber int, isPrimary, isTrunk,
522
539
AvailableIPv4Cidrs : make (map [string ]* CidrInfo )}
523
540
524
541
enis .Set (float64 (len (ds .eniPool )))
542
+ // Initialize ENI IPs In Use to 0 when an ENI is created
543
+ eniIPsInUse .WithLabelValues (eniID ).Set (0 )
525
544
return nil
526
545
}
527
546
@@ -711,9 +730,12 @@ func (ds *DataStore) AssignPodIPv6Address(ipamKey IPAMKey, ipamMetadata IPAMMeta
711
730
delete (V6Cidr .IPAddresses , addr .Address )
712
731
return "" , - 1 , err
713
732
}
733
+ // Increment ENI IP usage on pod IPv6 allocation
734
+ eniIPsInUse .WithLabelValues (eni .ID ).Inc ()
714
735
return addr .Address , eni .DeviceNumber , nil
715
736
}
716
737
}
738
+ noAvailableIPAddrs .Inc ()
717
739
return "" , - 1 , errors .New ("assignPodIPv6AddressUnsafe: no available IP addresses" )
718
740
}
719
741
@@ -776,11 +798,14 @@ func (ds *DataStore) AssignPodIPv4Address(ipamKey IPAMKey, ipamMetadata IPAMMeta
776
798
ipsPerCidr .With (prometheus.Labels {"cidr" : availableCidr .Cidr .String ()}).Dec ()
777
799
return "" , - 1 , err
778
800
}
801
+ // Increment ENI IP usage on pod IPv4 allocation
802
+ eniIPsInUse .WithLabelValues (eni .ID ).Inc ()
779
803
return addr .Address , eni .DeviceNumber , nil
780
804
}
781
805
ds .log .Debugf ("AssignPodIPv4Address: ENI %s does not have available addresses" , eni .ID )
782
806
}
783
807
808
+ noAvailableIPAddrs .Inc ()
784
809
ds .log .Errorf ("DataStore has no available IP/Prefix addresses" )
785
810
return "" , - 1 , errors .New ("assignPodIPv4AddressUnsafe: no available IP/Prefix addresses" )
786
811
}
@@ -1072,6 +1097,8 @@ func (ds *DataStore) RemoveUnusedENIFromStore(warmIPTarget, minimumIPTarget, war
1072
1097
1073
1098
// Prometheus update
1074
1099
enis .Set (float64 (len (ds .eniPool )))
1100
+ // Delete ENI IPs In Use when ENI is removed
1101
+ eniIPsInUse .DeleteLabelValues (removableENI )
1075
1102
totalIPs .Set (float64 (ds .total ))
1076
1103
return removableENI
1077
1104
}
@@ -1126,6 +1153,8 @@ func (ds *DataStore) RemoveENIFromDataStore(eniID string, force bool) error {
1126
1153
1127
1154
// Prometheus gauge
1128
1155
enis .Set (float64 (len (ds .eniPool )))
1156
+ // Delete ENI IPs In Use when ENI is removed
1157
+ eniIPsInUse .DeleteLabelValues (eniID )
1129
1158
return nil
1130
1159
}
1131
1160
@@ -1166,6 +1195,8 @@ func (ds *DataStore) UnassignPodIPAddress(ipamKey IPAMKey) (e *ENI, ip string, d
1166
1195
ipsPerCidr .With (prometheus.Labels {"cidr" : availableCidr .Cidr .String ()}).Dec ()
1167
1196
ds .log .Infof ("UnassignPodIPAddress: sandbox %s's ipAddr %s, DeviceNumber %d" ,
1168
1197
ipamKey , addr .Address , eni .DeviceNumber )
1198
+ // Decrement ENI IP usage when a pod is deallocated
1199
+ eniIPsInUse .WithLabelValues (eni .ID ).Dec ()
1169
1200
return eni , addr .Address , eni .DeviceNumber , nil
1170
1201
}
1171
1202
0 commit comments