Skip to content

Trendyol/gobreaker-metrics

Repository files navigation

gobreaker-metrics

This library enables you to monitor the state of your sony/gobreaker circuit breaker in real-time using Prometheus. It provides essential metrics like circuit state, failure rate, success rate, and others to track the health and performance of your circuit breakers.

The library is inspired by resilience4j-micrometer and acts as a similar tool but specifically designed for sony/gobreaker. Currently, no other metric library exists for gobreaker, making this tool a unique addition to the monitoring ecosystem.

Features

  • Monitor Circuit State: Track if the circuit breaker is in a closed, open, or half-open state.
  • Track Success and Failure Rates: Understand how your circuit breaker performs under different load conditions.
  • Prometheus Integration: Seamlessly export metrics to Prometheus for powerful visualization and alerting.
  • Lightweight and Easy-to-Integrate: Designed to work with your existing Go-Sony Breaker setup without much overhead. Getting Started

Prerequisites

  • gobreaker: Ensure that your project is already using sony/gobreaker.
  • Prometheus: This library is built to export metrics to Prometheus. You need a Prometheus server running to scrape the metrics.

Installation

You can add the library to your Go module by running:

go get github.com/Trendyol/gobreaker-metrics

Basic Setup

Below is a sample code snippet to demonstrate how to start monitoring your Go-Sony Breaker circuit breaker using this library.

package main

import (
	"github.com/sony/gobreaker/v2"
	"gobreaker-metric/gobreakerexporter"
	"time"
)

func main() {
	circuitBreaker := gobreaker.NewCircuitBreaker[any](gobreaker.Settings{Name: ""})
	gobreakerexporter.Of(circuitBreaker).Start(time.Second * 1)
}

Prometheus Configuration

To scrape the metrics from the exporter, make sure prometheus '/metrics' endpoint active. Add the following Prometheus configuration to your code if you use the Gin web framework:

router.GET("/metrics", prometheusHandler())

func prometheusHandler() gin.HandlerFunc {
h := promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{DisableCompression: true})

return func (c *gin.Context) {
h.ServeHTTP(c.Writer, c.Request)
}  
}

Available Metrics

The following metrics are exposed by the library:

Metric Name Type Tags Description
gobreaker_state Gauge name="circuit-breaker-name" state="open|half_open|closed" Indicates the current state of the circuit breaker
gobreaker_requests_total Counter name="circuit-breaker-name" Total number of requests made through the circuit breaker
gobreaker_success_total Counter name="circuit-breaker-name" Total number of successful requests
gobreaker_failure_total Counter name="circuit-breaker-name" Total number of failed requests handled by the circuit breaker
gobreaker_consecutive_success_total Counter name="circuit-breaker-name" Total number of consecutive successful requests
gobreaker_consecutive_failure_total Counter name="circuit-breaker-name" Total number of consecutive failedöö requests

These metrics provide a comprehensive view of the circuit breaker's health and allow you to set up alerting rules in Prometheus to be notified of potential issues.

Grafana

Here is a pre-built Grafana dashboard that can be easily imported to get you started quickly.

img.png

img.png

Troubleshooting

If you encounter issues, here are a few common checks:

  • Verify Prometheus Target: Ensure Prometheus can access the /metrics endpoint.
  • Check Circuit Breaker Configurations: Ensure your Go-Sony Breaker is set up correctly.
  • Debug Logs: Enable debug logs to get more insights into the metrics exporter.

Contributing

We welcome contributions! Please open issues or pull requests for any bugs, feature requests, or improvements.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages