From 786e0494bc5360d8f3c12e96682a29aaf1d39109 Mon Sep 17 00:00:00 2001 From: Amanuel Engeda Date: Fri, 1 Dec 2023 01:58:34 -0800 Subject: [PATCH] Adjust region for metrics of resource counter --- test/hack/resource/clean/main.go | 7 +++++-- test/hack/resource/count/main.go | 2 +- test/hack/resource/pkg/resourcetypes/eni.go | 4 ++++ test/hack/resource/pkg/resourcetypes/instance.go | 4 ++++ test/hack/resource/pkg/resourcetypes/instanceprofile.go | 4 ++++ test/hack/resource/pkg/resourcetypes/launchtemplate.go | 4 ++++ test/hack/resource/pkg/resourcetypes/oidc.go | 4 ++++ test/hack/resource/pkg/resourcetypes/resourcetypes.go | 2 ++ test/hack/resource/pkg/resourcetypes/securitygroup.go | 4 ++++ test/hack/resource/pkg/resourcetypes/stack.go | 4 ++++ test/hack/resource/pkg/resourcetypes/vpc_endpoint.go | 4 ++++ 11 files changed, 40 insertions(+), 3 deletions(-) diff --git a/test/hack/resource/clean/main.go b/test/hack/resource/clean/main.go index c5c6b32854c0..ba839f739489 100644 --- a/test/hack/resource/clean/main.go +++ b/test/hack/resource/clean/main.go @@ -87,8 +87,11 @@ func main() { if err != nil { resourceLogger.Errorf("%v", err) } - if err = metricsClient.FireMetric(ctx, sweeperCleanedResourcesTableName, fmt.Sprintf("%sDeleted", resourceTypes[i].String()), float64(len(cleaned)), cfg.Region); err != nil { - resourceLogger.Errorf("%v", err) + // Should only fire metrics if the resource have expired + if clusterName == "" { + if err = metricsClient.FireMetric(ctx, sweeperCleanedResourcesTableName, fmt.Sprintf("%sDeleted", resourceTypes[i].String()), float64(len(cleaned)), lo.Ternary(resourceTypes[i].Global(), "global", cfg.Region)); err != nil { + resourceLogger.Errorf("%v", err) + } } resourceLogger.With("ids", cleaned, "count", len(cleaned)).Infof("deleted resourceTypes") } diff --git a/test/hack/resource/count/main.go b/test/hack/resource/count/main.go index 1213a81c8b64..e048e3680733 100644 --- a/test/hack/resource/count/main.go +++ b/test/hack/resource/count/main.go @@ -59,7 +59,7 @@ func main() { resourceLogger.Errorf("%v", err) } - if err = metricsClient.FireMetric(ctx, resourceCountTableName, resourceTypes[i].String(), float64(resourceCount), cfg.Region); err != nil { + if err = metricsClient.FireMetric(ctx, resourceCountTableName, resourceTypes[i].String(), float64(resourceCount), lo.Ternary(resourceTypes[i].Global(), "global", cfg.Region)); err != nil { resourceLogger.Errorf("%v", err) } resourceLogger.With("count", resourceCount).Infof("counted resourceTypes") diff --git a/test/hack/resource/pkg/resourcetypes/eni.go b/test/hack/resource/pkg/resourcetypes/eni.go index a81450b0facf..52201a213768 100644 --- a/test/hack/resource/pkg/resourcetypes/eni.go +++ b/test/hack/resource/pkg/resourcetypes/eni.go @@ -37,6 +37,10 @@ func (e *ENI) String() string { return "ElasticNetworkInterface" } +func (e *ENI) Global() bool { + return false +} + func (e *ENI) GetExpired(ctx context.Context, expirationTime time.Time) (ids []string, err error) { var nextToken *string for { diff --git a/test/hack/resource/pkg/resourcetypes/instance.go b/test/hack/resource/pkg/resourcetypes/instance.go index d869d71c3dd6..2e8c557014fe 100644 --- a/test/hack/resource/pkg/resourcetypes/instance.go +++ b/test/hack/resource/pkg/resourcetypes/instance.go @@ -35,6 +35,10 @@ func (i *Instance) String() string { return "Instances" } +func (i *Instance) Global() bool { + return false +} + func (i *Instance) GetExpired(ctx context.Context, expirationTime time.Time) (ids []string, err error) { var nextToken *string for { diff --git a/test/hack/resource/pkg/resourcetypes/instanceprofile.go b/test/hack/resource/pkg/resourcetypes/instanceprofile.go index 23fff1a5a4f3..5bb6fa04b018 100644 --- a/test/hack/resource/pkg/resourcetypes/instanceprofile.go +++ b/test/hack/resource/pkg/resourcetypes/instanceprofile.go @@ -35,6 +35,10 @@ func (ip *InstanceProfile) String() string { return "InstanceProfile" } +func (ip *InstanceProfile) Global() bool { + return true +} + func (ip *InstanceProfile) GetExpired(ctx context.Context, expirationTime time.Time) (names []string, err error) { out, err := ip.iamClient.ListInstanceProfiles(ctx, &iam.ListInstanceProfilesInput{}) if err != nil { diff --git a/test/hack/resource/pkg/resourcetypes/launchtemplate.go b/test/hack/resource/pkg/resourcetypes/launchtemplate.go index 38dc681eef4f..d4b6b964f12b 100644 --- a/test/hack/resource/pkg/resourcetypes/launchtemplate.go +++ b/test/hack/resource/pkg/resourcetypes/launchtemplate.go @@ -36,6 +36,10 @@ func (lt *LaunchTemplate) String() string { return "LaunchTemplates" } +func (lt *LaunchTemplate) Global() bool { + return false +} + func (lt *LaunchTemplate) GetExpired(ctx context.Context, expirationTime time.Time) (names []string, err error) { var nextToken *string for { diff --git a/test/hack/resource/pkg/resourcetypes/oidc.go b/test/hack/resource/pkg/resourcetypes/oidc.go index def8e163db84..b70676726f52 100644 --- a/test/hack/resource/pkg/resourcetypes/oidc.go +++ b/test/hack/resource/pkg/resourcetypes/oidc.go @@ -35,6 +35,10 @@ func (o *OIDC) String() string { return "OpenIDConnectProvider" } +func (o *OIDC) Global() bool { + return true +} + func (o *OIDC) GetExpired(ctx context.Context, expirationTime time.Time) (names []string, err error) { out, err := o.iamClient.ListOpenIDConnectProviders(ctx, &iam.ListOpenIDConnectProvidersInput{}) if err != nil { diff --git a/test/hack/resource/pkg/resourcetypes/resourcetypes.go b/test/hack/resource/pkg/resourcetypes/resourcetypes.go index 58b47e3c61dc..bf4f84bc94b1 100644 --- a/test/hack/resource/pkg/resourcetypes/resourcetypes.go +++ b/test/hack/resource/pkg/resourcetypes/resourcetypes.go @@ -34,6 +34,8 @@ const ( type Type interface { // String is the string representation of the type String() string + // Global determines if a resource is globally located in an account + Global() bool // Get returns all resources of the type associated with the clusterName Get(ctx context.Context, clusterName string) (ids []string, err error) // GetExpired returns all resources of the type that were provisioned before the expirationTime diff --git a/test/hack/resource/pkg/resourcetypes/securitygroup.go b/test/hack/resource/pkg/resourcetypes/securitygroup.go index eac9c902b88a..e9b57096f26d 100644 --- a/test/hack/resource/pkg/resourcetypes/securitygroup.go +++ b/test/hack/resource/pkg/resourcetypes/securitygroup.go @@ -37,6 +37,10 @@ func (sg *SecurityGroup) String() string { return "SecurityGroup" } +func (sg *SecurityGroup) Global() bool { + return false +} + func (sg *SecurityGroup) GetExpired(ctx context.Context, expirationTime time.Time) (ids []string, err error) { var nextToken *string for { diff --git a/test/hack/resource/pkg/resourcetypes/stack.go b/test/hack/resource/pkg/resourcetypes/stack.go index 2aad555913a4..7d42ec1225c1 100644 --- a/test/hack/resource/pkg/resourcetypes/stack.go +++ b/test/hack/resource/pkg/resourcetypes/stack.go @@ -36,6 +36,10 @@ func (s *Stack) String() string { return "CloudformationStacks" } +func (s *Stack) Global() bool { + return false +} + func (s *Stack) GetExpired(ctx context.Context, expirationTime time.Time) (names []string, err error) { var nextToken *string for { diff --git a/test/hack/resource/pkg/resourcetypes/vpc_endpoint.go b/test/hack/resource/pkg/resourcetypes/vpc_endpoint.go index 380eba791996..a3f734781485 100644 --- a/test/hack/resource/pkg/resourcetypes/vpc_endpoint.go +++ b/test/hack/resource/pkg/resourcetypes/vpc_endpoint.go @@ -35,6 +35,10 @@ func (v *VPCEndpoint) String() string { return "VPCEndpoints" } +func (v *VPCEndpoint) Global() bool { + return true +} + func (v *VPCEndpoint) Get(ctx context.Context, clusterName string) (ids []string, err error) { var nextToken *string for {