Skip to content

Commit d4b5d6a

Browse files
authored
feat: TCP health check integration + ECS health checks on staging (#5377)
----- Co-authored-by: Rodrigo López Dato <rodrigo.lopezdato@flagsmith.com> deps: bump flagsmith-common from 1.10.0 to 1.11.0
1 parent 65bfa27 commit d4b5d6a

9 files changed

Lines changed: 61 additions & 44 deletions

File tree

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ FROM wolfi-base AS api-runtime
119119

120120
# Install Python and make it available to venv entrypoints
121121
ARG PYTHON_VERSION
122-
RUN apk add curl python-${PYTHON_VERSION} && \
122+
RUN apk add python-${PYTHON_VERSION} && \
123123
mkdir /build/ && ln -s /usr/local/ /build/.venv
124124

125125
WORKDIR /app
@@ -140,7 +140,7 @@ ENTRYPOINT ["/app/scripts/run-docker.sh"]
140140
CMD ["migrate-and-serve"]
141141

142142
HEALTHCHECK --interval=2s --timeout=2s --retries=3 --start-period=20s \
143-
CMD curl -f http://localhost:8000/health/liveness || exit 1
143+
CMD flagsmith healthcheck tcp
144144

145145
# * api-runtime-private [api-runtime]
146146
FROM api-runtime AS api-runtime-private

api/manage.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
#!/usr/bin/env python
22
import os
3-
import sys
43

54
from common.core.main import main
65

76
if __name__ == "__main__":
8-
# Backwards compatibility for task-processor health checks
9-
# See https://github.com/Flagsmith/flagsmith-task-processor/issues/24
10-
if "checktaskprocessorthreadhealth" in sys.argv:
11-
import scripts.healthcheck
12-
13-
scripts.healthcheck.main()
14-
157
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings.local")
168

179
main()

api/poetry.lock

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pygithub = "2.1.1"
154154
hubspot-api-client = "^8.2.1"
155155
djangorestframework-dataclasses = "^1.3.1"
156156
pyotp = "^2.9.0"
157-
flagsmith-common = "^1.10.0"
157+
flagsmith-common = "^1.11.0"
158158
django-stubs = "^5.1.3"
159159
tzdata = "^2024.1"
160160
djangorestframework-simplejwt = "^5.3.1"

api/scripts/__init__.py

Whitespace-only changes.

api/scripts/healthcheck.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
11
import logging
22
import sys
33

4-
import requests
5-
6-
HEALTH_LIVENESS_URL = "http://localhost:8000/health/liveness"
7-
8-
9-
logger = logging.getLogger(__name__)
10-
11-
12-
def main() -> None:
13-
logger.warning(
14-
f"This healthcheck, invoked by {' '.join(sys.argv)}, is deprecated. "
15-
f"Use the `{HEALTH_LIVENESS_URL}` endpoint instead."
16-
)
17-
status_code = requests.get(HEALTH_LIVENESS_URL).status_code
18-
19-
if status_code != 200:
20-
logger.error(f"Health check failed with status {status_code}")
21-
22-
sys.exit(0 if 200 >= status_code < 300 else 1)
23-
4+
from common.core.main import main
245

256
if __name__ == "__main__":
26-
main()
7+
logging.getLogger(__name__).warning(
8+
f"This healthcheck, invoked by `{' '.join(sys.argv)}``, is deprecated. "
9+
"Please use one of the `flagsmith healthcheck` commands instead."
10+
)
11+
main(["flagsmith", "healthcheck", "http"])

infrastructure/aws/production/ecs-task-definition-task-processor.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"containerDefinitions": [
77
{
88
"name": "flagsmith-task-processor",
9-
"command": ["run-task-processor"],
9+
"command": [
10+
"run-task-processor"
11+
],
1012
"essential": true,
1113
"environment": [
1214
{
@@ -21,6 +23,10 @@
2123
"name": "AWS_DEFAULT_REGION",
2224
"value": "eu-west-2"
2325
},
26+
{
27+
"name": "DJANGO_ALLOWED_HOSTS",
28+
"value": "*"
29+
},
2430
{
2531
"name": "DJANGO_SETTINGS_MODULE",
2632
"value": "app.settings.production"
@@ -255,4 +261,4 @@
255261
],
256262
"cpu": "1024",
257263
"memory": "2048"
258-
}
264+
}

infrastructure/aws/staging/ecs-task-definition-task-processor.json

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,26 @@
66
"containerDefinitions": [
77
{
88
"name": "flagsmith-task-processor",
9-
"command": ["run-task-processor"],
9+
"command": [
10+
"run-task-processor"
11+
],
12+
"portMappings": [
13+
{
14+
"containerPort": 8000,
15+
"hostPort": 8000,
16+
"protocol": "tcp"
17+
}
18+
],
19+
"healthCheck": {
20+
"command": [
21+
"CMD-SHELL",
22+
"flagsmith healthcheck tcp"
23+
],
24+
"interval": 10,
25+
"timeout": 2,
26+
"retries": 5,
27+
"startPeriod": 5
28+
},
1029
"essential": true,
1130
"environment": [
1231
{
@@ -21,6 +40,10 @@
2140
"name": "AWS_DEFAULT_REGION",
2241
"value": "eu-west-2"
2342
},
43+
{
44+
"name": "DJANGO_ALLOWED_HOSTS",
45+
"value": "*"
46+
},
2447
{
2548
"name": "DJANGO_SETTINGS_MODULE",
2649
"value": "app.settings.production"

infrastructure/aws/staging/ecs-task-definition-web.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
"protocol": "tcp"
1818
}
1919
],
20+
"healthCheck": {
21+
"command": [
22+
"CMD-SHELL",
23+
"flagsmith healthcheck tcp"
24+
],
25+
"interval": 10,
26+
"timeout": 2,
27+
"retries": 5,
28+
"startPeriod": 5
29+
},
2030
"essential": true,
2131
"environment": [
2232
{

0 commit comments

Comments
 (0)