Skip to content

Commit

Permalink
add error counters and address review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
pleasew8t committed Nov 29, 2024
1 parent a6cc5c6 commit ad10691
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 12 deletions.
7 changes: 6 additions & 1 deletion node/pkg/guardiansigner/amazonkms.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewAmazonKmsSigner(ctx context.Context, unsafeDevMode bool, keyPath string)

amazonKmsSigner := AmazonKms{
keyId: keyPath,
region: getRegionFromArn(keyPath),
region: region,
}

// Create a configuration object to create a new KMS client from. The region passed to
Expand Down Expand Up @@ -208,6 +208,11 @@ func (a *AmazonKms) Verify(ctx context.Context, sig []byte, hash []byte) (bool,
return recoveredPubKey.Equal(kmsPublicKey), nil
}

// Return the signer type as "amazonkms".
func (a *AmazonKms) TypeAsString() string {
return "amazonkms"
}

// https://bitcoin.stackexchange.com/questions/92680/what-are-the-der-signature-and-sec-format
// 1. 0x30 byte: header byte to indicate compound structure
// 2. one byte to encode the length of the following data
Expand Down
60 changes: 49 additions & 11 deletions node/pkg/guardiansigner/benchmarksigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,48 @@ type BenchmarkSigner struct {
}

var (
guardianSignerSigningLatency prometheus.Histogram
guardianSignerSigningErrorCount prometheus.Counter
guardianSignerVerifyLatency prometheus.Histogram
guardianSignerVerifyErrorCount prometheus.Counter
)

func BenchmarkWrappedSigner(innerSigner GuardianSigner) *BenchmarkSigner {
if innerSigner == nil {
return nil
}

signerType := innerSigner.TypeAsString()

guardianSignerSigningLatency = promauto.NewHistogram(
prometheus.HistogramOpts{
Name: "wormhole_guardian_signer_signing_latency_us",
Help: "Latency histogram for Guardian signing requests",
Buckets: []float64{10.0, 20.0, 50.0, 100.0, 1000.0, 5000.0, 10000.0, 100_000.0, 1_000_000.0, 10_000_000.0, 100_000_000.0, 1_000_000_000.0},
Name: "wormhole_guardian_signer_signing_latency_us",
Help: "Latency histogram for Guardian signing requests",
Buckets: []float64{10.0, 20.0, 50.0, 100.0, 1000.0, 5000.0, 10000.0, 100_000.0, 1_000_000.0, 10_000_000.0, 100_000_000.0, 1_000_000_000.0},
ConstLabels: prometheus.Labels{"signer_type": signerType},
})

guardianSignerSigningErrorCount = promauto.NewCounter(
prometheus.CounterOpts{
Name: "wormhole_guardian_signer_signing_error_count",
Help: "Total number of errors that ocurred during Guardian signing requests",
ConstLabels: prometheus.Labels{"signer_type": signerType},
})

guardianSignerVerifyLatency = promauto.NewHistogram(
prometheus.HistogramOpts{
Name: "wormhole_guardian_signer_sig_verify_latency_us",
Help: "Latency histogram for Guardian signature verification requests",
Buckets: []float64{10.0, 20.0, 50.0, 100.0, 1000.0, 5000.0, 10000.0, 100_000.0, 1_000_000.0, 10_000_000.0, 100_000_000.0, 1_000_000_000.0},
Name: "wormhole_guardian_signer_sig_verify_latency_us",
Help: "Latency histogram for Guardian signature verification requests",
Buckets: []float64{10.0, 20.0, 50.0, 100.0, 1000.0, 5000.0, 10000.0, 100_000.0, 1_000_000.0, 10_000_000.0, 100_000_000.0, 1_000_000_000.0},
ConstLabels: prometheus.Labels{"signer_type": signerType},
})
)

func BenchmarkWrappedSigner(innerSigner GuardianSigner) *BenchmarkSigner {
if innerSigner == nil {
return nil
}
guardianSignerVerifyErrorCount = promauto.NewCounter(
prometheus.CounterOpts{
Name: "wormhole_guardian_signer_verify_error_count",
Help: "Total number of errors that ocurred during Guardian signature verification requests",
ConstLabels: prometheus.Labels{"signer_type": signerType},
})

return &BenchmarkSigner{
innerSigner: innerSigner,
Expand All @@ -57,6 +80,11 @@ func (b *BenchmarkSigner) Sign(ctx context.Context, hash []byte) ([]byte, error)
// Add Observation to histogram
guardianSignerSigningLatency.Observe(float64(duration.Microseconds()))

// If an error occured, increment the error counter
if err != nil {
guardianSignerSigningErrorCount.Inc()
}

return sig, err
}

Expand All @@ -74,5 +102,15 @@ func (b *BenchmarkSigner) Verify(ctx context.Context, sig []byte, hash []byte) (
// Add observation to histogram
guardianSignerVerifyLatency.Observe(float64(duration.Microseconds()))

// If an error occured, increment the error counter
if err != nil {
guardianSignerVerifyErrorCount.Inc()
}

return valid, err
}

// Return the type of signer as "benchmark".
func (b *BenchmarkSigner) TypeAsString() string {
return "benchmark"
}
5 changes: 5 additions & 0 deletions node/pkg/guardiansigner/filesigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,8 @@ func (fs *FileSigner) Verify(ctx context.Context, sig []byte, hash []byte) (bool

return recoveredPubKey.Equal(fsPubkey), nil
}

// Return the signer type as "file".
func (fs *FileSigner) TypeAsString() string {
return "file"
}
5 changes: 5 additions & 0 deletions node/pkg/guardiansigner/generatedsigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func (gs *GeneratedSigner) Verify(ctx context.Context, sig []byte, hash []byte)
return recoveredPubKey.Equal(fsPubkey), nil
}

// Return the signer type as "generated".
func (gs *GeneratedSigner) TypeAsString() string {
return "generated"
}

// This function is meant to be a helper function that returns a guardian signer for tests
// that simply require a private key. The caller can specify a private key to be used, or
// pass nil to have `NewGeneratedSigner` generate a random private key.
Expand Down
2 changes: 2 additions & 0 deletions node/pkg/guardiansigner/guardiansigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type GuardianSigner interface {
// Verify is a convenience function that recovers a public key from the sig/hash pair,
// and checks if the public key matches that of the guardian signer.
Verify(ctx context.Context, sig []byte, hash []byte) (valid bool, err error)
// Return the type of signer as string.
TypeAsString() string
}

// Create a new GuardianSigner from the given URI. The caller can also specify the
Expand Down

0 comments on commit ad10691

Please sign in to comment.