Skip to content

Commit

Permalink
Merge branch 'main' into chore/python-3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
sastels authored Nov 18, 2024
2 parents 17fa3b1 + 56da4f9 commit df8e808
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ RUN apt-get update \
2>&1 \
&& apt-get -y install \
curl \
dbus-x11 \
dnsutils \
emacs \
exa \
fd-find \
fzf \
git \
graphviz \
iproute2 \
iputils-ping \
kcachegrind \
less \
libsodium-dev \
lsb-release \
Expand All @@ -28,6 +32,8 @@ RUN apt-get update \
npm \
openssh-client \
procps \
pyprof2calltree \
ripgrep \
sudo \
tldr \
unzip \
Expand Down
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"eamodio.gitlens",
"fill-labs.dependi",
"GitHub.copilot",
"GitHub.copilot-labs",
"github.copilot-chat",
"github.vscode-pull-request-github",
"googlecloudtools.cloudcode",
"kaiwood.center-editor-window",
"matangover.mypy",
Expand Down
4 changes: 0 additions & 4 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ services:
volumes:
- ..:/workspace:cached
command: sleep infinity
ports:
- 8000:8000
- 8001:8001
- 6011:6011
links:
- db
expose:
Expand Down
4 changes: 4 additions & 0 deletions .devcontainer/scripts/notify-dev-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ echo -e "alias smoke-staging='cd /workspace && cp .env_smoke_staging tests_smoke
echo -e "alias smoke-prod='cd /workspace && cp .env_smoke_prod tests_smoke/.env && poetry run make smoke-test'" >> ~/.zshrc
echo -e "alias smoke-dev='cd /workspace && cp .env_smoke_dev tests_smoke/.env && poetry run make smoke-test'" >> ~/.zshrc

echo -e "# fzf key bindings and completion" >> ~/.zshrc
echo -e "source /usr/share/doc/fzf/examples/key-bindings.zsh" >> ~/.zshrc
echo -e "source /usr/share/doc/fzf/examples/completion.zsh" >> ~/.zshrc

cd /workspace

# Poetry autocomplete
Expand Down
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.env
*.env
tests*
44 changes: 40 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@
"configurations": [
{
"name": "Python: current file",
"type": "python",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "Python: Gunicorn",
"type": "debugpy",
"request": "launch",
"program": "gunicorn",
"gevent": true,
"args": ["--config", "gunicorn_config.py", "application"],
"env": {
"FLASK_APP": "application.py",
"FLASK_ENV": "development"
},
"justMyCode": false,
"console": "integratedTerminal"
},
{
"name": "Python: Flask",
"type": "python",
"type": "debugpy",
"request": "launch",
"module": "flask",
"env": {
Expand All @@ -28,7 +42,7 @@
},
{
"name": "Python: Celery",
"type": "python",
"type": "debugpy",
"request": "launch",
"module": "celery",
"console": "integratedTerminal",
Expand All @@ -48,7 +62,7 @@
},
{
"name": "Locust",
"type": "python",
"type": "debugpy",
"request": "launch",
"module": "locust",
"args": [
Expand All @@ -64,6 +78,28 @@
],
"gevent": true,
"console": "integratedTerminal"
},
{
"name": "Python: Current File with profiler",
"type": "debugpy",
"request": "launch",
"module": "cProfile",
"env": {
"FLASK_APP": "application.py",
"FLASK_ENV": "development"
},
"args": [
"-o",
"/tmp/tmp.prof",
"${file}",
"flask",
"run",
"--no-debugger",
"-p 6011",
"--host=0.0.0.0"
],
"jinja": true,
"justMyCode": false
}
]
}
2 changes: 1 addition & 1 deletion application.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@


def handler(event, context):
newrelic.agent.initialize() # noqa: E402
newrelic.agent.initialize(environment=app.config["NOTIFY_ENVIRONMENT"]) # noqa: E402
newrelic.agent.register_application(timeout=20.0)
return apig_wsgi_handler(event, context)
19 changes: 15 additions & 4 deletions gunicorn_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import gunicorn # type: ignore
import newrelic.agent # See https://bit.ly/2xBVKBH

newrelic.agent.initialize() # noqa: E402
newrelic.agent.initialize(environment=os.getenv("NOTIFY_ENVIRONMENT")) # noqa: E402

workers = 4
worker_class = "gevent"
Expand All @@ -25,15 +25,26 @@
keepalive = 75

# The default graceful timeout period for Kubernetes is 30 seconds, so
# want a lower graceful timeout value for gunicorn so that proper instance
# shutdowns.
# make sure that the timeouts defined here are less than the configured
# Kubernetes timeout. This ensures that the gunicorn worker will exit
# before the Kubernetes pod is terminated. This is important because
# Kubernetes will send a SIGKILL to the pod if it does not terminate
# within the grace period. If the worker is still processing requests
# when it receives the SIGKILL, it will be terminated abruptly and
# will not be able to finish processing the request. This can lead to
# 502 errors being returned to the client.
#
# Also, some libraries such as NewRelic might need some time to finish
# initialization before the worker can start processing requests. The
# timeout values should consider these factors.
#
# Gunicorn config:
# https://docs.gunicorn.org/en/stable/settings.html#graceful-timeout
#
# Kubernetes config:
# https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/
graceful_timeout = 20
graceful_timeout = 85
timeout = 90


def on_starting(server):
Expand Down
17 changes: 16 additions & 1 deletion newrelic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,27 @@ error_collector.ignore_errors = app.v2.errors:BadRequestError jsonschema.excepti
# specific environment will be used when the environment argument to the
# newrelic.agent.initialize() function has been defined to be either
# "development", "test", "staging" or "production".
#

# If this setting is enabled, it will capture package and version
# information on startup of the agent that is displayed in the APM
# environment tab.
# In applications that have a large number of packages, having this
# setting enabled may cause a CPU spike as it captures all the package
# and version information. It is recommended in those cases to disable
# this setting.
# Disabling this setting will disable the ability to detect vulnerabilities in outdated packages.
package_reporting.enabled = false

[newrelic:development]
# monitor_mode = false
log_level = debug
package_reporting.enabled = true

[newrelic:staging]
# app_name = Python Application (Staging)
# monitor_mode = true
log_level = debug
package_reporting.enabled = true

[newrelic:production]
# monitor_mode = true
Expand All @@ -205,5 +218,7 @@ error_collector.ignore_errors = app.v2.errors:BadRequestError jsonschema.excepti

[newrelic:dev]
# monitor_mode = false
log_level = debug
package_reporting.enabled = true

# ---------------------------------------------------------------------------
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ PyYAML = "6.0.1"

cachelib = "0.12.0"
SQLAlchemy = "1.4.52"
newrelic = "8.10.0"
newrelic = "9.2.0"
notifications-python-client = "6.4.1"
python-dotenv = "1.0.1"
pwnedpasswords = "2.0.0"
Expand Down Expand Up @@ -80,6 +80,7 @@ aws-xray-sdk = "2.14.0"

[tool.poetry.group.test.dependencies]
flake8 = "6.1.0"
gprof2dot = "2024.6.6"
isort = "5.13.2"
moto = "4.2.14"
idna = "2.10"
Expand All @@ -91,6 +92,7 @@ coveralls = "3.3.1"
pytest-xdist = "2.5.0"
freezegun = "1.5.1"
requests-mock = "1.12.1"
snakeviz = "2.2.0"
# optional requirements for jsonschema
strict-rfc3339 = "0.7"
rfc3987 = "1.3.8"
Expand Down

0 comments on commit df8e808

Please sign in to comment.