Skip to content

Commit 6fc5745

Browse files
authored
Merge pull request #6004 from opsmill/fac-merge-stable-in-release1.2
Merge stable into release-1.2
2 parents 3a08fd2 + 70197d8 commit 6fc5745

File tree

15 files changed

+1564
-2876
lines changed

15 files changed

+1564
-2876
lines changed

.github/workflows/update-compose-file-and-chart.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,7 @@ jobs:
8686
if: steps.release.outputs.is_prerelease == 0 && steps.release.outputs.is_devrelease == 0
8787
working-directory: helm
8888
run: |
89+
git config --global user.name "opsmill-bot"
90+
git config --global user.email "[email protected]"
8991
git commit -a -m 'chore: bump appVersion'
9092
git push

backend/infrahub/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,12 @@ class DatabaseSettings(BaseSettings):
249249
retry_limit: int = Field(
250250
default=3, description="Maximum number of times a transient issue in a transaction should be retried."
251251
)
252+
max_concurrent_queries: int = Field(
253+
default=0, ge=0, description="Maximum number of concurrent queries that can run (0 means unlimited)."
254+
)
255+
max_concurrent_queries_delay: float = Field(
256+
default=0.01, ge=0, description="Delay to add when max_concurrent_queries is reached."
257+
)
252258

253259
@property
254260
def database_name(self) -> str:

backend/infrahub/database/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
from .constants import DatabaseType, Neo4jRuntime
3636
from .memgraph import DatabaseManagerMemgraph
37-
from .metrics import QUERY_EXECUTION_METRICS, TRANSACTION_RETRIES
37+
from .metrics import CONNECTION_POOL_USAGE, QUERY_EXECUTION_METRICS, TRANSACTION_RETRIES
3838
from .neo4j import DatabaseManagerNeo4j
3939

4040
if TYPE_CHECKING:
@@ -331,6 +331,14 @@ async def execute_query_with_metadata(
331331
context: dict[str, str] | None = None,
332332
type: QueryType | None = None,
333333
) -> tuple[list[Record], dict[str, Any]]:
334+
connpool_usage = self._driver._pool.in_use_connection_count(self._driver._pool.address)
335+
CONNECTION_POOL_USAGE.labels(self._driver._pool.address).set(float(connpool_usage))
336+
337+
if config.SETTINGS.database.max_concurrent_queries:
338+
while connpool_usage > config.SETTINGS.database.max_concurrent_queries: # noqa: ASYNC110
339+
await asyncio.sleep(config.SETTINGS.database.max_concurrent_queries_delay)
340+
connpool_usage = self._driver._pool.in_use_connection_count(self._driver._pool.address)
341+
334342
with trace.get_tracer(__name__).start_as_current_span("execute_db_query_with_metadata") as span:
335343
span.set_attribute("query", query)
336344
if name:

backend/infrahub/database/metrics.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from prometheus_client import Counter, Histogram
3+
from prometheus_client import Counter, Gauge, Histogram
44

55
METRIC_PREFIX = "infrahub_db"
66

@@ -16,3 +16,9 @@
1616
"Number of transaction that have been retried due to transcient error",
1717
labelnames=["name"],
1818
)
19+
20+
CONNECTION_POOL_USAGE = Gauge(
21+
f"{METRIC_PREFIX}_last_connection_pool_usage",
22+
"Number of last known active connections in the pool",
23+
labelnames=["address"],
24+
)

development/Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ RUN mkdir /prom_shared /remote
1515

1616
RUN apt-get update && \
1717
apt-get upgrade -y && \
18-
apt-get install --no-install-recommends -y tini curl git pkg-config build-essential ca-certificates && \
18+
apt-get install --no-install-recommends -y tini curl git pkg-config build-essential ca-certificates gnupg2 && \
19+
install -m 0755 -d /etc/apt/keyrings && \
20+
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
21+
chmod a+r /etc/apt/keyrings/docker.gpg && \
22+
echo "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
23+
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
24+
tee /etc/apt/sources.list.d/docker.list > /dev/null && \
25+
apt-get update && \
26+
apt-get install --no-install-recommends -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin && \
1927
curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.8.5 python3 - && \
2028
apt-get autoremove -y && \
2129
apt-get clean all && \

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ x-infrahub-config: &infrahub_config
5050
INFRAHUB_CONFIG:
5151
INFRAHUB_DB_ADDRESS: ${INFRAHUB_DB_ADDRESS:-localhost}
5252
INFRAHUB_DB_DATABASE:
53+
INFRAHUB_DB_MAX_CONCURRENT_QUERIES: ${INFRAHUB_DB_MAX_CONCURRENT_QUERIES:-0}
54+
INFRAHUB_DB_MAX_CONCURRENT_QUERIES_DELAY: ${INFRAHUB_DB_MAX_CONCURRENT_QUERIES_DELAY:-0.01}
5355
INFRAHUB_DB_MAX_DEPTH_SEARCH_HIERARCHY: ${INFRAHUB_DB_MAX_DEPTH_SEARCH_HIERARCHY:-5}
5456
INFRAHUB_DB_PASSWORD: ${INFRAHUB_DB_PASSWORD:-admin}
5557
INFRAHUB_DB_PORT: ${INFRAHUB_DB_PORT:-7687}

0 commit comments

Comments
 (0)