Skip to content

Commit c1db805

Browse files
Lindsay Hanksjdn5126
authored andcommitted
just metrics
1 parent 981cfa8 commit c1db805

15 files changed

+22
-3855
lines changed

config/grafana/grafana_dashboard.json

Lines changed: 0 additions & 2404 deletions
This file was deleted.

pkg/ipamd/datastore/data_store.go

Lines changed: 22 additions & 31 deletions
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
}
@@ -452,6 +452,8 @@ func (ds *DataStore) ReadBackingStore(isv6Enabled bool) error {
452452
cidr.IPAddresses[ipAddr.String()] = addr
453453
ds.assignPodIPAddressUnsafe(addr, allocation.IPAMKey, allocation.Metadata, time.Unix(0, allocation.AllocationTimestamp))
454454
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()
455457
// Update prometheus for ips per cidr
456458
// Secondary IP mode will have /32:1 and Prefix mode will have /28:<number of /32s>
457459
ipsPerCidr.With(prometheus.Labels{"cidr": cidr.Cidr.String()}).Inc()
@@ -536,8 +538,9 @@ func (ds *DataStore) AddENI(eniID string, deviceNumber int, isPrimary, isTrunk,
536538
DeviceNumber: deviceNumber,
537539
AvailableIPv4Cidrs: make(map[string]*CidrInfo)}
538540

539-
ds.GetENIUtilization()
540541
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)
541544
return nil
542545
}
543546

@@ -727,10 +730,12 @@ func (ds *DataStore) AssignPodIPv6Address(ipamKey IPAMKey, ipamMetadata IPAMMeta
727730
delete(V6Cidr.IPAddresses, addr.Address)
728731
return "", -1, err
729732
}
733+
// Increment ENI IP usage on pod IPv6 allocation
734+
eniIPsInUse.WithLabelValues(eni.ID).Inc()
730735
return addr.Address, eni.DeviceNumber, nil
731736
}
732737
}
733-
noAvailableAddrs.Inc()
738+
noAvailableIPAddrs.Inc()
734739
return "", -1, errors.New("assignPodIPv6AddressUnsafe: no available IP addresses")
735740
}
736741

@@ -793,12 +798,14 @@ func (ds *DataStore) AssignPodIPv4Address(ipamKey IPAMKey, ipamMetadata IPAMMeta
793798
ipsPerCidr.With(prometheus.Labels{"cidr": availableCidr.Cidr.String()}).Dec()
794799
return "", -1, err
795800
}
801+
// Increment ENI IP usage on pod IPv4 allocation
802+
eniIPsInUse.WithLabelValues(eni.ID).Inc()
796803
return addr.Address, eni.DeviceNumber, nil
797804
}
798805
ds.log.Debugf("AssignPodIPv4Address: ENI %s does not have available addresses", eni.ID)
799806
}
800807

801-
noAvailableAddrs.Inc()
808+
noAvailableIPAddrs.Inc()
802809
ds.log.Errorf("DataStore has no available IP/Prefix addresses")
803810
return "", -1, errors.New("assignPodIPv4AddressUnsafe: no available IP/Prefix addresses")
804811
}
@@ -815,7 +822,6 @@ func (ds *DataStore) assignPodIPAddressUnsafe(addr *AddressInfo, ipamKey IPAMKey
815822
addr.IPAMMetadata = ipamMetadata
816823
addr.AssignedTime = assignedTime
817824

818-
ds.log.Debugf("IP allocation request")
819825
ds.assigned++
820826
// Prometheus gauge
821827
assignedIPs.Set(float64(ds.assigned))
@@ -832,7 +838,6 @@ func (ds *DataStore) unassignPodIPAddressUnsafe(addr *AddressInfo) {
832838
addr.IPAMKey = IPAMKey{} // unassign the addr
833839
addr.IPAMMetadata = IPAMMetadata{}
834840
ds.assigned--
835-
ds.log.Debugf("IP deallocation request")
836841
// Prometheus gauge
837842
assignedIPs.Set(float64(ds.assigned))
838843
}
@@ -886,24 +891,6 @@ func (ds *DataStore) GetIPStats(addressFamily string) *DataStoreStats {
886891
return stats
887892
}
888893

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-
907894
// GetTrunkENI returns the trunk ENI ID or an empty string
908895
func (ds *DataStore) GetTrunkENI() string {
909896
ds.lock.Lock()
@@ -1110,7 +1097,8 @@ func (ds *DataStore) RemoveUnusedENIFromStore(warmIPTarget, minimumIPTarget, war
11101097

11111098
// Prometheus update
11121099
enis.Set(float64(len(ds.eniPool)))
1113-
ds.GetENIUtilization()
1100+
// Delete ENI IPs In Use when ENI is removed
1101+
eniIPsInUse.DeleteLabelValues(removableENI)
11141102
totalIPs.Set(float64(ds.total))
11151103
return removableENI
11161104
}
@@ -1165,7 +1153,8 @@ func (ds *DataStore) RemoveENIFromDataStore(eniID string, force bool) error {
11651153

11661154
// Prometheus gauge
11671155
enis.Set(float64(len(ds.eniPool)))
1168-
ds.GetENIUtilization()
1156+
// Delete ENI IPs In Use when ENI is removed
1157+
eniIPsInUse.DeleteLabelValues(eniID)
11691158
return nil
11701159
}
11711160

@@ -1206,6 +1195,8 @@ func (ds *DataStore) UnassignPodIPAddress(ipamKey IPAMKey) (e *ENI, ip string, d
12061195
ipsPerCidr.With(prometheus.Labels{"cidr": availableCidr.Cidr.String()}).Dec()
12071196
ds.log.Infof("UnassignPodIPAddress: sandbox %s's ipAddr %s, DeviceNumber %d",
12081197
ipamKey, addr.Address, eni.DeviceNumber)
1198+
// Decrement ENI IP usage when a pod is deallocated
1199+
eniIPsInUse.WithLabelValues(eni.ID).Dec()
12091200
return eni, addr.Address, eni.DeviceNumber, nil
12101201
}
12111202

pkg/ipamd/ipamd.go

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 26 deletions
This file was deleted.

test/integration/warm-pool/set_warm_env.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

test/integration/warm-pool/use_case_1_test.go

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)