From a9629654c94cffb22adaa9dc43edf1dce624caaa Mon Sep 17 00:00:00 2001 From: Gabriel Omar Cotelli Date: Thu, 17 Feb 2022 18:04:00 -0300 Subject: [PATCH 1/5] Improve test to check the health status received --- compose-test.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compose-test.sh b/compose-test.sh index bb60adc..0decf0d 100755 --- a/compose-test.sh +++ b/compose-test.sh @@ -11,5 +11,10 @@ docker-compose -f api-tests/docker-compose.yml up -d sleep 10 curl --fail http://localhost:8080/echo/hello curl --fail http://localhost:8500/v1/agent/services -curl --fail http://localhost:8500/v1/health/checks/echo +HEALTH_STATUS=$(curl -s fail http://localhost:8500/v1/health/checks/echo | jq '.[0].Status') +if [ "$HEALTH_STATUS" != "passing" ]; then + echo "Echo service is unhealthy" + docker-compose -f api-tests/docker-compose.yml down + exit 1 +fi docker-compose -f api-tests/docker-compose.yml down From a6f218b2040108bd2deb91f5e49c6bea3d49d902 Mon Sep 17 00:00:00 2001 From: Gabriel Omar Cotelli Date: Thu, 17 Feb 2022 18:16:26 -0300 Subject: [PATCH 2/5] Improve script --- compose-test.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compose-test.sh b/compose-test.sh index 0decf0d..7e5eb13 100755 --- a/compose-test.sh +++ b/compose-test.sh @@ -11,9 +11,10 @@ docker-compose -f api-tests/docker-compose.yml up -d sleep 10 curl --fail http://localhost:8080/echo/hello curl --fail http://localhost:8500/v1/agent/services -HEALTH_STATUS=$(curl -s fail http://localhost:8500/v1/health/checks/echo | jq '.[0].Status') +curl --fail http://localhost:8500/v1/health/checks/echo +HEALTH_STATUS=$(curl -s http://localhost:8500/v1/health/checks/echo | jq '.[0].Status') if [ "$HEALTH_STATUS" != "passing" ]; then - echo "Echo service is unhealthy" + echo "ERROR: Echo service is unhealthy" docker-compose -f api-tests/docker-compose.yml down exit 1 fi From 8eaa7301cd2e1e511cbbec87b246a29eb90e0819 Mon Sep 17 00:00:00 2001 From: Gabriel Omar Cotelli Date: Thu, 17 Feb 2022 18:48:15 -0300 Subject: [PATCH 3/5] Fix healthCheckEndpoint when using docker containers to not miss the scheme in the URL --- .../ConsulAwareStargateApplication.class.st | 20 +++++++++++++------ ...onsulAwareStargateApplication.extension.st | 11 ---------- 2 files changed, 14 insertions(+), 17 deletions(-) delete mode 100644 source/Stargate-Consul/ConsulAwareStargateApplication.extension.st diff --git a/source/Stargate-Consul/ConsulAwareStargateApplication.class.st b/source/Stargate-Consul/ConsulAwareStargateApplication.class.st index 10fa31e..3631c23 100644 --- a/source/Stargate-Consul/ConsulAwareStargateApplication.class.st +++ b/source/Stargate-Consul/ConsulAwareStargateApplication.class.st @@ -10,14 +10,21 @@ ConsulAwareStargateApplication class >> isAbstract [ ^ self = ConsulAwareStargateApplication ] -{ #category : #'*Stargate-Consul' } +{ #category : #private } ConsulAwareStargateApplication class >> stargateConfigurationParameters [ - ^ super stargateConfigurationParameters , { MandatoryConfigurationParameter - named: 'Consul Agent Location' - describedBy: 'Location of the Consul Agent. Leave empty to disable the plugin' - inside: self sectionsForStargateConfiguration - convertingWith: #asUrl } + ^ super stargateConfigurationParameters , { + (MandatoryConfigurationParameter + named: 'Consul Agent Location' + describedBy: + 'Location of the Consul Agent. Leave empty to disable the plugin' + inside: self sectionsForStargateConfiguration + convertingWith: #asUrl). + (OptionalConfigurationParameter + named: 'Scheme' + describedBy: 'Transport scheme. It''s used to configure Consul HTTP checks' + inside: self sectionsForStargateConfiguration + defaultingTo: 'http') } ] { #category : #'private - building' } @@ -91,6 +98,7 @@ ConsulAwareStargateApplication >> healthCheckEndpoint [ baseUrl := self withDockerHostnameDo: [ :hostname | ZnUrl new + scheme: self stargateConfiguration scheme; host: hostname; port: self stargateConfiguration port; yourself diff --git a/source/Stargate-Consul/ConsulAwareStargateApplication.extension.st b/source/Stargate-Consul/ConsulAwareStargateApplication.extension.st deleted file mode 100644 index a0de8db..0000000 --- a/source/Stargate-Consul/ConsulAwareStargateApplication.extension.st +++ /dev/null @@ -1,11 +0,0 @@ -Extension { #name : #ConsulAwareStargateApplication } - -{ #category : #'*Stargate-Consul' } -ConsulAwareStargateApplication class >> stargateConfigurationParameters [ - - ^ super stargateConfigurationParameters , { MandatoryConfigurationParameter - named: 'Consul Agent Location' - describedBy: 'Location of the Consul Agent. Leave empty to disable the plugin' - inside: self sectionsForStargateConfiguration - convertingWith: #asUrl } -] From 4b17263555b222cd28332f5f8cb8a67cc3d462fd Mon Sep 17 00:00:00 2001 From: Gabriel Omar Cotelli Date: Thu, 17 Feb 2022 18:56:28 -0300 Subject: [PATCH 4/5] Fix test --- .../StargateConsulExampleTest.class.st | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/Stargate-Consul-Examples-Tests/StargateConsulExampleTest.class.st b/source/Stargate-Consul-Examples-Tests/StargateConsulExampleTest.class.st index 67b5218..1cbb8e8 100644 --- a/source/Stargate-Consul-Examples-Tests/StargateConsulExampleTest.class.st +++ b/source/Stargate-Consul-Examples-Tests/StargateConsulExampleTest.class.st @@ -79,7 +79,7 @@ StargateConsulExampleTest >> testPrintHelpOn [ self assert: help equals: ( 'NAME stargate-consul-example [<1s>] - I provide a RESTful API over HTTP SYNOPSYS - stargate-consul-example --stargate.public-url=% --stargate.port=% --stargate.operations-secret=% --stargate.consul-agent-location=% + stargate-consul-example --stargate.public-url=% --stargate.port=% --stargate.operations-secret=% --stargate.consul-agent-location=% [--stargate.scheme=%] PARAMETERS --stargate.public-url=% Public URL where the API is deployed. Used to create hypermedia links. @@ -89,6 +89,8 @@ PARAMETERS Secret key for checking JWT signatures. --stargate.consul-agent-location=% Location of the Consul Agent. Leave empty to disable the plugin. + --stargate.scheme=% + Transport scheme. It''s used to configure Consul HTTP checks. Defaults to http. ENVIRONMENT STARGATE__PUBLIC_URL Public URL where the API is deployed. Used to create hypermedia links. @@ -98,6 +100,8 @@ ENVIRONMENT Secret key for checking JWT signatures. STARGATE__CONSUL_AGENT_LOCATION Location of the Consul Agent. Leave empty to disable the plugin. + STARGATE__SCHEME + Transport scheme. It''s used to configure Consul HTTP checks. Defaults to http. ' expandMacrosWith: StargateConsulExample version ) ] From b107bdf20231288edeed6902014e862cbf87e871 Mon Sep 17 00:00:00 2001 From: Gabriel Omar Cotelli Date: Fri, 18 Feb 2022 08:25:10 -0300 Subject: [PATCH 5/5] Improve compose test script --- compose-test.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/compose-test.sh b/compose-test.sh index 7e5eb13..d64a833 100755 --- a/compose-test.sh +++ b/compose-test.sh @@ -7,14 +7,22 @@ if [[ -z "${GITHUB_HEAD_REF##*/}" ]]; then else echo "BRANCH_NAME=${GITHUB_HEAD_REF##*/}" > .env fi -docker-compose -f api-tests/docker-compose.yml up -d +echo "Building API" +docker-compose -f api-tests/docker-compose.yml build api +echo "Starting Consul Agent" +docker-compose -f api-tests/docker-compose.yml up -d consul-agent +sleep 1 +echo "Starting API" +docker-compose -f api-tests/docker-compose.yml up -d api sleep 10 +echo "Testing API" curl --fail http://localhost:8080/echo/hello curl --fail http://localhost:8500/v1/agent/services curl --fail http://localhost:8500/v1/health/checks/echo HEALTH_STATUS=$(curl -s http://localhost:8500/v1/health/checks/echo | jq '.[0].Status') -if [ "$HEALTH_STATUS" != "passing" ]; then - echo "ERROR: Echo service is unhealthy" +echo "$HEALTH_STATUS" +if [ "$HEALTH_STATUS" != '"passing"' ]; then + echo "Error: Echo service is unhealthy" >&2 docker-compose -f api-tests/docker-compose.yml down exit 1 fi