diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index a4a983a..296aa09 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -17,16 +17,12 @@ jobs: - name: Check out code uses: actions/checkout@v2 - name: golangci-lint - uses: golangci/golangci-lint-action@v1 - env: - ACTIONS_ALLOW_UNSECURE_COMMANDS: "true" - with: - version: v1.33 + uses: golangci/golangci-lint-action@v2 test: name: Test runs-on: ubuntu-latest - needs: [lint] + needs: [ lint ] services: pg-pq: @@ -62,6 +58,11 @@ jobs: ports: - "5672" - "15672" + options: >- + --health-cmd "rabbitmqctl status" + --health-interval 10s + --health-timeout 5s + --health-retries 5 redis: image: redis:3.2-alpine @@ -77,6 +78,11 @@ jobs: image: mongo:3 ports: - "27017" + options: >- + --health-cmd "mongo localhost:27017/test --quiet --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'" + --health-interval 10s + --health-timeout 5s + --health-retries 5 mysql: image: mysql:5.7 @@ -105,7 +111,6 @@ jobs: ports: - "11211" - steps: - name: Set up Go uses: actions/setup-go@v2 @@ -124,10 +129,3 @@ jobs: HEALTH_GO_MS_DSN: test:test@tcp(localhost:${{ job.services.mysql.ports[3306] }})/test?charset=utf8 HEALTH_GO_HTTP_URL: http://localhost:${{ job.services.http.ports[8080] }}/status HEALTH_GO_MD_DSN: memcached://localhost:${{ job.services.memcached.ports[11211] }}/ - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 - if: success() - with: - file: ./coverage.txt - fail_ci_if_error: false diff --git a/README.md b/README.md index a44a06a..8e6f3c1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # health-go [![Go Report Card](https://goreportcard.com/badge/github.com/hellofresh/health-go)](https://goreportcard.com/report/github.com/hellofresh/health-go) [![Go Doc](https://godoc.org/github.com/hellofresh/health-go?status.svg)](https://godoc.org/github.com/hellofresh/health-go) -[![Coverage Status](https://codecov.io/gh/hellofresh/health-go/branch/master/graph/badge.svg)](https://codecov.io/gh/hellofresh/health-go) * Exposes an HTTP handler that retrieves health status of the application * Implements some generic checkers for the following services: @@ -18,7 +17,8 @@ The library exports `Handler` and `HandlerFunc` functions which are fully compatible with `net/http`. -Additionally, library exports `Measure` function that returns summary status for all the registered health checks, so it can be used in non-HTTP environments. +Additionally, library exports `Measure` function that returns summary status for all the registered health checks, +so it can be used in non-HTTP environments. ### Handler diff --git a/checks/http/check_test.go b/checks/http/check_test.go index 4feec5b..b398677 100644 --- a/checks/http/check_test.go +++ b/checks/http/check_test.go @@ -3,6 +3,7 @@ package http import ( "context" "os" + "strings" "testing" "github.com/stretchr/testify/require" @@ -25,5 +26,8 @@ func getURL(t *testing.T) string { httpURL, ok := os.LookupEnv(httpURLEnv) require.True(t, ok) + // "docker-compose port " returns 0.0.0.0:XXXX locally, change it to local port + httpURL = strings.Replace(httpURL, "0.0.0.0:", "127.0.0.1:", 1) + return httpURL } diff --git a/checks/mongo/check_test.go b/checks/mongo/check_test.go index 2a8b4c5..df2dffb 100644 --- a/checks/mongo/check_test.go +++ b/checks/mongo/check_test.go @@ -3,6 +3,7 @@ package mongo import ( "context" "os" + "strings" "testing" "github.com/stretchr/testify/require" @@ -25,5 +26,8 @@ func getDSN(t *testing.T) string { mongoDSN, ok := os.LookupEnv(mgDSNEnv) require.True(t, ok) + // "docker-compose port " returns 0.0.0.0:XXXX locally, change it to local port + mongoDSN = strings.Replace(mongoDSN, "0.0.0.0:", "127.0.0.1:", 1) + return mongoDSN } diff --git a/checks/mysql/check_test.go b/checks/mysql/check_test.go index 8883f82..de1aaca 100644 --- a/checks/mysql/check_test.go +++ b/checks/mysql/check_test.go @@ -4,6 +4,7 @@ import ( "context" "database/sql" "os" + "strings" "sync" "testing" "time" @@ -72,6 +73,9 @@ func getDSN(t *testing.T) string { mysqlDSN, ok := os.LookupEnv(mysqlDSNEnv) require.True(t, ok) + // "docker-compose port " returns 0.0.0.0:XXXX locally, change it to local port + mysqlDSN = strings.Replace(mysqlDSN, "0.0.0.0:", "127.0.0.1:", 1) + return mysqlDSN } diff --git a/checks/postgres/check_test.go b/checks/postgres/check_test.go index 795536f..403847d 100644 --- a/checks/postgres/check_test.go +++ b/checks/postgres/check_test.go @@ -4,6 +4,7 @@ import ( "context" "database/sql" "os" + "strings" "sync" "testing" "time" @@ -69,6 +70,9 @@ func getDSN(t *testing.T) string { pgDSN, ok := os.LookupEnv(pgDSNEnv) require.True(t, ok) + // "docker-compose port " returns 0.0.0.0:XXXX locally, change it to local port + pgDSN = strings.Replace(pgDSN, "0.0.0.0:", "127.0.0.1:", 1) + return pgDSN } diff --git a/checks/rabbitmq/aliveness_check_test.go b/checks/rabbitmq/aliveness_check_test.go index c0c2926..1c2dbf9 100644 --- a/checks/rabbitmq/aliveness_check_test.go +++ b/checks/rabbitmq/aliveness_check_test.go @@ -3,6 +3,7 @@ package rabbitmq import ( "context" "os" + "strings" "testing" "github.com/stretchr/testify/require" @@ -27,5 +28,8 @@ func getURL(t *testing.T) string { httpURL, ok := os.LookupEnv(httpURLEnv) require.True(t, ok) + // "docker-compose port " returns 0.0.0.0:XXXX locally, change it to local port + httpURL = strings.Replace(httpURL, "0.0.0.0:", "127.0.0.1:", 1) + return httpURL } diff --git a/checks/rabbitmq/check_test.go b/checks/rabbitmq/check_test.go index 6702147..d093b00 100644 --- a/checks/rabbitmq/check_test.go +++ b/checks/rabbitmq/check_test.go @@ -3,6 +3,7 @@ package rabbitmq import ( "context" "os" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -37,5 +38,8 @@ func getDSN(t *testing.T) string { mqDSN, ok := os.LookupEnv(mqDSNEnv) require.True(t, ok) + // "docker-compose port " returns 0.0.0.0:XXXX locally, change it to local port + mqDSN = strings.Replace(mqDSN, "0.0.0.0:", "127.0.0.1:", 1) + return mqDSN } diff --git a/checks/redis/check_test.go b/checks/redis/check_test.go index 323abcb..805ffe5 100644 --- a/checks/redis/check_test.go +++ b/checks/redis/check_test.go @@ -3,6 +3,7 @@ package redis import ( "context" "os" + "strings" "testing" "github.com/stretchr/testify/require" @@ -25,5 +26,8 @@ func getDSN(t *testing.T) string { redisDSN, ok := os.LookupEnv(rdDSNEnv) require.True(t, ok) + // "docker-compose port " returns 0.0.0.0:XXXX locally, change it to local port + redisDSN = strings.Replace(redisDSN, "0.0.0.0:", "127.0.0.1:", 1) + return redisDSN } diff --git a/docker-compose.yml b/docker-compose.yml index 123d697..cbfd8b1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,22 +18,42 @@ services: POSTGRES_USER: test POSTGRES_PASSWORD: test POSTGRES_DB: test + healthcheck: + test: [ "CMD", "pg_isready" ] + interval: 10s + timeout: 5s + retries: 5 rabbit: image: rabbitmq:3.6-management-alpine ports: - "5672" - "15672" + healthcheck: + test: [ "CMD", "rabbitmqctl", "status" ] + interval: 10s + timeout: 5s + retries: 5 redis: image: redis:3.2-alpine ports: - "6379" + healthcheck: + test: [ "CMD", "redis-cli", "ping" ] + interval: 10s + timeout: 5s + retries: 5 mongo: image: mongo:3 ports: - "27017" + healthcheck: + test: "mongo localhost:27017/test --quiet --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'" + interval: 10s + timeout: 5s + retries: 5 mysql: image: mysql:5.7 @@ -44,6 +64,11 @@ services: MYSQL_DATABASE: test MYSQL_USER: test MYSQL_PASSWORD: test + healthcheck: + test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ] + interval: 10s + timeout: 5s + retries: 5 memcached: image: memcached:1.6.9-alpine diff --git a/go.mod b/go.mod index 498fcaa..dce05b8 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/streadway/amqp v1.0.0 github.com/stretchr/testify v1.7.0 go.mongodb.org/mongo-driver v1.4.1 - go.opentelemetry.io/otel v0.19.0 - go.opentelemetry.io/otel/trace v0.19.0 + go.opentelemetry.io/otel v0.20.0 + go.opentelemetry.io/otel/trace v0.20.0 google.golang.org/grpc v1.36.0 ) diff --git a/go.sum b/go.sum index 92c3c85..8300818 100644 --- a/go.sum +++ b/go.sum @@ -418,17 +418,17 @@ go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opentelemetry.io/otel v0.18.0/go.mod h1:PT5zQj4lTsR1YeARt8YNKcFb88/c2IKoSABK9mX0r78= -go.opentelemetry.io/otel v0.19.0 h1:Lenfy7QHRXPZVsw/12CWpxX6d/JkrX8wrx2vO8G80Ng= -go.opentelemetry.io/otel v0.19.0/go.mod h1:j9bF567N9EfomkSidSfmMwIwIBuP37AMAIzVW85OxSg= +go.opentelemetry.io/otel v0.20.0 h1:eaP0Fqu7SXHwvjiqDq83zImeehOHX8doTvU9AwXON8g= +go.opentelemetry.io/otel v0.20.0/go.mod h1:Y3ugLH2oa81t5QO+Lty+zXf8zC9L26ax4Nzoxm/dooo= go.opentelemetry.io/otel/metric v0.18.0/go.mod h1:kEH2QtzAyBy3xDVQfGZKIcok4ZZFvd5xyKPfPcuK6pE= -go.opentelemetry.io/otel/metric v0.19.0 h1:dtZ1Ju44gkJkYvo+3qGqVXmf88tc+a42edOywypengg= -go.opentelemetry.io/otel/metric v0.19.0/go.mod h1:8f9fglJPRnXuskQmKpnad31lcLJ2VmNNqIsx/uIwBSc= +go.opentelemetry.io/otel/metric v0.20.0 h1:4kzhXFP+btKm4jwxpjIqjs41A7MakRFUS86bqLHTIw8= +go.opentelemetry.io/otel/metric v0.20.0/go.mod h1:598I5tYlH1vzBjn+BTuhzTCSb/9debfNp6R3s7Pr1eU= go.opentelemetry.io/otel/oteltest v0.18.0/go.mod h1:NyierCU3/G8DLTva7KRzGii2fdxdR89zXKH1bNWY7Bo= -go.opentelemetry.io/otel/oteltest v0.19.0 h1:YVfA0ByROYqTwOxqHVZYZExzEpfZor+MU1rU+ip2v9Q= -go.opentelemetry.io/otel/oteltest v0.19.0/go.mod h1:tI4yxwh8U21v7JD6R3BcA/2+RBoTKFexE/PJ/nSO7IA= +go.opentelemetry.io/otel/oteltest v0.20.0 h1:HiITxCawalo5vQzdHfKeZurV8x7ljcqAgiWzF6Vaeaw= +go.opentelemetry.io/otel/oteltest v0.20.0/go.mod h1:L7bgKf9ZB7qCwT9Up7i9/pn0PWIa9FqQ2IQ8LoxiGnw= go.opentelemetry.io/otel/trace v0.18.0/go.mod h1:FzdUu3BPwZSZebfQ1vl5/tAa8LyMLXSJN57AXIt/iDk= -go.opentelemetry.io/otel/trace v0.19.0 h1:1ucYlenXIDA1OlHVLDZKX0ObXV5RLaq06DtUKz5e5zc= -go.opentelemetry.io/otel/trace v0.19.0/go.mod h1:4IXiNextNOpPnRlI4ryK69mn5iC84bjBWZQA5DXz/qg= +go.opentelemetry.io/otel/trace v0.20.0 h1:1DL6EXUdcg95gukhuRRvLDO/4X5THh/5dIV52lqtnbw= +go.opentelemetry.io/otel/trace v0.20.0/go.mod h1:6GjCW8zgDjwGHGa6GkyeB8+/5vjT16gUEi0Nf1iBdgw= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=