Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Handle status 439 - Too Many Requests over extended time #80

Merged
merged 2 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions azure_monitor/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ package_dir=
=src
packages=find_namespace:
install_requires =
opentelemetry-api >= 0.5b0
opentelemetry-sdk >= 0.5b0
opentelemetry-api >= 0.6b0
opentelemetry-sdk >= 0.6b0
psutil >= 5.6.3
requests ~= 2.0

Expand Down
2 changes: 2 additions & 0 deletions azure_monitor/src/azure_monitor/export/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def _transmit(self, envelopes: typing.List[Envelope]) -> ExportResult:
for error in data["errors"]:
if error["statusCode"] in (
429, # Too Many Requests
439, # Too Many Requests over extended time
500, # Internal Server Error
503, # Service Unavailable
):
Expand Down Expand Up @@ -172,6 +173,7 @@ def _transmit(self, envelopes: typing.List[Envelope]) -> ExportResult:
if response.status_code in (
206, # Partial Content
429, # Too Many Requests
439, # Too Many Requests over extended time
500, # Internal Server Error
503, # Service Unavailable
):
Expand Down
1 change: 1 addition & 0 deletions azure_monitor/src/azure_monitor/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def _maintenance_routine(self, silent=False):
if not silent:
raise
try:
# pylint: disable=unused-variable
for blob in self.gets():
pass
except Exception:
Expand Down
2 changes: 1 addition & 1 deletion azure_monitor/tests/metrics/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from azure_monitor.options import ExporterOptions
from azure_monitor.protocol import Data, DataPoint, Envelope, MetricData

TEST_FOLDER = os.path.abspath(".test.exporter.trace")
TEST_FOLDER = os.path.abspath(".test")
STORAGE_PATH = os.path.join(TEST_FOLDER)


Expand Down
16 changes: 14 additions & 2 deletions azure_monitor/tests/test_base_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from azure_monitor.options import ExporterOptions
from azure_monitor.protocol import Data, Envelope

TEST_FOLDER = os.path.abspath(".test.exporter.base")
TEST_FOLDER = os.path.abspath(".test")
STORAGE_PATH = os.path.join(TEST_FOLDER)


Expand Down Expand Up @@ -191,7 +191,7 @@ def test_transmission_lease_failure(self, requests_mock):
exporter._transmit_from_storage()
self.assertTrue(exporter.storage.get())

def test_(self):
def test_transmission(self):
exporter = BaseExporter(
storage_path=os.path.join(TEST_FOLDER, self.id())
)
Expand Down Expand Up @@ -316,6 +316,18 @@ def test_transmission_400(self):
exporter._transmit_from_storage()
self.assertEqual(len(os.listdir(exporter.storage.path)), 0)

def test_transmission_439(self):
exporter = BaseExporter(
storage_path=os.path.join(TEST_FOLDER, self.id())
)
envelopes_to_export = map(lambda x: x.to_dict(), tuple([Envelope()]))
exporter.storage.put(envelopes_to_export)
with mock.patch("requests.post") as post:
post.return_value = MockResponse(439, "{}")
exporter._transmit_from_storage()
self.assertIsNone(exporter.storage.get())
self.assertEqual(len(os.listdir(exporter.storage.path)), 1)

def test_transmission_500(self):
exporter = BaseExporter(
storage_path=os.path.join(TEST_FOLDER, self.id())
Expand Down
2 changes: 1 addition & 1 deletion azure_monitor/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
_seconds,
)

TEST_FOLDER = os.path.abspath(".test.storage")
TEST_FOLDER = os.path.abspath(".test")


# pylint: disable=invalid-name
Expand Down
2 changes: 1 addition & 1 deletion azure_monitor/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from azure_monitor.export.trace import AzureMonitorSpanExporter
from azure_monitor.options import ExporterOptions

TEST_FOLDER = os.path.abspath(".test.exporter.trace")
TEST_FOLDER = os.path.abspath(".test")
STORAGE_PATH = os.path.join(TEST_FOLDER)


Expand Down