From 080feaf54894627da7bb744e462b1882d93e5c47 Mon Sep 17 00:00:00 2001 From: Luc Talatinian Date: Mon, 17 Jun 2024 10:13:07 -0400 Subject: [PATCH] filter requestcompression metrics if service has --- .../customization/RequestCompressionUserAgent.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/RequestCompressionUserAgent.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/RequestCompressionUserAgent.java index 30cc3b457b0..d01759f76cf 100644 --- a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/RequestCompressionUserAgent.java +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/RequestCompressionUserAgent.java @@ -26,6 +26,7 @@ import software.amazon.smithy.go.codegen.integration.MiddlewareRegistrar; import software.amazon.smithy.go.codegen.integration.RuntimeClientPlugin; import software.amazon.smithy.model.Model; +import software.amazon.smithy.model.knowledge.TopDownIndex; import software.amazon.smithy.model.shapes.OperationShape; import software.amazon.smithy.model.shapes.ServiceShape; import software.amazon.smithy.model.traits.RequestCompressionTrait; @@ -42,6 +43,12 @@ public class RequestCompressionUserAgent implements GoIntegration { .useClientOptions() .build(); + private static boolean hasRequestCompression(Model model, ServiceShape service) { + return TopDownIndex.of(model) + .getContainedOperations(service).stream() + .anyMatch(it -> it.hasTrait(RequestCompressionTrait.class)); + } + private static boolean isRequestCompression(Model model, ServiceShape service, OperationShape operation) { return operation.hasTrait(RequestCompressionTrait.class); } @@ -58,6 +65,10 @@ public List getClientPlugins() { @Override public void writeAdditionalFiles(GoSettings settings, Model model, SymbolProvider symbolProvider, GoDelegator goDelegator) { + if (!hasRequestCompression(model, settings.getService(model))) { + return; + } + goDelegator.useFileWriter("api_client.go", settings.getModuleName(), goTemplate(""" func addIsRequestCompressionUserAgent(stack $stack:P, options Options) error { ua, err := getOrAddRequestUserAgent(stack)