Skip to content

Commit a5d5f50

Browse files
authored
Merge branch 'master' into ops/disable_connection_pool
Signed-off-by: Florian <floriansw@t-online.de>
2 parents a63c1b1 + eb9d8b5 commit a5d5f50

File tree

7 files changed

+45
-15
lines changed

7 files changed

+45
-15
lines changed

docker-compose-common-components.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ services:
1717
- common
1818
postgres:
1919
image: ${POSTGRES_IMAGE}
20+
# Increases the default 100 to 300
21+
command: postgres -c max_connections=300
2022
environment:
2123
# If a password is not defined this container will fail to create
2224
POSTGRES_PASSWORD: ${HLL_DB_PASSWORD}

rcon/models.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import logging
22
import os
33
import re
4+
import sys
45
from collections import defaultdict
56
from contextlib import contextmanager
67
from datetime import datetime, timezone
7-
from typing import Any, Generator, List, Literal, Optional, Sequence, overload, TypedDict
8+
from typing import Any, Generator, List, Literal, Optional, Sequence, overload
89

910
import pydantic
1011
from sqlalchemy import TIMESTAMP, Enum, ForeignKey, String, create_engine, select, text, JSON, Engine, NullPool, Pool
@@ -73,6 +74,30 @@
7374
_ENGINE: Engine | None = None
7475

7576

77+
def _connection_name() -> str:
78+
"""
79+
Identify what application component is using the SQLAlchemy session. This can be helpful when inspecting the connections
80+
in Postgres to identify the purpose of a connection. The connection name will be used as the application_name connection
81+
property and show up in the pg_stat_activity table:
82+
select * from pg_stat_activity;
83+
84+
:return: str
85+
"""
86+
args = sys.argv
87+
name = 'CRCon Generic'
88+
if "manage.py" not in args[0]:
89+
# stuff like daphne, gunicorn (backend) etc
90+
name = args[0]
91+
elif len(args) > 1 and args[1] != "":
92+
# Take whatever argument we passed to manage.py (for Supervisor services, such as log_loop, etc)
93+
name = args[1]
94+
95+
name = (os.getenv("SERVER_NUMBER") or "") + name
96+
# in the standard build (which we use in teh default docker setup) the name cannot exceed 63 chars (less than 64),
97+
# see https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-APPLICATION-NAME
98+
return name[:63]
99+
100+
76101
def get_engine():
77102
global _ENGINE
78103

@@ -88,7 +113,7 @@ def get_engine():
88113
if os.getenv("HLL_DB_DISABLE_CONNECTION_POOL") is not None:
89114
pool = NullPool
90115

91-
_ENGINE = create_engine(url, poolclass=pool, echo=False)
116+
_ENGINE = create_engine(url, poolclass=pool, echo=False, connect_args={"application_name":_connection_name()})
92117
return _ENGINE
93118

94119

rcongui/package-lock.json

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

rcongui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"@vitejs/plugin-react": "^4.5.2",
8282
"miragejs": "^0.1.48",
8383
"prettier": "^2.8.8",
84-
"vite": "^6.4.1"
84+
"vite": "^6.4.2"
8585
},
8686
"browserslist": {
8787
"production": [

rcongui_public/package-lock.json

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

rcongui_public/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
"tailwindcss": "3.4.16",
119119
"ts-node": "^10.9.2",
120120
"typescript": "^5.7.2",
121-
"vite": "^6.4.1",
121+
"vite": "^6.4.2",
122122
"vite-plugin-external": "^4.3.1",
123123
"vite-plugin-svgr": "^4.3.0"
124124
}

rconweb/rconweb/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@
253253
"HOST": db_info["HOST"],
254254
"PORT": db_info["PORT"],
255255
"NAME": db_info["NAME"],
256+
"OPTIONS": {
257+
"application_name": (os.getenv("SERVER_NUMBER") or "") + "Django",
258+
}
256259
}
257260
}
258261

0 commit comments

Comments
 (0)