Skip to content

Commit

Permalink
Allow setting metrics point exported in a batch
Browse files Browse the repository at this point in the history
via environmental variable METRIC_EXPORT_SIZE
  • Loading branch information
gregorjerse committed Aug 23, 2024
1 parent d4e0c07 commit 4297dab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ All notable changes to this project are documented in this file.
This project adheres to `Semantic Versioning <http://semver.org/>`_.


==========
Unreleased
==========

Added
-----
- Allow overriding the number of max metrics points that are exported in the
same batch via ``METRICS_EXPORT_SIZE`` environmental variable (defaults to
1000)

===================
40.2.0 - 2024-08-19
===================
Expand Down
14 changes: 13 additions & 1 deletion resolwe/flow/managers/listener/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
METRICS_EXPORT_INTERVAL = 30000
# TODO: Remove this when metrics are properly implemented.
METRICS_INSECURE_EXPORT = True
# The number of data points to send in one request.
# See
# https://github.com/open-telemetry/opentelemetry-python/pull/2809
# and
# https://github.com/open-telemetry/opentelemetry-python/issues/2710
# for details.
try:
METRICS_EXPORT_SIZE = int(os.environ.get("METRICS_EXPORT_SIZE", 1000))
except ValueError:
METRICS_EXPORT_SIZE = 1000


class MetricsEventReporter(MessageProcessingCallback):
Expand Down Expand Up @@ -60,7 +70,9 @@ def _init_metrics(self, metric_endpoint):

# Initialize the opentelemetry metrics.
metric_exporter = OTLPMetricExporter(
endpoint=metric_endpoint, insecure=METRICS_INSECURE_EXPORT
endpoint=metric_endpoint,
insecure=METRICS_INSECURE_EXPORT,
max_export_batch_size=METRICS_EXPORT_SIZE,
)
metric_reader = PeriodicExportingMetricReader(
metric_exporter, METRICS_EXPORT_INTERVAL
Expand Down

0 comments on commit 4297dab

Please sign in to comment.