-
Notifications
You must be signed in to change notification settings - Fork 653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add SDK-specific feature tracking #2682
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"id": "a048e0bc-5088-4e76-a29c-9524e4ee34eb", | ||
"type": "feature", | ||
"collapse": true, | ||
"description": "Add framework for tracking specific features in user-agent string.", | ||
"modules": [ | ||
"." | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -231,6 +231,71 @@ func TestAddUserAgentKeyValue(t *testing.T) { | |
} | ||
} | ||
|
||
func TestAddUserAgentFeature(t *testing.T) { | ||
restoreEnv := clearEnv() | ||
defer restoreEnv() | ||
|
||
cases := map[string]struct { | ||
Features []UserAgentFeature | ||
Expect string | ||
}{ | ||
"none": { | ||
Features: []UserAgentFeature{}, | ||
Expect: expectedAgent, | ||
}, | ||
"one": { | ||
Features: []UserAgentFeature{ | ||
UserAgentFeatureWaiter, | ||
}, | ||
Expect: "m/B " + expectedAgent, | ||
}, | ||
"two": { | ||
Features: []UserAgentFeature{ | ||
UserAgentFeatureRetryModeAdaptive, // ensure stable order, and idempotent | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] not sure if I'd call it stable order since this maps to a set at the end, and we end up sorting the feature set |
||
UserAgentFeatureRetryModeAdaptive, | ||
UserAgentFeatureWaiter, | ||
}, | ||
Expect: "m/B,F " + expectedAgent, | ||
}, | ||
} | ||
|
||
for name, c := range cases { | ||
t.Run(name, func(t *testing.T) { | ||
b := NewRequestUserAgent() | ||
stack := middleware.NewStack("testStack", smithyhttp.NewStackRequest) | ||
err := stack.Build.Add(b, middleware.After) | ||
if err != nil { | ||
t.Fatalf("expect no error, got %v", err) | ||
} | ||
|
||
for _, f := range c.Features { | ||
b.AddUserAgentFeature(f) | ||
} | ||
|
||
in := middleware.BuildInput{ | ||
Request: &smithyhttp.Request{ | ||
Request: &http.Request{ | ||
Header: map[string][]string{}, | ||
}, | ||
}, | ||
} | ||
_, _, err = b.HandleBuild(context.Background(), in, middleware.BuildHandlerFunc(func(ctx context.Context, input middleware.BuildInput) (o middleware.BuildOutput, m middleware.Metadata, err error) { | ||
return o, m, err | ||
})) | ||
if err != nil { | ||
t.Fatalf("expect no error, got %v", err) | ||
} | ||
ua, ok := in.Request.(*smithyhttp.Request).Header["User-Agent"] | ||
if !ok { | ||
t.Fatalf("expect User-Agent to be present") | ||
} | ||
if ua[0] != c.Expect { | ||
t.Errorf("User-Agent did not match expected, %v != %v", c.Expect, ua[0]) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestAddSDKAgentKey(t *testing.T) { | ||
restoreEnv := clearEnv() | ||
defer restoreEnv() | ||
|
63 changes: 63 additions & 0 deletions
63
...egen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/AwsPaginators.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.smithy.aws.go.codegen.customization; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import software.amazon.smithy.aws.go.codegen.AwsGoDependency; | ||
import software.amazon.smithy.codegen.core.Symbol; | ||
import software.amazon.smithy.codegen.core.SymbolProvider; | ||
import software.amazon.smithy.go.codegen.GoDelegator; | ||
import software.amazon.smithy.go.codegen.GoSettings; | ||
import software.amazon.smithy.go.codegen.SmithyGoDependency; | ||
import software.amazon.smithy.go.codegen.integration.Paginators; | ||
import software.amazon.smithy.model.Model; | ||
|
||
import static software.amazon.smithy.go.codegen.GoWriter.goTemplate; | ||
import static software.amazon.smithy.go.codegen.SymbolUtils.buildPackageSymbol; | ||
|
||
/** | ||
* Extends the base smithy Paginators integration to track in the User-Agent string. | ||
*/ | ||
public class AwsPaginators extends Paginators { | ||
@Override | ||
public Set<Symbol> getAdditionalClientOptions() { | ||
return Set.of(buildPackageSymbol("addIsPaginatorUserAgent")); | ||
} | ||
|
||
@Override | ||
public void writeAdditionalFiles(GoSettings settings, Model model, SymbolProvider symbolProvider, GoDelegator goDelegator) { | ||
super.writeAdditionalFiles(settings, model, symbolProvider, goDelegator); | ||
|
||
goDelegator.useFileWriter("api_client.go", settings.getModuleName(), goTemplate(""" | ||
func addIsPaginatorUserAgent(o *Options) { | ||
o.APIOptions = append(o.APIOptions, func(stack $stack:P) error { | ||
ua, err := getOrAddRequestUserAgent(stack) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ua.AddUserAgentFeature($featurePaginator:T) | ||
return nil | ||
}) | ||
}""", | ||
Map.of( | ||
"stack", SmithyGoDependency.SMITHY_MIDDLEWARE.struct("Stack"), | ||
"featurePaginator", AwsGoDependency.AWS_MIDDLEWARE.valueSymbol("UserAgentFeaturePaginator") | ||
))); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/AwsWaiters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.smithy.aws.go.codegen.customization; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import software.amazon.smithy.aws.go.codegen.AwsGoDependency; | ||
import software.amazon.smithy.codegen.core.Symbol; | ||
import software.amazon.smithy.codegen.core.SymbolProvider; | ||
import software.amazon.smithy.go.codegen.GoDelegator; | ||
import software.amazon.smithy.go.codegen.GoSettings; | ||
import software.amazon.smithy.go.codegen.SmithyGoDependency; | ||
import software.amazon.smithy.go.codegen.integration.Waiters; | ||
import software.amazon.smithy.model.Model; | ||
|
||
import static software.amazon.smithy.go.codegen.GoWriter.goTemplate; | ||
import static software.amazon.smithy.go.codegen.SymbolUtils.buildPackageSymbol; | ||
|
||
/** | ||
* Extends the base smithy Waiters integration to track in the User-Agent string. | ||
*/ | ||
public class AwsWaiters extends Waiters { | ||
@Override | ||
public Set<Symbol> getAdditionalClientOptions() { | ||
return Set.of(buildPackageSymbol("addIsWaiterUserAgent")); | ||
} | ||
|
||
@Override | ||
public void writeAdditionalFiles(GoSettings settings, Model model, SymbolProvider symbolProvider, GoDelegator goDelegator) { | ||
super.writeAdditionalFiles(settings, model, symbolProvider, goDelegator); | ||
|
||
goDelegator.useFileWriter("api_client.go", settings.getModuleName(), goTemplate(""" | ||
func addIsWaiterUserAgent(o *Options) { | ||
o.APIOptions = append(o.APIOptions, func(stack $stack:P) error { | ||
ua, err := getOrAddRequestUserAgent(stack) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ua.AddUserAgentFeature($featureWaiter:T) | ||
return nil | ||
}) | ||
}""", | ||
Map.of( | ||
"stack", SmithyGoDependency.SMITHY_MIDDLEWARE.struct("Stack"), | ||
"featureWaiter", AwsGoDependency.AWS_MIDDLEWARE.valueSymbol("UserAgentFeatureWaiter") | ||
))); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I double checked that these are correct (hate when I push a PR and then whoops typo)