Skip to content

Commit 364264e

Browse files
author
Lindsay Hanks
committed
just metrics
1 parent 7da77c5 commit 364264e

15 files changed

+20
-3855
lines changed

config/grafana/grafana_dashboard.json

-2,404
This file was deleted.

pkg/ipamd/datastore/data_store.go

+20-31
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,18 @@ var (
122122
},
123123
[]string{"cidr"},
124124
)
125-
noAvailableAddrs = prometheus.NewCounter(
125+
noAvailableIPAddrs = prometheus.NewCounter(
126126
prometheus.CounterOpts{
127127
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",
129129
},
130130
)
131-
eniUtilization = prometheus.NewGaugeVec(
131+
eniIPsInUse = prometheus.NewGaugeVec(
132132
prometheus.GaugeOpts{
133133
Name: "awscni_eni_util",
134134
Help: "The number of allocated ips partitioned by eni",
135135
},
136-
[]string{"fn"},
136+
[]string{"eni"},
137137
)
138138
prometheusRegistered = false
139139
)
@@ -357,8 +357,8 @@ func prometheusRegister() {
357357
prometheus.MustRegister(forceRemovedIPs)
358358
prometheus.MustRegister(totalPrefixes)
359359
prometheus.MustRegister(ipsPerCidr)
360-
prometheus.MustRegister(noAvailableAddrs)
361-
prometheus.MustRegister(eniUtilization)
360+
prometheus.MustRegister(noAvailableIPAddrs)
361+
prometheus.MustRegister(eniIPsInUse)
362362
prometheusRegistered = true
363363
}
364364
}
@@ -536,8 +536,9 @@ func (ds *DataStore) AddENI(eniID string, deviceNumber int, isPrimary, isTrunk,
536536
DeviceNumber: deviceNumber,
537537
AvailableIPv4Cidrs: make(map[string]*CidrInfo)}
538538

539-
ds.GetENIUtilization()
540539
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)
541542
return nil
542543
}
543544

@@ -727,10 +728,12 @@ func (ds *DataStore) AssignPodIPv6Address(ipamKey IPAMKey, ipamMetadata IPAMMeta
727728
delete(V6Cidr.IPAddresses, addr.Address)
728729
return "", -1, err
729730
}
731+
// Increment ENI IP usage on pod IPv6 allocation
732+
eniIPsInUse.WithLabelValues(eni.ID).Inc()
730733
return addr.Address, eni.DeviceNumber, nil
731734
}
732735
}
733-
noAvailableAddrs.Inc()
736+
noAvailableIPAddrs.Inc()
734737
return "", -1, errors.New("assignPodIPv6AddressUnsafe: no available IP addresses")
735738
}
736739

@@ -793,12 +796,14 @@ func (ds *DataStore) AssignPodIPv4Address(ipamKey IPAMKey, ipamMetadata IPAMMeta
793796
ipsPerCidr.With(prometheus.Labels{"cidr": availableCidr.Cidr.String()}).Dec()
794797
return "", -1, err
795798
}
799+
// Increment ENI IP usage on pod IPv4 allocation
800+
eniIPsInUse.WithLabelValues(eni.ID).Inc()
796801
return addr.Address, eni.DeviceNumber, nil
797802
}
798803
ds.log.Debugf("AssignPodIPv4Address: ENI %s does not have available addresses", eni.ID)
799804
}
800805

801-
noAvailableAddrs.Inc()
806+
noAvailableIPAddrs.Inc()
802807
ds.log.Errorf("DataStore has no available IP/Prefix addresses")
803808
return "", -1, errors.New("assignPodIPv4AddressUnsafe: no available IP/Prefix addresses")
804809
}
@@ -815,7 +820,6 @@ func (ds *DataStore) assignPodIPAddressUnsafe(addr *AddressInfo, ipamKey IPAMKey
815820
addr.IPAMMetadata = ipamMetadata
816821
addr.AssignedTime = assignedTime
817822

818-
ds.log.Debugf("IP allocation request")
819823
ds.assigned++
820824
// Prometheus gauge
821825
assignedIPs.Set(float64(ds.assigned))
@@ -832,7 +836,6 @@ func (ds *DataStore) unassignPodIPAddressUnsafe(addr *AddressInfo) {
832836
addr.IPAMKey = IPAMKey{} // unassign the addr
833837
addr.IPAMMetadata = IPAMMetadata{}
834838
ds.assigned--
835-
ds.log.Debugf("IP deallocation request")
836839
// Prometheus gauge
837840
assignedIPs.Set(float64(ds.assigned))
838841
}
@@ -886,24 +889,6 @@ func (ds *DataStore) GetIPStats(addressFamily string) *DataStoreStats {
886889
return stats
887890
}
888891

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-
907892
// GetTrunkENI returns the trunk ENI ID or an empty string
908893
func (ds *DataStore) GetTrunkENI() string {
909894
ds.lock.Lock()
@@ -1110,7 +1095,8 @@ func (ds *DataStore) RemoveUnusedENIFromStore(warmIPTarget, minimumIPTarget, war
11101095

11111096
// Prometheus update
11121097
enis.Set(float64(len(ds.eniPool)))
1113-
ds.GetENIUtilization()
1098+
// Delete ENI IPs In Use when ENI is removed
1099+
eniIPsInUse.DeleteLabelValues(removableENI)
11141100
totalIPs.Set(float64(ds.total))
11151101
return removableENI
11161102
}
@@ -1165,7 +1151,8 @@ func (ds *DataStore) RemoveENIFromDataStore(eniID string, force bool) error {
11651151

11661152
// Prometheus gauge
11671153
enis.Set(float64(len(ds.eniPool)))
1168-
ds.GetENIUtilization()
1154+
// Delete ENI IPs In Use when ENI is removed
1155+
eniIPsInUse.DeleteLabelValues(eniID)
11691156
return nil
11701157
}
11711158

@@ -1206,6 +1193,8 @@ func (ds *DataStore) UnassignPodIPAddress(ipamKey IPAMKey) (e *ENI, ip string, d
12061193
ipsPerCidr.With(prometheus.Labels{"cidr": availableCidr.Cidr.String()}).Dec()
12071194
ds.log.Infof("UnassignPodIPAddress: sandbox %s's ipAddr %s, DeviceNumber %d",
12081195
ipamKey, addr.Address, eni.DeviceNumber)
1196+
// Decrement ENI IP usage when a pod is deallocated
1197+
eniIPsInUse.WithLabelValues(eni.ID).Dec()
12091198
return eni, addr.Address, eni.DeviceNumber, nil
12101199
}
12111200

pkg/ipamd/ipamd.go

-2
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,6 @@ func (c *IPAMContext) updateIPPoolIfRequired(ctx context.Context) {
679679
if c.shouldRemoveExtraENIs() {
680680
c.tryFreeENI()
681681
}
682-
// Prometheus Metric
683-
c.dataStore.GetENIUtilization()
684682
}
685683

686684
// decreaseDatastorePool runs every `interval` and attempts to return unused ENIs and IPs

test/integration/warm-pool/clear_warm_env.go

-26
This file was deleted.

test/integration/warm-pool/set_warm_env.go

-26
This file was deleted.

test/integration/warm-pool/use_case_1_test.go

-98
This file was deleted.

0 commit comments

Comments
 (0)