Skip to content

Commit

Permalink
filter requestcompression metrics if service has
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws committed Jun 17, 2024
1 parent 2d2e8d6 commit 080feaf
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -58,6 +65,10 @@ public List<RuntimeClientPlugin> 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)
Expand Down

0 comments on commit 080feaf

Please sign in to comment.