{"id":18150047,"url":"https://github.com/sysulq/gobreak","last_synced_at":"2025-08-03T23:06:22.622Z","repository":{"id":57485810,"uuid":"98709921","full_name":"sysulq/gobreak","owner":"sysulq","description":"Latency and fault tolerance library like Netflix's Hystrix with prometheus and gobreaker.","archived":false,"fork":false,"pushed_at":"2024-05-30T06:54:36.000Z","size":119,"stargazers_count":44,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-15T11:25:30.916Z","etag":null,"topics":["circuit-breaker","gobreak","gobreaker","golang","hystrix","prometheus"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/hnlq715/gobreak","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sysulq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-29T05:09:56.000Z","updated_at":"2024-08-22T06:08:32.000Z","dependencies_parsed_at":"2024-06-08T08:20:26.068Z","dependency_job_id":"b4c02ce3-4aa9-4b77-9bb5-5a075c0708a1","html_url":"https://github.com/sysulq/gobreak","commit_stats":null,"previous_names":["sysulq/gobreak","hnlq715/gobreak"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/sysulq/gobreak","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysulq%2Fgobreak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysulq%2Fgobreak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysulq%2Fgobreak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysulq%2Fgobreak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sysulq","download_url":"https://codeload.github.com/sysulq/gobreak/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysulq%2Fgobreak/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268625009,"owners_count":24280188,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["circuit-breaker","gobreak","gobreaker","golang","hystrix","prometheus"],"created_at":"2024-11-02T00:07:17.003Z","updated_at":"2025-08-03T23:06:22.594Z","avatar_url":"https://github.com/sysulq.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gobreak\n[![Build Status](https://travis-ci.org/hnlq715/gobreak.svg?branch=master)](https://travis-ci.org/hnlq715/gobreak)\n[![Go Report Card](https://goreportcard.com/badge/github.com/sysulq/gobreak)](https://goreportcard.com/report/github.com/sysulq/gobreak)\n[![Coverage](https://codecov.io/gh/sysulq/gobreak/branch/master/graph/badge.svg)](https://codecov.io/gh/sysulq/gobreak)\n\nLatency and fault tolerance library like Netflix's Hystrix with prometheus and gobreaker.\n\nFeature\n---\n\n* Lightweight\n* Easy to use\n* Panic recoverable\n* Prometheus metric supported\n* Integrated with context.Context\n* Async and sync method supported\n* Unit test coverage almost 100%\n\nInstall\n---\n```\ngo get -u -v github.com/hnlq715/gobreak\n```\nTry example\n---\n```\npackage main\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"net/http\"\n\t\"os\"\n\t\"time\"\n\n\t\"github.com/hnlq715/gobreak\"\n\t\"github.com/prometheus/client_golang/prometheus\"\n)\n\nfunc main() {\n\n\thttp.HandleFunc(\"/test\", func(rw http.ResponseWriter, r *http.Request) {\n\t\terr := gobreak.Do(r.Context(), \"test\", func(context.Context) error {\n\t\t\treturn errors.New(\"mock error\\n\")\n\t\t}, func(context.Context, error) error {\n\t\t\treturn errors.New(\"fallback\\n\")\n\t\t})\n\t\trw.Write([]byte(err.Error()))\n\t})\n\n\thttp.HandleFunc(\"/timeout\", func(rw http.ResponseWriter, r *http.Request) {\n\t\terr := gobreak.Do(r.Context(), \"timeout\", func(context.Context) error {\n\t\t\ttime.Sleep(2 * time.Second)\n\t\t\treturn errors.New(\"mock error\\n\")\n\t\t}, nil)\n\t\trw.Write([]byte(err.Error()))\n\t})\n\n\tprometheus.Unregister(prometheus.NewGoCollector())\n\tprometheus.Unregister(prometheus.NewProcessCollector(os.Getpid(), \"\"))\n\thttp.Handle(\"/metrics\", prometheus.Handler())\n\thttp.ListenAndServe(\"0.0.0.0:8000\", nil)\n}\n```\n\n```\ngo install github.com/hnlq715/gobreak/example\n$(GOPATH)/bin/example\n```\n\n* Fail and fallback\n```\n➜  gobreak git:(master) ✗ curl localhost:8000\nfallback\n➜  gobreak git:(master) ✗ curl localhost:8000\nfallback\n➜  gobreak git:(master) ✗ curl localhost:8000\nfallback\n➜  gobreak git:(master) ✗ curl localhost:8000\nfallback\n```\n\n* Timeout and fast fail\n```\n➜  gobreak git:(master) ✗ time curl localhost:8000/timeout\nmock error\ncurl localhost:8000/timeout  0.01s user 0.01s system 0% cpu 2.026 total\n➜  gobreak git:(master) ✗ time curl localhost:8000/timeout\nmock error\ncurl localhost:8000/timeout  0.01s user 0.01s system 0% cpu 2.019 total\n➜  gobreak git:(master) ✗ time curl localhost:8000/timeout\nmock error\ncurl localhost:8000/timeout  0.01s user 0.01s system 0% cpu 2.021 total\n➜  gobreak git:(master) ✗ time curl localhost:8000/timeout\nmock error\ncurl localhost:8000/timeout  0.01s user 0.01s system 0% cpu 2.021 total\n➜  gobreak git:(master) ✗ time curl localhost:8000/timeout\nmock error\ncurl localhost:8000/timeout  0.01s user 0.01s system 0% cpu 2.018 total\n➜  gobreak git:(master) ✗ time curl localhost:8000/timeout\nmock error\ncurl localhost:8000/timeout  0.01s user 0.01s system 0% cpu 2.023 total\n➜  gobreak git:(master) ✗ time curl localhost:8000/timeout\ncircuit breaker 'timeout' is open\ncurl localhost:8000/timeout  0.01s user 0.01s system 68% cpu 0.019 total\n```\n\nPrometheus metrics\n---\n```\n# HELP gobreak_request_latency_histogram request latency histogram.\n# TYPE gobreak_request_latency_histogram histogram\ngobreak_request_latency_histogram_bucket{name=\"test\",le=\"0.005\"} 4\ngobreak_request_latency_histogram_bucket{name=\"test\",le=\"0.01\"} 4\ngobreak_request_latency_histogram_bucket{name=\"test\",le=\"0.025\"} 4\ngobreak_request_latency_histogram_bucket{name=\"test\",le=\"0.05\"} 4\ngobreak_request_latency_histogram_bucket{name=\"test\",le=\"0.1\"} 4\ngobreak_request_latency_histogram_bucket{name=\"test\",le=\"0.25\"} 4\ngobreak_request_latency_histogram_bucket{name=\"test\",le=\"0.5\"} 4\ngobreak_request_latency_histogram_bucket{name=\"test\",le=\"1\"} 4\ngobreak_request_latency_histogram_bucket{name=\"test\",le=\"2.5\"} 4\ngobreak_request_latency_histogram_bucket{name=\"test\",le=\"5\"} 4\ngobreak_request_latency_histogram_bucket{name=\"test\",le=\"10\"} 4\ngobreak_request_latency_histogram_bucket{name=\"test\",le=\"+Inf\"} 4\ngobreak_request_latency_histogram_sum{name=\"test\"} 1.1410000000000002e-06\ngobreak_request_latency_histogram_count{name=\"test\"} 4\ngobreak_request_latency_histogram_bucket{name=\"timeout\",le=\"0.005\"} 0\ngobreak_request_latency_histogram_bucket{name=\"timeout\",le=\"0.01\"} 0\ngobreak_request_latency_histogram_bucket{name=\"timeout\",le=\"0.025\"} 0\ngobreak_request_latency_histogram_bucket{name=\"timeout\",le=\"0.05\"} 0\ngobreak_request_latency_histogram_bucket{name=\"timeout\",le=\"0.1\"} 0\ngobreak_request_latency_histogram_bucket{name=\"timeout\",le=\"0.25\"} 0\ngobreak_request_latency_histogram_bucket{name=\"timeout\",le=\"0.5\"} 0\ngobreak_request_latency_histogram_bucket{name=\"timeout\",le=\"1\"} 0\ngobreak_request_latency_histogram_bucket{name=\"timeout\",le=\"2.5\"} 6\ngobreak_request_latency_histogram_bucket{name=\"timeout\",le=\"5\"} 6\ngobreak_request_latency_histogram_bucket{name=\"timeout\",le=\"10\"} 6\ngobreak_request_latency_histogram_bucket{name=\"timeout\",le=\"+Inf\"} 6\ngobreak_request_latency_histogram_sum{name=\"timeout\"} 12.018237157000002\ngobreak_request_latency_histogram_count{name=\"timeout\"} 6\n# HELP gobreak_requests request count.\n# TYPE gobreak_requests counter\ngobreak_requests{name=\"test\",state=\"fail\"} 4\ngobreak_requests{name=\"timeout\",state=\"fail\"} 6\ngobreak_requests{name=\"timeout\",state=\"reject\"} 4\n# HELP http_request_duration_microseconds The HTTP request latencies in microseconds.\n# TYPE http_request_duration_microseconds summary\nhttp_request_duration_microseconds{handler=\"prometheus\",quantile=\"0.5\"} NaN\nhttp_request_duration_microseconds{handler=\"prometheus\",quantile=\"0.9\"} NaN\nhttp_request_duration_microseconds{handler=\"prometheus\",quantile=\"0.99\"} NaN\nhttp_request_duration_microseconds_sum{handler=\"prometheus\"} 0\nhttp_request_duration_microseconds_count{handler=\"prometheus\"} 0\n# HELP http_request_size_bytes The HTTP request sizes in bytes.\n# TYPE http_request_size_bytes summary\nhttp_request_size_bytes{handler=\"prometheus\",quantile=\"0.5\"} NaN\nhttp_request_size_bytes{handler=\"prometheus\",quantile=\"0.9\"} NaN\nhttp_request_size_bytes{handler=\"prometheus\",quantile=\"0.99\"} NaN\nhttp_request_size_bytes_sum{handler=\"prometheus\"} 0\nhttp_request_size_bytes_count{handler=\"prometheus\"} 0\n# HELP http_response_size_bytes The HTTP response sizes in bytes.\n# TYPE http_response_size_bytes summary\nhttp_response_size_bytes{handler=\"prometheus\",quantile=\"0.5\"} NaN\nhttp_response_size_bytes{handler=\"prometheus\",quantile=\"0.9\"} NaN\nhttp_response_size_bytes{handler=\"prometheus\",quantile=\"0.99\"} NaN\nhttp_response_size_bytes_sum{handler=\"prometheus\"} 0\nhttp_response_size_bytes_count{handler=\"prometheus\"} 0\n```\n\nPrometheus Graph (like Netflix-dashboard)\n---\n\nAlso you can use `Grafana` instead to graph and alert, which is recommended.\n\n* metric: gobreak_requests\n```\nsum by(name, state) (irate(gobreak_requests[5m]))\n```\n\n![gobreak_requests](example/gobreak_requests.png)\n\n* metric: gobreak_request_latency_histogram [Apdex score](https://en.wikipedia.org/wiki/Apdex)\n\n```\n(sum(rate(gobreak_request_latency_histogram_bucket{le=\"0.05\"}[5m])) by (name) + (sum(rate(gobreak_request_latency_histogram_bucket{le=\"0.1\"}[5m])) by (name))) / 2/ sum(rate(gobreak_request_latency_histogram_count[5m])) by (name)\n```\n\n![gobreak_request_latency_histogram_bucket](example/gobreak_request_latency_histogram_bucket.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsysulq%2Fgobreak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsysulq%2Fgobreak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsysulq%2Fgobreak/lists"}