@@ -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
}
@@ -536,8 +536,9 @@ func (ds *DataStore) AddENI(eniID string, deviceNumber int, isPrimary, isTrunk,
536
536
DeviceNumber : deviceNumber ,
537
537
AvailableIPv4Cidrs : make (map [string ]* CidrInfo )}
538
538
539
- ds .GetENIUtilization ()
540
539
enis .Set (float64 (len (ds .eniPool )))
540
+ // Initialize ENI IPs In Use to 0 when an ENI is created
541
+ eniIPsInUse .WithLabelValues (eniID ).Set (0 )
541
542
return nil
542
543
}
543
544
@@ -727,10 +728,12 @@ func (ds *DataStore) AssignPodIPv6Address(ipamKey IPAMKey, ipamMetadata IPAMMeta
727
728
delete (V6Cidr .IPAddresses , addr .Address )
728
729
return "" , - 1 , err
729
730
}
731
+ // Increment ENI IP usage on pod IPv6 allocation
732
+ eniIPsInUse .WithLabelValues (eni .ID ).Inc ()
730
733
return addr .Address , eni .DeviceNumber , nil
731
734
}
732
735
}
733
- noAvailableAddrs .Inc ()
736
+ noAvailableIPAddrs .Inc ()
734
737
return "" , - 1 , errors .New ("assignPodIPv6AddressUnsafe: no available IP addresses" )
735
738
}
736
739
@@ -793,12 +796,14 @@ func (ds *DataStore) AssignPodIPv4Address(ipamKey IPAMKey, ipamMetadata IPAMMeta
793
796
ipsPerCidr .With (prometheus.Labels {"cidr" : availableCidr .Cidr .String ()}).Dec ()
794
797
return "" , - 1 , err
795
798
}
799
+ // Increment ENI IP usage on pod IPv4 allocation
800
+ eniIPsInUse .WithLabelValues (eni .ID ).Inc ()
796
801
return addr .Address , eni .DeviceNumber , nil
797
802
}
798
803
ds .log .Debugf ("AssignPodIPv4Address: ENI %s does not have available addresses" , eni .ID )
799
804
}
800
805
801
- noAvailableAddrs .Inc ()
806
+ noAvailableIPAddrs .Inc ()
802
807
ds .log .Errorf ("DataStore has no available IP/Prefix addresses" )
803
808
return "" , - 1 , errors .New ("assignPodIPv4AddressUnsafe: no available IP/Prefix addresses" )
804
809
}
@@ -815,7 +820,6 @@ func (ds *DataStore) assignPodIPAddressUnsafe(addr *AddressInfo, ipamKey IPAMKey
815
820
addr .IPAMMetadata = ipamMetadata
816
821
addr .AssignedTime = assignedTime
817
822
818
- ds .log .Debugf ("IP allocation request" )
819
823
ds .assigned ++
820
824
// Prometheus gauge
821
825
assignedIPs .Set (float64 (ds .assigned ))
@@ -832,7 +836,6 @@ func (ds *DataStore) unassignPodIPAddressUnsafe(addr *AddressInfo) {
832
836
addr .IPAMKey = IPAMKey {} // unassign the addr
833
837
addr .IPAMMetadata = IPAMMetadata {}
834
838
ds .assigned --
835
- ds .log .Debugf ("IP deallocation request" )
836
839
// Prometheus gauge
837
840
assignedIPs .Set (float64 (ds .assigned ))
838
841
}
@@ -886,24 +889,6 @@ func (ds *DataStore) GetIPStats(addressFamily string) *DataStoreStats {
886
889
return stats
887
890
}
888
891
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
892
// GetTrunkENI returns the trunk ENI ID or an empty string
908
893
func (ds * DataStore ) GetTrunkENI () string {
909
894
ds .lock .Lock ()
@@ -1110,7 +1095,8 @@ func (ds *DataStore) RemoveUnusedENIFromStore(warmIPTarget, minimumIPTarget, war
1110
1095
1111
1096
// Prometheus update
1112
1097
enis .Set (float64 (len (ds .eniPool )))
1113
- ds .GetENIUtilization ()
1098
+ // Delete ENI IPs In Use when ENI is removed
1099
+ eniIPsInUse .DeleteLabelValues (removableENI )
1114
1100
totalIPs .Set (float64 (ds .total ))
1115
1101
return removableENI
1116
1102
}
@@ -1165,7 +1151,8 @@ func (ds *DataStore) RemoveENIFromDataStore(eniID string, force bool) error {
1165
1151
1166
1152
// Prometheus gauge
1167
1153
enis .Set (float64 (len (ds .eniPool )))
1168
- ds .GetENIUtilization ()
1154
+ // Delete ENI IPs In Use when ENI is removed
1155
+ eniIPsInUse .DeleteLabelValues (eniID )
1169
1156
return nil
1170
1157
}
1171
1158
@@ -1206,6 +1193,8 @@ func (ds *DataStore) UnassignPodIPAddress(ipamKey IPAMKey) (e *ENI, ip string, d
1206
1193
ipsPerCidr .With (prometheus.Labels {"cidr" : availableCidr .Cidr .String ()}).Dec ()
1207
1194
ds .log .Infof ("UnassignPodIPAddress: sandbox %s's ipAddr %s, DeviceNumber %d" ,
1208
1195
ipamKey , addr .Address , eni .DeviceNumber )
1196
+ // Decrement ENI IP usage when a pod is deallocated
1197
+ eniIPsInUse .WithLabelValues (eni .ID ).Dec ()
1209
1198
return eni , addr .Address , eni .DeviceNumber , nil
1210
1199
}
1211
1200
0 commit comments