Skip to content

Commit

Permalink
Add settings to split up organizations across exporters
Browse files Browse the repository at this point in the history
  • Loading branch information
mderynck committed Oct 4, 2024
1 parent ac7dc97 commit a389c74
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion engine/apps/metrics_exporter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import random
import typing

from django.conf import settings
from django.core.cache import cache
from django.utils import timezone

Expand Down Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions engine/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,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:
Expand Down

0 comments on commit a389c74

Please sign in to comment.