-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-enable Storage Metrics emitter and refactor it
This refactors the code used to retrieve the space utilized by domain's artifacts and emit a `pulp_space_usage` metric value using OpenTelemetry SDK. Closes #5762
- Loading branch information
Showing
6 changed files
with
56 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Re-enabled and refactored the Domain Storage metric emitter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from django.db.models import Sum | ||
|
||
from pulpcore.app.models import Artifact | ||
|
||
from opentelemetry.sdk.metrics import MeterProvider | ||
|
||
from opentelemetry.exporter.otlp.proto.http.metric_exporter import OTLPMetricExporter | ||
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader | ||
from opentelemetry.sdk.resources import Resource | ||
|
||
# This configuration is needed since the worker thread is not using the opentelemetry | ||
# instrumentation agent to run the task code. | ||
|
||
exporter = OTLPMetricExporter() | ||
|
||
resource = Resource(attributes={"service.name": "pulp-worker"}) | ||
|
||
metric_reader = PeriodicExportingMetricReader(exporter) | ||
provider = MeterProvider(metric_readers=[metric_reader], resource=resource) | ||
|
||
|
||
def otel_metrics(): | ||
|
||
meter = provider.get_meter(__name__) | ||
space_usage_gauge = meter.create_gauge( | ||
name="space_usage", | ||
description="The total space usage per domain.", | ||
unit="bytes", | ||
) | ||
|
||
space_utilization_per_domain = Artifact.objects.values("pulp_domain__name").annotate( | ||
total_size=Sum("size", default=0) | ||
) | ||
|
||
# We're using the same gauge with different attributes for each domain space usage | ||
for domain in space_utilization_per_domain: | ||
space_usage_gauge.set(domain["total_size"], {"domain_name": domain["pulp_domain__name"]}) | ||
|
||
metric_reader.collect() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters