-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from hellofresh/feature-rabbit-aliveness-check
RabbitMQ aliveness test example
- Loading branch information
Showing
4 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -42,7 +42,7 @@ func main() { | |
Timeout: time.Second * 5, | ||
SkipOnErr: true, | ||
Check: healthPg.New(healthPg.Config{ | ||
DSN: `postgres://test:[email protected]:32807/test?sslmode=disable`, | ||
DSN: `postgres://test:[email protected]:32783/test?sslmode=disable`, | ||
}), | ||
}) | ||
|
||
|
@@ -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:[email protected]:32780/api/aliveness-test/%2f`, | ||
}), | ||
}) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters