feat(account): #49 add mertrics
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 4m8s
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 4m4s

This commit was merged in pull request #63.
This commit is contained in:
2025-05-10 23:27:03 +02:00
parent 0792d8e01a
commit df022c9077
2 changed files with 17 additions and 2 deletions

View File

@@ -13,7 +13,7 @@ import (
var ( var (
errorMetric = promauto.NewCounter( errorMetric = promauto.NewCounter(
prometheus.CounterOpts{ prometheus.CounterOpts{
Name: "mefit_error_total", Name: "spendsparrow_error_total",
Help: "The total number of errors during processing", Help: "The total number of errors during processing",
}, },
) )

View File

@@ -9,10 +9,20 @@ import (
"spend-sparrow/types" "spend-sparrow/types"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
) )
var ( var (
safeInputRegex = regexp.MustCompile(`^[a-zA-Z0-9äöüß -]+$`) safeInputRegex = regexp.MustCompile(`^[a-zA-Z0-9äöüß -]+$`)
accountMetric = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "spendsparrow_account_total",
Help: "The total of account operations",
},
[]string{"operation"},
)
) )
type Account interface { type Account interface {
@@ -40,6 +50,8 @@ func NewAccountImpl(db db.Account, random Random, clock Clock, settings *types.S
} }
func (s AccountImpl) Add(user *types.User, name string) (*types.Account, error) { func (s AccountImpl) Add(user *types.User, name string) (*types.Account, error) {
accountMetric.WithLabelValues("add").Inc()
if user == nil { if user == nil {
return nil, ErrUnauthorized return nil, ErrUnauthorized
} }
@@ -84,6 +96,7 @@ func (s AccountImpl) Add(user *types.User, name string) (*types.Account, error)
} }
func (s AccountImpl) Update(user *types.User, id uuid.UUID, name string) (*types.Account, error) { func (s AccountImpl) Update(user *types.User, id uuid.UUID, name string) (*types.Account, error) {
accountMetric.WithLabelValues("update").Inc()
if user == nil { if user == nil {
return nil, ErrUnauthorized return nil, ErrUnauthorized
} }
@@ -114,6 +127,7 @@ func (s AccountImpl) Update(user *types.User, id uuid.UUID, name string) (*types
} }
func (s AccountImpl) Get(user *types.User, id uuid.UUID) (*types.Account, error) { func (s AccountImpl) Get(user *types.User, id uuid.UUID) (*types.Account, error) {
accountMetric.WithLabelValues("get").Inc()
if user == nil { if user == nil {
return nil, ErrUnauthorized return nil, ErrUnauthorized
@@ -131,7 +145,7 @@ func (s AccountImpl) Get(user *types.User, id uuid.UUID) (*types.Account, error)
} }
func (s AccountImpl) GetAll(user *types.User) ([]*types.Account, error) { func (s AccountImpl) GetAll(user *types.User) ([]*types.Account, error) {
accountMetric.WithLabelValues("get_all").Inc()
if user == nil { if user == nil {
return nil, ErrUnauthorized return nil, ErrUnauthorized
} }
@@ -145,6 +159,7 @@ func (s AccountImpl) GetAll(user *types.User) ([]*types.Account, error) {
} }
func (s AccountImpl) Delete(user *types.User, id uuid.UUID) error { func (s AccountImpl) Delete(user *types.User, id uuid.UUID) error {
accountMetric.WithLabelValues("delete").Inc()
if user == nil { if user == nil {
return ErrUnauthorized return ErrUnauthorized
} }