Skip to content
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

additional covenant signer metrics #99

Merged
merged 2 commits into from
Jan 27, 2025
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -43,6 +43,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
* [#95](https://github.com/babylonlabs-io/covenant-emulator/pull/95) removed local signer option
as the covenant emulator should only connect to a remote signer
* [#96](https://github.com/babylonlabs-io/covenant-emulator/pull/96) add pagination to `queryDelegationsWithStatus`
* [#99](https://github.com/babylonlabs-io/covenant-emulator/pull/99) add more metrics
covenant-signer

## v0.11.3

30 changes: 26 additions & 4 deletions covenant-signer/observability/metrics/signer.go
Original file line number Diff line number Diff line change
@@ -6,10 +6,12 @@ import (
)

type CovenantSignerMetrics struct {
Registry *prometheus.Registry
ReceivedSigningRequests prometheus.Counter
SuccessfulSigningRequests prometheus.Counter
FailedSigningRequests prometheus.Counter
Registry *prometheus.Registry
ReceivedSigningRequests prometheus.Counter
SuccessfulSigningRequests prometheus.Counter
FailedSigningRequests prometheus.Counter
SignerUnlockStatus prometheus.Gauge
SignerFailedUnlockRequests prometheus.Counter
}

func NewCovenantSignerMetrics() *CovenantSignerMetrics {
@@ -30,6 +32,14 @@ func NewCovenantSignerMetrics() *CovenantSignerMetrics {
Name: "signer_failed_signing_requests",
Help: "The total number of times signer responded with an internal error",
}),
SignerUnlockStatus: registerer.NewGauge(prometheus.GaugeOpts{
Name: "signer_unlock_status",
Help: "The status indicating if the signer is unlocked or locked. 1 for unlocked, 0 for locked",
}),
SignerFailedUnlockRequests: registerer.NewCounter(prometheus.CounterOpts{
Name: "signer_failed_unlock_requests",
Help: "The total number of times the signer failed to unlock",
}),
}

return uwMetrics
@@ -46,3 +56,15 @@ func (m *CovenantSignerMetrics) IncSuccessfulSigningRequests() {
func (m *CovenantSignerMetrics) IncFailedSigningRequests() {
m.FailedSigningRequests.Inc()
}

func (m *CovenantSignerMetrics) SetSignerUnlocked() {
m.SignerUnlockStatus.Set(1)
}

func (m *CovenantSignerMetrics) SetSignerLocked() {
m.SignerUnlockStatus.Set(0)
}

func (m *CovenantSignerMetrics) IncFailedUnlockRequests() {
m.SignerFailedUnlockRequests.Inc()
}
5 changes: 5 additions & 0 deletions covenant-signer/signerservice/handlers/signtransactions.go
Original file line number Diff line number Diff line change
@@ -64,9 +64,12 @@ func (h *Handler) Unlock(request *http.Request) (*Result, *types.Error) {

err = h.s.Unlock(request.Context(), payload.Passphrase)
if err != nil {
h.m.IncFailedUnlockRequests()
return nil, types.NewErrorWithMsg(http.StatusBadRequest, types.BadRequest, err.Error())
}

h.m.SetSignerUnlocked()

return NewResult(&types.UnlockResponse{}), nil
}

@@ -76,5 +79,7 @@ func (h *Handler) Lock(request *http.Request) (*Result, *types.Error) {
return nil, types.NewErrorWithMsg(http.StatusBadRequest, types.BadRequest, err.Error())
}

h.m.SetSignerLocked()

return NewResult(&types.LockResponse{}), nil
}