Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit 891666a

Browse files
authored
Add 502 and 504 as retriable (#1153)
1 parent b83d6fd commit 891666a

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

contrib/opencensus-ext-azure/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- Add storage existence checks to storing and transmitting in exporter
66
([#1150](https://github.com/census-instrumentation/opencensus-python/pull/1150))
7+
- Add 502 and 504 status codes as retriable
8+
([#1150](https://github.com/census-instrumentation/opencensus-python/pull/1150))
79

810
## 1.1.6
911
Released 2022-08-03

contrib/opencensus-ext-azure/opencensus/ext/azure/common/transport.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
408, # Request Timeout
4444
429, # Too many requests
4545
500, # Internal server error
46+
502, # Bad Gateway
4647
503, # Service unavailable
48+
504, # Gateway timeout
4749
)
4850
THROTTLE_STATUS_CODES = (402, 439)
4951

contrib/opencensus-ext-azure/tests/test_transport_mixin.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,30 @@ def test_statsbeat_500(self):
599599
self.assertEqual(_requests_map['count'], 1)
600600
self.assertEqual(result, TransportStatusCode.RETRY)
601601

602+
def test_transmission_502(self):
603+
mixin = TransportMixin()
604+
mixin.options = Options()
605+
with LocalFileStorage(os.path.join(TEST_FOLDER, self.id())) as stor:
606+
mixin.storage = stor
607+
mixin.storage.put([1, 2, 3])
608+
with mock.patch('requests.post') as post:
609+
post.return_value = MockResponse(502, 'unknown')
610+
mixin._transmit_from_storage()
611+
self.assertIsNone(mixin.storage.get())
612+
self.assertEqual(len(os.listdir(mixin.storage.path)), 1)
613+
614+
def test_statsbeat_502(self):
615+
mixin = TransportMixin()
616+
mixin.options = Options()
617+
with mock.patch('requests.post') as post:
618+
post.return_value = MockResponse(502, 'unknown')
619+
result = mixin._transmit([1, 2, 3])
620+
self.assertEqual(len(_requests_map), 3)
621+
self.assertIsNotNone(_requests_map['duration'])
622+
self.assertEqual(_requests_map['retry'][502], 1)
623+
self.assertEqual(_requests_map['count'], 1)
624+
self.assertEqual(result, TransportStatusCode.RETRY)
625+
602626
def test_transmission_503(self):
603627
mixin = TransportMixin()
604628
mixin.options = Options()
@@ -623,6 +647,30 @@ def test_statsbeat_503(self):
623647
self.assertEqual(_requests_map['count'], 1)
624648
self.assertEqual(result, TransportStatusCode.RETRY)
625649

650+
def test_transmission_504(self):
651+
mixin = TransportMixin()
652+
mixin.options = Options()
653+
with LocalFileStorage(os.path.join(TEST_FOLDER, self.id())) as stor:
654+
mixin.storage = stor
655+
mixin.storage.put([1, 2, 3])
656+
with mock.patch('requests.post') as post:
657+
post.return_value = MockResponse(504, 'unknown')
658+
mixin._transmit_from_storage()
659+
self.assertIsNone(mixin.storage.get())
660+
self.assertEqual(len(os.listdir(mixin.storage.path)), 1)
661+
662+
def test_statsbeat_504(self):
663+
mixin = TransportMixin()
664+
mixin.options = Options()
665+
with mock.patch('requests.post') as post:
666+
post.return_value = MockResponse(504, 'unknown')
667+
result = mixin._transmit([1, 2, 3])
668+
self.assertEqual(len(_requests_map), 3)
669+
self.assertIsNotNone(_requests_map['duration'])
670+
self.assertEqual(_requests_map['retry'][504], 1)
671+
self.assertEqual(_requests_map['count'], 1)
672+
self.assertEqual(result, TransportStatusCode.RETRY)
673+
626674
def test_transmission_401(self):
627675
mixin = TransportMixin()
628676
mixin.options = Options()

0 commit comments

Comments
 (0)