Skip to content

Commit

Permalink
updates docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubhang Balkundi committed Apr 1, 2024
1 parent 10468da commit 1b36beb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions mw/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -71,7 +60,6 @@ func StartMonitoringServer(ctx context.Context, opts ...ServerOpts) error {
func Register() {
prometheus.MustRegister(
HandlerEventsCounter,
HandlerFailuresCounter,
HandlerDurationHistogram,
)
}
Expand All @@ -87,7 +75,6 @@ func PublishHandlerMetrics(next ziggurat.Handler) ziggurat.Handler {
}

HandlerDurationHistogram.With(labels).Observe(time.Since(t1).Seconds())

HandlerEventsCounter.With(labels).Inc()

}
Expand Down

0 comments on commit 1b36beb

Please sign in to comment.