@@ -122,18 +122,18 @@ var (
122
122
},
123
123
[]string {"cidr" },
124
124
)
125
- noAvailableAddrs = prometheus .NewCounter (
125
+ noAvailableIPAddrs = prometheus .NewCounter (
126
126
prometheus.CounterOpts {
127
127
Name : "awscni_err_no_avail_addrs" ,
128
- Help : "The number of IP/Prefix assignments that fail due to no available addresses at the ENI level " ,
128
+ Help : "The number of pod IP assignments that fail due to no available IP addresses " ,
129
129
},
130
130
)
131
- eniUtilization = prometheus .NewGaugeVec (
131
+ eniIPsInUse = prometheus .NewGaugeVec (
132
132
prometheus.GaugeOpts {
133
133
Name : "awscni_eni_util" ,
134
134
Help : "The number of allocated ips partitioned by eni" ,
135
135
},
136
- []string {"fn " },
136
+ []string {"eni " },
137
137
)
138
138
prometheusRegistered = false
139
139
)
@@ -357,8 +357,8 @@ func prometheusRegister() {
357
357
prometheus .MustRegister (forceRemovedIPs )
358
358
prometheus .MustRegister (totalPrefixes )
359
359
prometheus .MustRegister (ipsPerCidr )
360
- prometheus .MustRegister (noAvailableAddrs )
361
- prometheus .MustRegister (eniUtilization )
360
+ prometheus .MustRegister (noAvailableIPAddrs )
361
+ prometheus .MustRegister (eniIPsInUse )
362
362
prometheusRegistered = true
363
363
}
364
364
}
@@ -452,6 +452,8 @@ func (ds *DataStore) ReadBackingStore(isv6Enabled bool) error {
452
452
cidr .IPAddresses [ipAddr .String ()] = addr
453
453
ds .assignPodIPAddressUnsafe (addr , allocation .IPAMKey , allocation .Metadata , time .Unix (0 , allocation .AllocationTimestamp ))
454
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 ()
455
457
// Update prometheus for ips per cidr
456
458
// Secondary IP mode will have /32:1 and Prefix mode will have /28:<number of /32s>
457
459
ipsPerCidr .With (prometheus.Labels {"cidr" : cidr .Cidr .String ()}).Inc ()
@@ -536,8 +538,9 @@ func (ds *DataStore) AddENI(eniID string, deviceNumber int, isPrimary, isTrunk,
536
538
DeviceNumber : deviceNumber ,
537
539
AvailableIPv4Cidrs : make (map [string ]* CidrInfo )}
538
540
539
- ds .GetENIUtilization ()
540
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 )
541
544
return nil
542
545
}
543
546
@@ -727,10 +730,12 @@ func (ds *DataStore) AssignPodIPv6Address(ipamKey IPAMKey, ipamMetadata IPAMMeta
727
730
delete (V6Cidr .IPAddresses , addr .Address )
728
731
return "" , - 1 , err
729
732
}
733
+ // Increment ENI IP usage on pod IPv6 allocation
734
+ eniIPsInUse .WithLabelValues (eni .ID ).Inc ()
730
735
return addr .Address , eni .DeviceNumber , nil
731
736
}
732
737
}
733
- noAvailableAddrs .Inc ()
738
+ noAvailableIPAddrs .Inc ()
734
739
return "" , - 1 , errors .New ("assignPodIPv6AddressUnsafe: no available IP addresses" )
735
740
}
736
741
@@ -793,12 +798,14 @@ func (ds *DataStore) AssignPodIPv4Address(ipamKey IPAMKey, ipamMetadata IPAMMeta
793
798
ipsPerCidr .With (prometheus.Labels {"cidr" : availableCidr .Cidr .String ()}).Dec ()
794
799
return "" , - 1 , err
795
800
}
801
+ // Increment ENI IP usage on pod IPv4 allocation
802
+ eniIPsInUse .WithLabelValues (eni .ID ).Inc ()
796
803
return addr .Address , eni .DeviceNumber , nil
797
804
}
798
805
ds .log .Debugf ("AssignPodIPv4Address: ENI %s does not have available addresses" , eni .ID )
799
806
}
800
807
801
- noAvailableAddrs .Inc ()
808
+ noAvailableIPAddrs .Inc ()
802
809
ds .log .Errorf ("DataStore has no available IP/Prefix addresses" )
803
810
return "" , - 1 , errors .New ("assignPodIPv4AddressUnsafe: no available IP/Prefix addresses" )
804
811
}
@@ -815,7 +822,6 @@ func (ds *DataStore) assignPodIPAddressUnsafe(addr *AddressInfo, ipamKey IPAMKey
815
822
addr .IPAMMetadata = ipamMetadata
816
823
addr .AssignedTime = assignedTime
817
824
818
- ds .log .Debugf ("IP allocation request" )
819
825
ds .assigned ++
820
826
// Prometheus gauge
821
827
assignedIPs .Set (float64 (ds .assigned ))
@@ -832,7 +838,6 @@ func (ds *DataStore) unassignPodIPAddressUnsafe(addr *AddressInfo) {
832
838
addr .IPAMKey = IPAMKey {} // unassign the addr
833
839
addr .IPAMMetadata = IPAMMetadata {}
834
840
ds .assigned --
835
- ds .log .Debugf ("IP deallocation request" )
836
841
// Prometheus gauge
837
842
assignedIPs .Set (float64 (ds .assigned ))
838
843
}
@@ -886,24 +891,6 @@ func (ds *DataStore) GetIPStats(addressFamily string) *DataStoreStats {
886
891
return stats
887
892
}
888
893
889
- // GetENIUtilization updates a Prometheus gauge vector with each ENIs id and how many ip addresses are assigned on it
890
- func (ds * DataStore ) GetENIUtilization () {
891
- //eniUtilization.Reset()
892
- for _ , eni := range ds .eniPool {
893
- count := 0
894
- for _ , assignedAddr := range eni .AvailableIPv4Cidrs {
895
- for _ , addr := range assignedAddr .IPAddresses {
896
- if addr .Assigned () {
897
- count += 1
898
- }
899
- }
900
- }
901
- utilization := count
902
- eniID := eni .ID
903
- eniUtilization .WithLabelValues (eniID ).Set (float64 (utilization ))
904
- }
905
- }
906
-
907
894
// GetTrunkENI returns the trunk ENI ID or an empty string
908
895
func (ds * DataStore ) GetTrunkENI () string {
909
896
ds .lock .Lock ()
@@ -1110,7 +1097,8 @@ func (ds *DataStore) RemoveUnusedENIFromStore(warmIPTarget, minimumIPTarget, war
1110
1097
1111
1098
// Prometheus update
1112
1099
enis .Set (float64 (len (ds .eniPool )))
1113
- ds .GetENIUtilization ()
1100
+ // Delete ENI IPs In Use when ENI is removed
1101
+ eniIPsInUse .DeleteLabelValues (removableENI )
1114
1102
totalIPs .Set (float64 (ds .total ))
1115
1103
return removableENI
1116
1104
}
@@ -1165,7 +1153,8 @@ func (ds *DataStore) RemoveENIFromDataStore(eniID string, force bool) error {
1165
1153
1166
1154
// Prometheus gauge
1167
1155
enis .Set (float64 (len (ds .eniPool )))
1168
- ds .GetENIUtilization ()
1156
+ // Delete ENI IPs In Use when ENI is removed
1157
+ eniIPsInUse .DeleteLabelValues (eniID )
1169
1158
return nil
1170
1159
}
1171
1160
@@ -1206,6 +1195,8 @@ func (ds *DataStore) UnassignPodIPAddress(ipamKey IPAMKey) (e *ENI, ip string, d
1206
1195
ipsPerCidr .With (prometheus.Labels {"cidr" : availableCidr .Cidr .String ()}).Dec ()
1207
1196
ds .log .Infof ("UnassignPodIPAddress: sandbox %s's ipAddr %s, DeviceNumber %d" ,
1208
1197
ipamKey , addr .Address , eni .DeviceNumber )
1198
+ // Decrement ENI IP usage when a pod is deallocated
1199
+ eniIPsInUse .WithLabelValues (eni .ID ).Dec ()
1209
1200
return eni , addr .Address , eni .DeviceNumber , nil
1210
1201
}
1211
1202
0 commit comments