Skip to content

Commit

Permalink
fix(loader-metrics): Update reload metrics, include result (#15)
Browse files Browse the repository at this point in the history
Update reload metrics for peristed operations, include result label

Co-authored-by: ldebruijn <[email protected]>
  • Loading branch information
ldebruijn and ldebruijn authored Jan 9, 2024
1 parent 7cea98a commit d161eeb
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions internal/business/persisted_operations/persisted_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ var (
},
[]string{"state", "result"},
)
reloadGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
reloadCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "go_graphql_armor",
Subsystem: "persisted_operations",
Name: "reload",
Help: "Gauge tracking reloading behavior",
Help: "Counter tracking reloading behavior and results",
ConstLabels: nil,
},
[]string{"system"})
[]string{"system", "result"})
)

type ErrorPayload struct {
Expand Down Expand Up @@ -76,7 +76,7 @@ type PersistedOperationsHandler struct {
}

func init() {
prometheus.MustRegister(persistedOpsCounter, reloadGauge)
prometheus.MustRegister(persistedOpsCounter, reloadCounter)
}

func NewPersistedOperations(log *slog.Logger, cfg Config, loader LocalLoader, remoteLoader RemoteLoader) (*PersistedOperationsHandler, error) {
Expand Down Expand Up @@ -201,14 +201,15 @@ func (p *PersistedOperationsHandler) Execute(next http.Handler) http.Handler {
func (p *PersistedOperationsHandler) reloadFromLocalDir() error {
cache, err := p.dirLoader.Load(context.Background())
if err != nil {
reloadCounter.WithLabelValues("local", "failure").Inc()
return err
}
p.lock.Lock()
p.cache = cache
p.lock.Unlock()

p.log.Info("Loaded persisted operations", "amount", len(cache))
reloadGauge.WithLabelValues("local").Set(1)
reloadCounter.WithLabelValues("local", "success").Inc()

return nil
}
Expand All @@ -228,8 +229,10 @@ func (p *PersistedOperationsHandler) reload() {
err := p.reloadFromLocalDir()
if err != nil {
p.log.Warn("Error loading from local dir", "err", err)
reloadCounter.WithLabelValues("ticker", "failure").Inc()
continue
}
reloadGauge.WithLabelValues("ticker").Set(1)
reloadCounter.WithLabelValues("ticker", "success").Inc()
}
}
}()
Expand All @@ -245,10 +248,11 @@ func (p *PersistedOperationsHandler) reloadFromRemote() {

err := p.remoteLoader.Load(ctx)
if err != nil {
reloadCounter.WithLabelValues("remote", "failure").Inc()
return
}

reloadGauge.WithLabelValues("remote").Set(1)
reloadCounter.WithLabelValues("remote", "success").Inc()
}

func (p *PersistedOperationsHandler) Shutdown() {
Expand Down

0 comments on commit d161eeb

Please sign in to comment.