Skip to content

Commit e7a8356

Browse files
committed
Revert change to start respecting timeout passed into metric exporter
1 parent f917af6 commit e7a8356

File tree

2 files changed

+6
-26
lines changed

2 files changed

+6
-26
lines changed

exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,14 @@ def _export(self, serialized_data: bytes, timeout_sec: float):
205205
def export(
206206
self,
207207
metrics_data: MetricsData,
208-
timeout_millis: Optional[float] = None,
208+
timeout_millis: Optional[float] = 10000,
209209
**kwargs,
210210
) -> MetricExportResult:
211211
if self._shutdown:
212212
_logger.warning("Exporter already shutdown, ignoring batch")
213213
return MetricExportResult.FAILURE
214214
serialized_data = encode_metrics(metrics_data).SerializeToString()
215-
deadline_sec = time() + (
216-
timeout_millis / 1e3 if timeout_millis else self._timeout
217-
)
215+
deadline_sec = time() + self._timeout
218216
for retry_num in range(_MAX_RETRYS):
219217
resp = self._export(serialized_data, deadline_sec - time())
220218
if resp.ok:

exporter/opentelemetry-exporter-otlp-proto-http/tests/metrics/test_otlp_metrics_exporter.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -505,17 +505,16 @@ def test_preferred_aggregation_override(self):
505505

506506
@patch.object(Session, "post")
507507
def test_retry_timeout(self, mock_post):
508-
exporter = OTLPMetricExporter(timeout=3.5)
508+
exporter = OTLPMetricExporter(timeout=1.5)
509509

510510
resp = Response()
511511
resp.status_code = 503
512512
resp.reason = "UNAVAILABLE"
513513
mock_post.return_value = resp
514514
with self.assertLogs(level=WARNING) as warning:
515515
before = time.time()
516-
# Set timeout to 1.5 seconds, takes precedence over the 3.5 second class timeout.
517516
self.assertEqual(
518-
exporter.export(self.metrics["sum_int"], 1500),
517+
exporter.export(self.metrics["sum_int"]),
519518
MetricExportResult.FAILURE,
520519
)
521520
after = time.time()
@@ -528,23 +527,6 @@ def test_retry_timeout(self, mock_post):
528527
"Transient error UNAVAILABLE encountered while exporting metrics batch, retrying in",
529528
warning.records[0].message,
530529
)
531-
mock_post.reset_mock()
532-
before = time.time()
533-
# This time the class level 3.5s timeout should be used.
534-
self.assertEqual(
535-
exporter.export(self.metrics["sum_int"]),
536-
MetricExportResult.FAILURE,
537-
)
538-
after = time.time()
539-
540-
# First call at time 0, second at time 1, third at time 3.
541-
self.assertEqual(mock_post.call_count, 3)
542-
# There's a +/-20% jitter on each backoff.
543-
self.assertTrue(2.35 < after - before < 3.65)
544-
self.assertIn(
545-
"Transient error UNAVAILABLE encountered while exporting metrics batch, retrying in",
546-
warning.records[0].message,
547-
)
548530

549531
@patch.object(Session, "post")
550532
def test_timeout_set_correctly(self, mock_post):
@@ -557,5 +539,5 @@ def export_side_effect(*args, **kwargs):
557539
return resp
558540

559541
mock_post.side_effect = export_side_effect
560-
exporter = OTLPMetricExporter()
561-
exporter.export(self.metrics["sum_int"], 400)
542+
exporter = OTLPMetricExporter(timeout=0.4)
543+
exporter.export(self.metrics["sum_int"])

0 commit comments

Comments
 (0)