diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e77ffe2 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,27 @@ +name: release + +on: + workflow_dispatch: + push: + tags: + - "v*" + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: setup go dependencies + uses: actions/setup-go@v5 + with: + go-version: "1.21" + + - name: build and publish backend release + uses: goreleaser/goreleaser-action@v5 + with: + args: release --clean + distribution: goreleaser + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml index 0ada2b1..db62b6c 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -25,8 +25,5 @@ archives: checksum: name_template: 'checksums.txt' -signs: - - artifacts: checksum - release: prerelease: auto diff --git a/cmd/serve.go b/cmd/serve.go index f10809a..5b64d3d 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -1,6 +1,7 @@ package main import ( + "net/http" "time" "github.com/flashbots/node-healthchecker/healthchecker" @@ -34,6 +35,30 @@ func CommandServe() *cli.Command { Value: time.Second, }, + &cli.IntFlag{ + Category: "Serving:", + Destination: &cfg.StatusOk, + Name: "status-ok", + Usage: "http `status` to report for good healthchecks", + Value: http.StatusOK, + }, + + &cli.IntFlag{ + Category: "Serving:", + Destination: &cfg.StatusWarning, + Name: "status-warning", + Usage: "http `status` to report for warning healthchecks", + Value: http.StatusAccepted, + }, + + &cli.IntFlag{ + Category: "Serving:", + Destination: &cfg.StatusError, + Name: "status-error", + Usage: "http `status` to report for error healthchecks", + Value: http.StatusInternalServerError, + }, + // Monitoring &cli.StringFlag{ diff --git a/go.mod b/go.mod index a12698e..645b45c 100644 --- a/go.mod +++ b/go.mod @@ -3,14 +3,14 @@ module github.com/flashbots/node-healthchecker go 1.21 require ( - github.com/google/uuid v1.3.1 - github.com/urfave/cli/v2 v2.25.7 - go.uber.org/zap v1.26.0 + github.com/google/uuid v1.6.0 + github.com/urfave/cli/v2 v2.27.2 + go.uber.org/zap v1.27.0 ) require ( - github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect go.uber.org/multierr v1.11.0 // indirect ) diff --git a/go.sum b/go.sum index e06886d..f1a2fcc 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,13 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1/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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= @@ -12,13 +16,19 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= +github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI= +github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4= +github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM= go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= +go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= +go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/healthchecker/healthchecker.go b/healthchecker/healthchecker.go index ff709ec..5477184 100644 --- a/healthchecker/healthchecker.go +++ b/healthchecker/healthchecker.go @@ -22,6 +22,10 @@ type Healthchecker struct { timeout time.Duration monitors []healthcheckMonitor + + statusOk int + statusWarning int + statusError int } type healthcheckMonitor = func(context.Context) *healthcheckResult @@ -37,6 +41,10 @@ type Config struct { ServeAddress string Timeout time.Duration + + StatusOk int + StatusWarning int + StatusError int } func New(cfg *Config) (*Healthchecker, error) { @@ -44,6 +52,10 @@ func New(cfg *Config) (*Healthchecker, error) { addr: cfg.ServeAddress, log: zap.L(), timeout: cfg.Timeout, + + statusOk: cfg.StatusOk, + statusWarning: cfg.StatusWarning, + statusError: cfg.StatusError, } // Configure geth checks @@ -140,10 +152,11 @@ func (h *Healthchecker) handleHTTPRequest(w http.ResponseWriter, r *http.Request switch { case len(errs) == 0 && len(warns) == 0: + w.WriteHeader(h.statusOk) return case len(errs) > 0: - w.WriteHeader(http.StatusInternalServerError) + w.WriteHeader(h.statusError) w.Header().Set("Content-Type", "application/text") for idx, err := range errs { @@ -168,7 +181,7 @@ func (h *Healthchecker) handleHTTPRequest(w http.ResponseWriter, r *http.Request ) case len(errs) == 0 && len(warns) > 0: - w.WriteHeader(http.StatusAccepted) + w.WriteHeader(h.statusWarning) w.Header().Set("Content-Type", "application/text") for idx, warn := range warns {