Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/bench.yml
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 }}

@reyhankoyun reyhankoyun Apr 16, 2026

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor

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-benchmark step will still run, it just won't have a baseline to compare against. Non-blocking.


- 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
Comment thread
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 }}
170 changes: 170 additions & 0 deletions server/benchmark_test.go
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() {
Comment thread
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)
}
}
}
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Package responsible for reciving incomming mount requests from the driver.
* Package responsible for receiving incoming mount requests from the driver.
*
* This package acts as the high level orchestrator; unpacking the message and
* calling the provider implementation to fetch the secrets.
Expand Down
Loading