From 2545bf8336b681af2d7e162bcb34a4a87d8d0cf4 Mon Sep 17 00:00:00 2001 From: Michael Derynck Date: Tue, 8 Oct 2024 11:29:36 -0600 Subject: [PATCH] Split up organizations across metrics exporters (#5127) # What this PR does Limits organizations that a metrics exporter is responsible for. As more organizations are added it becomes more difficult for the exporter to deliver metrics within the scrape timeout. This would let us use the settings to divide up the organizations between multiple exporters. ## Which issue(s) this PR closes Related to [issue link here] ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] Added the relevant release notes label (see labels prefixed w/ `release:`). These labels dictate how your PR will show up in the autogenerated release notes. --- engine/apps/metrics_exporter/helpers.py | 6 +++++- engine/settings/base.py | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/engine/apps/metrics_exporter/helpers.py b/engine/apps/metrics_exporter/helpers.py index db1164bcb7..91a0190520 100644 --- a/engine/apps/metrics_exporter/helpers.py +++ b/engine/apps/metrics_exporter/helpers.py @@ -2,6 +2,7 @@ import random import typing +from django.conf import settings from django.core.cache import cache from django.utils import timezone @@ -50,7 +51,10 @@ def get_organization_ids(): if not organizations_ids: organizations_ids = get_organization_ids_from_db() cache.set(organizations_ids, METRICS_ORGANIZATIONS_IDS, METRICS_ORGANIZATIONS_IDS_CACHE_TIMEOUT) - return organizations_ids + + group_id = settings.METRICS_EXPORTER_ORGANIZATION_GROUP_ID + group_count = settings.METRICS_EXPORTER_TOTAL_ORGANIZATION_GROUPS + return [i for i in organizations_ids if i % group_count == group_id] def is_allowed_to_start_metrics_calculation(organization_id, force=False) -> bool: diff --git a/engine/settings/base.py b/engine/settings/base.py index 88530f1b22..ae5f8716b2 100644 --- a/engine/settings/base.py +++ b/engine/settings/base.py @@ -121,6 +121,11 @@ # List of metrics to collect. Collect all available application metrics by default METRICS_TO_COLLECT = getenv_list("METRICS_TO_COLLECT", METRICS_ALL) +# Total number of exporters collecting the same set of metrics +METRICS_EXPORTER_TOTAL_ORGANIZATION_GROUPS = getenv_integer("METRICS_EXPORTER_TOTAL_ORGANIZATION_GROUPS", 1) +# ID of this exporter, used to filter which orgs to collect for +METRICS_EXPORTER_ORGANIZATION_GROUP_ID = getenv_integer("METRICS_EXPORTER_ORGANIZATION_GROUP_ID", 0) + # Database class DatabaseTypes: