diff --git a/README.md b/README.md index 4ded8ad..32f2399 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Consumer Orchestration made easy * [Ziggurat Handler interface](#ziggurat-handler-interface) * [Writing custom re-usable middlewares](#writing-custom-re-usable-middlewares) * [A practical example](#a-practical-example) + * [Bundled middlewares with Ziggurat-go](#bundled-middlewares-with-ziggurat-go) * [Ziggurat Event struct](#ziggurat-event-struct) * [Description](#description) * [Ziggurat MessageConsumer interface](#ziggurat-messageconsumer-interface) @@ -221,9 +222,41 @@ func main() { _ = zig.Run(context.Background(),handler,&kcg) } +``` + +#### Bundled middlewares with Ziggurat-go +Ziggurat Go includes two middlewares out of the box. +- Event Logger middleware + - The event logger middleware logs to the STDOUT whenever an event is received. + - Usage +```go +hf := ziggurat.HandlerFunc(func(context.Context,*ziggurat.Event){...}) +l := someLogger() // must implement the ziggurat.StructuredLogger interface +eventLoggerMW := event.Logger(l) +handler := ziggurat.Use(hf,eventLoggerMW) +ziggurat.Run(context.Background(),handler) +``` +- Prometheus middleware + - The Prometheus middleware emits handler metrics using the Prometheus exporter server + - Usage +```go +hf := ziggurat.HandlerFunc(func(context.Context,*ziggurat.Event){...}) +prometheus.Register() // registers promethues registry handlers +go func() { + prometheus.StartMonitoringServer(context.Background(),....) +} +eventLoggerMW := event.Logger(l) +handler := ziggurat.Use(hf,promtheues.PublishHandlerMetrics) +ziggurat.Run(context.Background(),handler) +``` +To get the metrics +```shell +curl -vv "http://localhost:9090/metrics" ``` + + ## Ziggurat Event struct The `ziggurat.Event` struct is a generic event struct that is passed to the handler. This is a pointer value and should diff --git a/mw/prometheus/prometheus.go b/mw/prometheus/prometheus.go index 5568bdc..1248046 100644 --- a/mw/prometheus/prometheus.go +++ b/mw/prometheus/prometheus.go @@ -40,17 +40,6 @@ var HandlerEventsCounter = prometheus.NewCounterVec( []string{RouteLabel}, ) -// HandlerFailuresCounter - Prometheus counter for handler failures -var HandlerFailuresCounter = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: handlerSubsystem, - Name: "failures_total", - Help: "Event handler failures, partitioned by route", - }, - []string{RouteLabel}, -) - // HandlerDurationHistogram - Prometheus histogram for handler duration var HandlerDurationHistogram = prometheus.NewHistogramVec( prometheus.HistogramOpts{ @@ -71,7 +60,6 @@ func StartMonitoringServer(ctx context.Context, opts ...ServerOpts) error { func Register() { prometheus.MustRegister( HandlerEventsCounter, - HandlerFailuresCounter, HandlerDurationHistogram, ) } @@ -87,7 +75,6 @@ func PublishHandlerMetrics(next ziggurat.Handler) ziggurat.Handler { } HandlerDurationHistogram.With(labels).Observe(time.Since(t1).Seconds()) - HandlerEventsCounter.With(labels).Inc() }