Skip to content

Commit

Permalink
Merge pull request #23 from ihippik/feature/21-add-metrics
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
ihippik authored Mar 6, 2024
2 parents 32a1984 + a4ba932 commit 43edb01
Show file tree
Hide file tree
Showing 11 changed files with 297 additions and 405 deletions.
28 changes: 23 additions & 5 deletions config/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,36 @@ import (

// Metrics Prometheus metrics.
type Metrics struct {
filterSkippedEvents, publishedEvents *prometheus.CounterVec
filterSkippedEvents, publishedEvents, problematicEvents *prometheus.CounterVec
}

const (
labelApp = "app"
labelTable = "table"
labelSubject = "subject"
labelKind = "kind"
)

// NewMetrics create and initialize new Prometheus metrics.
func NewMetrics() *Metrics {
return &Metrics{
publishedEvents: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "published_events_total",
Help: "The total number of published events",
},
[]string{"app", "subject", "table"},
[]string{labelApp, labelSubject, labelTable},
),
problematicEvents: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "problematic_events_total",
Help: "The total number of skipped problematic events",
},
[]string{labelApp, labelKind},
),
filterSkippedEvents: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "filter_skipped_events_total",
Help: "The total number of skipped events",
},
[]string{"app", "table"},
[]string{labelApp, labelTable},
),
}
}
Expand All @@ -32,10 +45,15 @@ const appName = "wal-listener"

// IncPublishedEvents increment published events counter.
func (m Metrics) IncPublishedEvents(subject, table string) {
m.publishedEvents.With(prometheus.Labels{"app": appName, "subject": subject, "table": table}).Inc()
m.publishedEvents.With(prometheus.Labels{labelApp: appName, labelSubject: subject, labelTable: table}).Inc()
}

// IncFilterSkippedEvents increment skipped by filter events counter.
func (m Metrics) IncFilterSkippedEvents(table string) {
m.filterSkippedEvents.With(prometheus.Labels{"app": appName, "table": table}).Inc()
m.filterSkippedEvents.With(prometheus.Labels{labelApp: appName, labelTable: table}).Inc()
}

// IncProblematicEvents increment skipped by filter events counter.
func (m Metrics) IncProblematicEvents(kind string) {
m.problematicEvents.With(prometheus.Labels{labelApp: appName, labelKind: kind}).Inc()
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.26.0
github.com/wagslane/go-rabbitmq v0.12.4
golang.org/x/sync v0.6.0
)

require (
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
Expand Down
13 changes: 0 additions & 13 deletions listener/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,3 @@ var (
errUnknownMessageType = errors.New("unknown message type")
errRelationNotFound = errors.New("relation not found")
)

type serviceErr struct {
Caller string
Err error
}

func newListenerError(caller string, err error) *serviceErr {
return &serviceErr{Caller: caller, Err: err}
}

func (e *serviceErr) Error() string {
return e.Caller + ": " + e.Err.Error()
}
70 changes: 0 additions & 70 deletions listener/errors_test.go

This file was deleted.

Loading

0 comments on commit 43edb01

Please sign in to comment.