From 593fed811b91456d4b7596141e632e1794bf73d7 Mon Sep 17 00:00:00 2001 From: KonradStaniec Date: Mon, 27 Jan 2025 12:55:30 +0100 Subject: [PATCH 1/2] additional covenant signer metrics --- .../observability/metrics/signer.go | 30 ++++++++++++++++--- .../handlers/signtransactions.go | 5 ++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/covenant-signer/observability/metrics/signer.go b/covenant-signer/observability/metrics/signer.go index ba3dde5..bbd688d 100644 --- a/covenant-signer/observability/metrics/signer.go +++ b/covenant-signer/observability/metrics/signer.go @@ -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() +} diff --git a/covenant-signer/signerservice/handlers/signtransactions.go b/covenant-signer/signerservice/handlers/signtransactions.go index f0109b7..8d47036 100644 --- a/covenant-signer/signerservice/handlers/signtransactions.go +++ b/covenant-signer/signerservice/handlers/signtransactions.go @@ -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 } From 18a8a15d5ec8f31a649ebf0e1c795278b8e98871 Mon Sep 17 00:00:00 2001 From: KonradStaniec Date: Mon, 27 Jan 2025 12:58:40 +0100 Subject: [PATCH 2/2] cl --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03153b3..334a81a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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