diff --git a/CHANGES/5762.feature b/CHANGES/5762.feature new file mode 100644 index 0000000000..bfa3291289 --- /dev/null +++ b/CHANGES/5762.feature @@ -0,0 +1,2 @@ +Re-enable the Domain Storage metric emmiter and adds a feature flag to it. +This is an experimental feature and can change without prior notice. diff --git a/pulpcore/app/models/domain.py b/pulpcore/app/models/domain.py index 9098222d0d..748ca39672 100644 --- a/pulpcore/app/models/domain.py +++ b/pulpcore/app/models/domain.py @@ -2,7 +2,7 @@ from django.core.files.storage import default_storage from django.db import models -from django_lifecycle import hook, BEFORE_DELETE, BEFORE_UPDATE +from django_lifecycle import hook, BEFORE_DELETE, BEFORE_UPDATE, AFTER_CREATE from pulpcore.app.models import BaseModel, AutoAddObjPermsMixin from pulpcore.exceptions import DomainProtectedError @@ -74,13 +74,11 @@ def _cleanup_orphans_pre_delete(self): # Delete on by one to properly cleanup the storage. artifact.delete() - # Disabling Storage metrics until we find a solution to resource usage. - # https://github.com/pulp/pulpcore/issues/5468 - # @hook(AFTER_CREATE) - # def _report_domain_disk_usage(self): - # from pulpcore.app.util import DomainMetricsEmitterBuilder - # - # DomainMetricsEmitterBuilder.build(self) + @hook(AFTER_CREATE) + def _report_domain_disk_usage(self): + from pulpcore.app.util import DomainMetricsEmitterBuilder + + DomainMetricsEmitterBuilder.build(self) class Meta: permissions = [ diff --git a/pulpcore/app/util.py b/pulpcore/app/util.py index b332ce3014..2192349312 100644 --- a/pulpcore/app/util.py +++ b/pulpcore/app/util.py @@ -580,10 +580,15 @@ def build(cls, domain): def init_domain_metrics_exporter(): - from pulpcore.app.models.domain import Domain + PULP_OTEL_SPACE_USAGE_TELEMETRY = ( + os.getenv("PULP_OTEL_SPACE_USAGE_TELEMETRY", "").lower() == "true" + ) - for domain in Domain.objects.all(): - DomainMetricsEmitterBuilder.build(domain) + if PULP_OTEL_SPACE_USAGE_TELEMETRY: + from pulpcore.app.models.domain import Domain + + for domain in Domain.objects.all(): + DomainMetricsEmitterBuilder.build(domain) class PGAdvisoryLock: diff --git a/pulpcore/app/wsgi.py b/pulpcore/app/wsgi.py index 5287224e8a..367604dce9 100644 --- a/pulpcore/app/wsgi.py +++ b/pulpcore/app/wsgi.py @@ -18,8 +18,6 @@ application = get_wsgi_application() application = OpenTelemetryMiddleware(application) -# Disabling Storage metrics until we find a solution to resource usage. -# https://github.com/pulp/pulpcore/issues/5468 -# from pulpcore.app.util import init_domain_metrics_exporter # noqa: E402 +from pulpcore.app.util import init_domain_metrics_exporter # noqa: E402 -# init_domain_metrics_exporter() +init_domain_metrics_exporter()