Skip to content

Commit

Permalink
Merge pull request #20 from hellofresh/feature-rabbit-aliveness-check
Browse files Browse the repository at this point in the history
RabbitMQ aliveness test example
  • Loading branch information
aleksandrzhiliaev committed Jul 27, 2018
2 parents 456ffac + 9d0ae38 commit e3aa755
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test:
@sleep 3 && \
HEALTH_GO_PG_DSN="postgres://test:test@`docker-compose port postgres 5432`/test?sslmode=disable" \
HEALTH_GO_MQ_DSN="amqp://guest:guest@`docker-compose port rabbit 5672`/" \
HEALTH_GO_MQ_URL="http://guest:guest@`docker-compose port rabbit 15672`/" \
HEALTH_GO_RD_DSN="redis://`docker-compose port redis 6379`/" \
HEALTH_GO_MG_DSN="`docker-compose port mongo 27017`/" \
HEALTH_GO_MS_DSN="test:test@tcp(`docker-compose port mysql 3306`)/test?charset=utf8" \
Expand Down
19 changes: 16 additions & 3 deletions _examples/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
Name: "some-custom-check-fail",
Timeout: time.Second * 5,
SkipOnErr: true,
Check: func() error { return errors.New("failed during rabbitmq health check") },
Check: func() error { return errors.New("failed during custom health check") },
})

// custom health check example (success)
Expand All @@ -42,7 +42,7 @@ func main() {
Timeout: time.Second * 5,
SkipOnErr: true,
Check: healthPg.New(healthPg.Config{
DSN: `postgres://test:test@0.0.0.0:32807/test?sslmode=disable`,
DSN: `postgres://test:test@0.0.0.0:32783/test?sslmode=disable`,
}),
})

Expand All @@ -52,7 +52,20 @@ func main() {
Timeout: time.Second * 5,
SkipOnErr: true,
Check: healthMySql.New(healthMySql.Config{
DSN: `test:test@tcp(0.0.0.0:32802)/test?charset=utf8`,
DSN: `test:test@tcp(0.0.0.0:32778)/test?charset=utf8`,
}),
})

// rabbitmq aliveness test example.
// Use it if your app has access to RabbitMQ management API.
// This endpoint declares a test queue, then publishes and consumes a message. Intended for use by monitoring tools. If everything is working correctly, will return HTTP status 200.
// As the default virtual host is called "/", this will need to be encoded as "%2f".
health.Register(health.Config{
Name: "rabbit-aliveness-check",
Timeout: time.Second * 5,
SkipOnErr: true,
Check: healthHttp.New(healthHttp.Config{
URL: `http://guest:guest@0.0.0.0:32780/api/aliveness-test/%2f`,
}),
})

Expand Down
24 changes: 24 additions & 0 deletions checks/rabbitmq/aliveness_check_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package rabbitmq

import (
"os"
"testing"

"github.com/hellofresh/health-go/checks/http"
)

const httpURLEnv = "HEALTH_GO_MQ_URL"

func TestAliveness(t *testing.T) {
if os.Getenv(httpURLEnv) == "" {
t.SkipNow()
}

check := http.New(http.Config{
URL: os.Getenv(httpURLEnv),
})

if err := check(); err != nil {
t.Fatalf("HTTP check failed: %s", err.Error())
}
}
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
image: rabbitmq:3.6-management-alpine
ports:
- "5672"
- "15672"

redis:
image: redis:3.2-alpine
Expand Down

0 comments on commit e3aa755

Please sign in to comment.