@@ -20,6 +20,8 @@ import (
20
20
21
21
"github.com/aws/amazon-vpc-resource-controller-k8s/pkg/config"
22
22
rcHealthz "github.com/aws/amazon-vpc-resource-controller-k8s/pkg/healthz"
23
+ "github.com/prometheus/client_golang/prometheus"
24
+ "golang.org/x/exp/slices"
23
25
24
26
"github.com/aws/aws-sdk-go/aws"
25
27
"github.com/aws/aws-sdk-go/service/ec2"
@@ -39,6 +41,21 @@ type ENICleaner struct {
39
41
ctx context.Context
40
42
}
41
43
44
+ var (
45
+ vpcCniLeakedENICleanupCnt = prometheus .NewCounter (
46
+ prometheus.CounterOpts {
47
+ Name : "vpc_cni_created_leaked_eni_cleanup_count" ,
48
+ Help : "The number of leaked ENIs created by VPC-CNI that is cleaned up by the controller" ,
49
+ },
50
+ )
51
+ vpcrcLeakedENICleanupCnt = prometheus .NewCounter (
52
+ prometheus.CounterOpts {
53
+ Name : "vpc_rc_created_leaked_eni_cleanup_count" ,
54
+ Help : "The number of leaked ENIs created by VPC-RC that is cleaned up by the controller" ,
55
+ },
56
+ )
57
+ )
58
+
42
59
func (e * ENICleaner ) SetupWithManager (ctx context.Context , mgr ctrl.Manager , healthzHandler * rcHealthz.HealthzHandler ) error {
43
60
e .clusterNameTagKey = fmt .Sprintf (config .ClusterNameTagKeyFormat , e .ClusterName )
44
61
e .availableENIs = make (map [string ]struct {})
@@ -113,6 +130,21 @@ func (e *ENICleaner) cleanUpAvailableENIs() {
113
130
114
131
for _ , networkInterface := range describeNetworkInterfaceOp .NetworkInterfaces {
115
132
if _ , exists := e .availableENIs [* networkInterface .NetworkInterfaceId ]; exists {
133
+ // Increment promethues metrics for number of leaked ENIs cleaned up
134
+ if tagIdx := slices .IndexFunc (networkInterface .TagSet , func (tag * ec2.Tag ) bool {
135
+ return * tag .Key == config .NetworkInterfaceOwnerTagKey
136
+ }); tagIdx != - 1 {
137
+ switch * networkInterface .TagSet [tagIdx ].Value {
138
+ case config .NetworkInterfaceOwnerTagValue :
139
+ vpcrcLeakedENICleanupCnt .Inc ()
140
+ case config .NetworkInterfaceOwnerVPCCNITagValue :
141
+ vpcCniLeakedENICleanupCnt .Inc ()
142
+ default :
143
+ // We will not hit this case as we only filter for above two tag values, adding it for any future use cases
144
+ e .Log .Info ("found available ENI not created by VPC-CNI/VPC-RC" )
145
+ }
146
+ }
147
+
116
148
// The ENI in available state has been sitting for at least the eni clean up interval and it should
117
149
// be removed
118
150
_ , err := e .EC2Wrapper .DeleteNetworkInterface (& ec2.DeleteNetworkInterfaceInput {
0 commit comments