-
Notifications
You must be signed in to change notification settings - Fork 255
test: Add benchmarks for KMS signer #3205
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package aws | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "os" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "google.golang.org/protobuf/proto" | ||
|
|
||
| pb "github.com/evstack/ev-node/types/pb/evnode/v1" | ||
| ) | ||
|
|
||
| // BenchmarkKmsSignerSign test kms round trip | ||
| // export EVNODE_E2E_GCP_KMS_KEY_NAME=projects/<project-id>/locations/<region>/keyRings/<keyring-name>/cryptoKeys/<key-name>/cryptoKeyVersions/1 | ||
| // export EVNODE_E2E_GCP_KMS_CREDENTIALS_FILE=... | ||
| // go test -v -bench=BenchmarkKmsSignerSign -benchtime=3s -count=10 -run='^$' ./pkg/signer/gcp | ||
| func BenchmarkKmsSignerSign(b *testing.B) { | ||
| keyID := os.Getenv("EVNODE_E2E_AWS_KMS_KEY_ID") | ||
| if keyID == "" { | ||
| b.Skip("set EVNODE_E2E_AWS_KMS_KEY_ID to run AWS KMS benchmark") | ||
| } | ||
|
|
||
| region := firstNonEmpty( | ||
| os.Getenv("EVNODE_E2E_AWS_KMS_REGION"), | ||
| os.Getenv("AWS_REGION"), | ||
| os.Getenv("AWS_DEFAULT_REGION"), | ||
| ) | ||
| profile := os.Getenv("EVNODE_E2E_AWS_KMS_PROFILE") | ||
|
|
||
| signer, err := NewKmsSigner(b.Context(), region, profile, keyID, &Options{ | ||
| Timeout: 10 * time.Second, | ||
| MaxRetries: 0, | ||
| }) | ||
| require.NoError(b, err) | ||
|
|
||
| headerData := benchmarkHeaderData(b) | ||
|
|
||
| b.ReportAllocs() | ||
| b.SetBytes(int64(len(headerData))) | ||
| b.ResetTimer() | ||
|
|
||
| for b.Loop() { | ||
| _, err := signer.Sign(b.Context(), headerData) | ||
| require.NoError(b, err) | ||
| } | ||
| } | ||
|
|
||
| func firstNonEmpty(values ...string) string { | ||
| for _, value := range values { | ||
| if value != "" { | ||
| return value | ||
| } | ||
| } | ||
|
|
||
| return "" | ||
| } | ||
|
|
||
| func benchmarkHeaderData(b *testing.B) []byte { | ||
| b.Helper() | ||
|
|
||
| header := &pb.Header{ | ||
| Version: &pb.Version{ | ||
| Block: 11, | ||
| App: 1, | ||
| }, | ||
| Height: 1, | ||
| Time: 1743091200000000000, // 2025-03-27T00:00:00Z | ||
| LastHeaderHash: bytes.Repeat([]byte{0x3b}, 32), | ||
| DataHash: bytes.Repeat([]byte{0x78}, 32), | ||
| AppHash: bytes.Repeat([]byte{0xf5}, 32), | ||
| ProposerAddress: bytes.Repeat([]byte{0x25}, 32), | ||
| ValidatorHash: bytes.Repeat([]byte{0x25}, 32), | ||
| ChainId: "benchmark-chain", | ||
| } | ||
|
|
||
| headerData, err := proto.Marshal(header) | ||
| require.NoError(b, err) | ||
| require.NotEmpty(b, headerData) | ||
|
|
||
| return headerData | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,69 @@ | ||||||||||||||||||
| package gcp | ||||||||||||||||||
|
|
||||||||||||||||||
| import ( | ||||||||||||||||||
| "bytes" | ||||||||||||||||||
| "os" | ||||||||||||||||||
| "testing" | ||||||||||||||||||
| "time" | ||||||||||||||||||
|
|
||||||||||||||||||
| "github.com/stretchr/testify/require" | ||||||||||||||||||
| "google.golang.org/protobuf/proto" | ||||||||||||||||||
|
|
||||||||||||||||||
| pb "github.com/evstack/ev-node/types/pb/evnode/v1" | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| // BenchmarkKmsSignerSign test kms round trip | ||||||||||||||||||
| // export EVNODE_E2E_AWS_KMS_KEY_ID="arn:aws:kms:...." | ||||||||||||||||||
| // export EVNODE_E2E_AWS_KMS_REGION=eu-west-1 | ||||||||||||||||||
| // go test -v -bench=BenchmarkKmsSignerSign -benchtime=3s -count=10 -run='^$' ./pkg/signer/aws | ||||||||||||||||||
|
Comment on lines
+15
to
+18
Contributor
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. Copy-paste error: comments describe AWS instead of GCP. The comment block references AWS environment variables and the AWS package path, but this is the GCP benchmark file. The actual code correctly uses GCP variables. 📝 Suggested fix // BenchmarkKmsSignerSign test kms round trip
-// export EVNODE_E2E_AWS_KMS_KEY_ID="arn:aws:kms:...."
-// export EVNODE_E2E_AWS_KMS_REGION=eu-west-1
-// go test -v -bench=BenchmarkKmsSignerSign -benchtime=3s -count=10 -run='^$' ./pkg/signer/aws
+// export EVNODE_E2E_GCP_KMS_KEY_NAME=projects/<project-id>/locations/<region>/keyRings/<keyring-name>/cryptoKeys/<key-name>/cryptoKeyVersions/1
+// export EVNODE_E2E_GCP_KMS_CREDENTIALS_FILE=...
+// go test -v -bench=BenchmarkKmsSignerSign -benchtime=3s -count=10 -run='^$' ./pkg/signer/gcp📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| func BenchmarkKmsSignerSign(b *testing.B) { | ||||||||||||||||||
| keyName := os.Getenv("EVNODE_E2E_GCP_KMS_KEY_NAME") | ||||||||||||||||||
| if keyName == "" { | ||||||||||||||||||
| b.Skip("set EVNODE_E2E_GCP_KMS_KEY_NAME to run GCP KMS benchmark") | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| credentialsFile := os.Getenv("EVNODE_E2E_GCP_KMS_CREDENTIALS_FILE") | ||||||||||||||||||
|
|
||||||||||||||||||
| signer, err := NewKmsSigner(b.Context(), keyName, &Options{ | ||||||||||||||||||
| CredentialsFile: credentialsFile, | ||||||||||||||||||
| Timeout: 1 * time.Second, | ||||||||||||||||||
| MaxRetries: 0, | ||||||||||||||||||
| }) | ||||||||||||||||||
| require.NoError(b, err) | ||||||||||||||||||
|
|
||||||||||||||||||
| headerData := benchmarkHeaderData(b) | ||||||||||||||||||
|
|
||||||||||||||||||
| b.ReportAllocs() | ||||||||||||||||||
| b.SetBytes(int64(len(headerData))) | ||||||||||||||||||
| b.ResetTimer() | ||||||||||||||||||
|
|
||||||||||||||||||
| for b.Loop() { | ||||||||||||||||||
| _, err := signer.Sign(b.Context(), headerData) | ||||||||||||||||||
| require.NoError(b, err) | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| func benchmarkHeaderData(b *testing.B) []byte { | ||||||||||||||||||
| b.Helper() | ||||||||||||||||||
|
|
||||||||||||||||||
| header := &pb.Header{ | ||||||||||||||||||
| Version: &pb.Version{ | ||||||||||||||||||
| Block: 11, | ||||||||||||||||||
| App: 1, | ||||||||||||||||||
| }, | ||||||||||||||||||
| Height: 1, | ||||||||||||||||||
| Time: 1743091200000000000, // 2025-03-27T00:00:00Z | ||||||||||||||||||
| LastHeaderHash: bytes.Repeat([]byte{0x3b}, 32), | ||||||||||||||||||
| DataHash: bytes.Repeat([]byte{0x78}, 32), | ||||||||||||||||||
| AppHash: bytes.Repeat([]byte{0xf5}, 32), | ||||||||||||||||||
| ProposerAddress: bytes.Repeat([]byte{0x25}, 32), | ||||||||||||||||||
| ValidatorHash: bytes.Repeat([]byte{0x25}, 32), | ||||||||||||||||||
| ChainId: "benchmark-chain", | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| headerData, err := proto.Marshal(header) | ||||||||||||||||||
| require.NoError(b, err) | ||||||||||||||||||
| require.NotEmpty(b, headerData) | ||||||||||||||||||
|
|
||||||||||||||||||
| return headerData | ||||||||||||||||||
| } | ||||||||||||||||||
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.
Copy-paste error: comments describe GCP instead of AWS.
The comment block references GCP environment variables and the GCP package path, but this is the AWS benchmark file. The actual code correctly uses AWS variables.
📝 Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents