Skip to content

Commit

Permalink
additional covenant signer metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
KonradStaniec committed Jan 27, 2025
1 parent 58904be commit 593fed8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
30 changes: 26 additions & 4 deletions covenant-signer/observability/metrics/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand Up @@ -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
}

Expand All @@ -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
}

0 comments on commit 593fed8

Please sign in to comment.