-
Notifications
You must be signed in to change notification settings - Fork 172
Add a basic benchmark #593
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
Open
simonmarty
wants to merge
17
commits into
aws:main
Choose a base branch
from
simonmarty:benchmark
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+222
−1
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ea63f7e
Add a basic benchmark
simonmarty 5faa261
Use github-action-benchmark
simonmarty d2a507d
Error on mount failures
simonmarty d74bb93
Remove ./provider and ./utils since they do not have benchmarks at th…
simonmarty 3d0669d
Add doc comment
simonmarty 974834a
Fix typos
simonmarty 769027f
Fix attributes now that token requests are merged
simonmarty bc9b52e
Cache entries are immutable, use commit hashes
simonmarty 32f8999
Update benchmark_test.go
simonmarty 3c9a273
Merge branch 'main' into benchmark
reyhankoyun 9e98384
Merge branch 'main' into benchmark
simonmarty 7786b7e
Merge branch 'main' into benchmark
simonmarty 2fcf223
Merge branch 'main' into benchmark
simonmarty de7deda
Merge branch 'main' into benchmark
simonmarty 922b7ee
Merge branch 'main' into benchmark
simonmarty ce978dc
Update bench.yml
simonmarty 55214f1
Merge branch 'main' into benchmark
simonmarty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,51 @@ | ||
| name: Benchmark | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| types: [opened, synchronize, ready_for_review] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| benchmark: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v6 | ||
| with: | ||
| go-version-file: 'go.mod' | ||
|
|
||
| - name: Run benchmarks | ||
| run: go test -bench=. -benchmem -count=5 -timeout=30m ./server/ | tee bench-result.txt | ||
|
|
||
| - name: Download previous benchmark result | ||
| if: github.event_name == 'pull_request' | ||
| uses: actions/cache/restore@v5 | ||
| with: | ||
| path: bench-baseline.json | ||
| key: benchmark-baseline-${{ runner.os }}-${{ github.event.pull_request.base.sha }} | ||
|
|
||
| - name: Compare benchmarks | ||
| uses: benchmark-action/github-action-benchmark@v1 | ||
| with: | ||
| tool: 'go' | ||
| output-file-path: bench-result.txt | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| external-data-json-path: bench-baseline.json | ||
| comment-on-alert: true | ||
| summary-always: true | ||
|
reyhankoyun marked this conversation as resolved.
|
||
|
|
||
| - name: Cache baseline | ||
| if: github.ref == 'refs/heads/main' | ||
| uses: actions/cache/save@v5 | ||
| with: | ||
| path: bench-baseline.json | ||
| key: benchmark-baseline-${{ runner.os }}-${{ github.sha }} | ||
This file contains hidden or 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,170 @@ | ||
| // Benchmarks for the server package covering end-to-end mount request | ||
| // handling with mocked AWS clients (single secret, mixed types, JMES path | ||
| // extraction, and large batches). | ||
| // All benchmark tests benchmark both server initialization and mount requests. | ||
| // Run with: go test -bench=. -benchmem ./server/ | ||
| package server | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "testing" | ||
|
|
||
| "github.com/aws/aws-sdk-go-v2/aws" | ||
| "github.com/aws/aws-sdk-go-v2/service/secretsmanager" | ||
| "github.com/aws/aws-sdk-go-v2/service/ssm" | ||
| ssmtypes "github.com/aws/aws-sdk-go-v2/service/ssm/types" | ||
| "sigs.k8s.io/secrets-store-csi-driver/provider/v1alpha1" | ||
| "sigs.k8s.io/yaml" | ||
| ) | ||
|
|
||
| func buildBenchMountReq(dir string, tst testCase) *v1alpha1.MountRequest { | ||
| attrMap := map[string]string{ | ||
| "csi.storage.k8s.io/pod.name": tst.attributes["podName"], | ||
| "csi.storage.k8s.io/pod.namespace": tst.attributes["namespace"], | ||
| "csi.storage.k8s.io/serviceAccount.name": tst.attributes["accName"], | ||
| "csi.storage.k8s.io/serviceAccount.tokens": `{"sts.amazonaws.com":{"token":"fake-irsa-token","expirationTimestamp":"2099-01-15T10:30:00Z"},"pods.eks.amazonaws.com":{"token":"fake-pod-identity-token","expirationTimestamp":"2099-01-15T10:30:00Z"}}`, | ||
| } | ||
| if r := tst.attributes["region"]; len(r) > 0 { | ||
| attrMap["region"] = r | ||
| } | ||
| if fr := tst.attributes["failoverRegion"]; len(fr) > 0 { | ||
| attrMap["failoverRegion"] = fr | ||
| } | ||
| if pt := tst.attributes["pathTranslation"]; len(pt) > 0 { | ||
| attrMap["pathTranslation"] = pt | ||
| } | ||
|
|
||
| objs, _ := yaml.Marshal(tst.mountObjs) | ||
| attrMap["objects"] = string(objs) | ||
| attr, _ := json.Marshal(attrMap) | ||
|
|
||
| return &v1alpha1.MountRequest{ | ||
| Attributes: string(attr), | ||
| TargetPath: dir, | ||
| Permission: tst.perms, | ||
| CurrentObjectVersion: []*v1alpha1.ObjectVersion{}, | ||
| } | ||
| } | ||
|
|
||
| func BenchmarkMount_SingleSecret(b *testing.B) { | ||
| tst := testCase{ | ||
| testName: "Bench Single Secret", | ||
| attributes: stdAttributes, | ||
| mountObjs: []map[string]interface{}{ | ||
| {"objectName": "TestSecret1", "objectType": "secretsmanager"}, | ||
| }, | ||
| ssmRsp: []*ssm.GetParametersOutput{}, | ||
| gsvRsp: []*secretsmanager.GetSecretValueOutput{ | ||
| {SecretString: aws.String("secret1"), VersionId: aws.String("1")}, | ||
| }, | ||
| descRsp: []*secretsmanager.DescribeSecretOutput{}, | ||
| perms: "420", | ||
| } | ||
|
|
||
| for b.Loop() { | ||
|
simonmarty marked this conversation as resolved.
|
||
| dir := b.TempDir() | ||
| svr := newServerWithMocks(&tst, true, nil) | ||
| req := buildBenchMountReq(dir, tst) | ||
|
|
||
| if _, err := svr.Mount(context.Background(), req); err != nil { | ||
| b.Fatal(err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func BenchmarkMount_MixedSecrets(b *testing.B) { | ||
| tst := testCase{ | ||
| testName: "Bench Mixed", | ||
| attributes: stdAttributes, | ||
| mountObjs: []map[string]interface{}{ | ||
| {"objectName": "TestSecret1", "objectType": "secretsmanager"}, | ||
| {"objectName": "TestParm1", "objectType": "ssmparameter"}, | ||
| }, | ||
| ssmRsp: []*ssm.GetParametersOutput{ | ||
| { | ||
| Parameters: []ssmtypes.Parameter{ | ||
| {Name: aws.String("TestParm1"), Value: aws.String("parm1"), Version: 1}, | ||
| }, | ||
| }, | ||
| }, | ||
| gsvRsp: []*secretsmanager.GetSecretValueOutput{ | ||
| {SecretString: aws.String("secret1"), VersionId: aws.String("1")}, | ||
| }, | ||
| descRsp: []*secretsmanager.DescribeSecretOutput{}, | ||
| perms: "420", | ||
| } | ||
|
|
||
| for b.Loop() { | ||
| dir := b.TempDir() | ||
| svr := newServerWithMocks(&tst, true, nil) | ||
| req := buildBenchMountReq(dir, tst) | ||
| if _, err := svr.Mount(context.Background(), req); err != nil { | ||
| b.Fatal(err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func BenchmarkMount_WithJMESPath(b *testing.B) { | ||
| tst := testCase{ | ||
| testName: "Bench JMES", | ||
| attributes: stdAttributes, | ||
| mountObjs: []map[string]interface{}{ | ||
| { | ||
| "objectName": "TestSecret1", | ||
| "objectType": "secretsmanager", | ||
| "jmesPath": []map[string]string{ | ||
| {"path": "dbUser.username", "objectAlias": "username"}, | ||
| {"path": "dbUser.password", "objectAlias": "password"}, | ||
| }, | ||
| }, | ||
| }, | ||
| ssmRsp: []*ssm.GetParametersOutput{}, | ||
| gsvRsp: []*secretsmanager.GetSecretValueOutput{ | ||
| {SecretString: aws.String(`{"dbUser": {"username": "user1", "password": "pass1"}}`), VersionId: aws.String("1")}, | ||
| }, | ||
| descRsp: []*secretsmanager.DescribeSecretOutput{}, | ||
| perms: "420", | ||
| } | ||
|
|
||
| for b.Loop() { | ||
| dir := b.TempDir() | ||
| svr := newServerWithMocks(&tst, true, nil) | ||
| req := buildBenchMountReq(dir, tst) | ||
| if _, err := svr.Mount(context.Background(), req); err != nil { | ||
| b.Fatal(err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func BenchmarkMount_LargeBatch(b *testing.B) { | ||
| mountObjs := make([]map[string]interface{}, 15) | ||
| params := make([]ssmtypes.Parameter, 15) | ||
| for i := range 15 { | ||
| name := "TestParm" + string(rune('A'+i)) | ||
| mountObjs[i] = map[string]interface{}{"objectName": name, "objectType": "ssmparameter"} | ||
| params[i] = ssmtypes.Parameter{Name: aws.String(name), Value: aws.String("val"), Version: 1} | ||
| } | ||
|
|
||
| tst := testCase{ | ||
| testName: "Bench Large Batch", | ||
| attributes: stdAttributes, | ||
| mountObjs: mountObjs, | ||
| ssmRsp: []*ssm.GetParametersOutput{ | ||
| {Parameters: params[:10]}, | ||
| {Parameters: params[10:]}, | ||
| }, | ||
| gsvRsp: []*secretsmanager.GetSecretValueOutput{}, | ||
| descRsp: []*secretsmanager.DescribeSecretOutput{}, | ||
| perms: "420", | ||
| } | ||
|
|
||
| for b.Loop() { | ||
| dir := b.TempDir() | ||
| svr := newServerWithMocks(&tst, true, nil) | ||
| req := buildBenchMountReq(dir, tst) | ||
| if _, err := svr.Mount(context.Background(), req); err != nil { | ||
| b.Fatal(err) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
As you pointed out on the agent, cache entries are immutable and the exact-key restore here might silently miss when the PR base SHA doesn't match a saved key. The GitHub docs recommend using a unique-per-run key with a restore-keys prefix fallback in a single actions/cache step, which lets you drop the separate save step too. I just fixed this on the agent repo
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.
The cache entry for the base sha should always exist since we run the action on every push.
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'm okay to ship as it'll work in the common case, and a miss would just mean no comparison (not a failure). The
github-action-benchmarkstep will still run, it just won't have a baseline to compare against. Non-blocking.