Skip to content

Commit 2545bf8

Browse files
authored
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] <!-- *Note*: If you want the issue to be auto-closed once the PR is merged, change "Related to" to "Closes" in the line above. If you have more than one GitHub issue that this PR closes, be sure to preface each issue link with a [closing keyword](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests#linking-a-pull-request-to-an-issue). This ensures that the issue(s) are auto-closed once the PR has been merged. --> ## 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.
1 parent de47684 commit 2545bf8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

engine/apps/metrics_exporter/helpers.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import random
33
import typing
44

5+
from django.conf import settings
56
from django.core.cache import cache
67
from django.utils import timezone
78

@@ -50,7 +51,10 @@ def get_organization_ids():
5051
if not organizations_ids:
5152
organizations_ids = get_organization_ids_from_db()
5253
cache.set(organizations_ids, METRICS_ORGANIZATIONS_IDS, METRICS_ORGANIZATIONS_IDS_CACHE_TIMEOUT)
53-
return organizations_ids
54+
55+
group_id = settings.METRICS_EXPORTER_ORGANIZATION_GROUP_ID
56+
group_count = settings.METRICS_EXPORTER_TOTAL_ORGANIZATION_GROUPS
57+
return [i for i in organizations_ids if i % group_count == group_id]
5458

5559

5660
def is_allowed_to_start_metrics_calculation(organization_id, force=False) -> bool:

engine/settings/base.py

+5
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@
121121
# List of metrics to collect. Collect all available application metrics by default
122122
METRICS_TO_COLLECT = getenv_list("METRICS_TO_COLLECT", METRICS_ALL)
123123

124+
# Total number of exporters collecting the same set of metrics
125+
METRICS_EXPORTER_TOTAL_ORGANIZATION_GROUPS = getenv_integer("METRICS_EXPORTER_TOTAL_ORGANIZATION_GROUPS", 1)
126+
# ID of this exporter, used to filter which orgs to collect for
127+
METRICS_EXPORTER_ORGANIZATION_GROUP_ID = getenv_integer("METRICS_EXPORTER_ORGANIZATION_GROUP_ID", 0)
128+
124129

125130
# Database
126131
class DatabaseTypes:

0 commit comments

Comments
 (0)