Skip to content
Open
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
25 changes: 19 additions & 6 deletions src/axiom_py/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,25 @@ def ingest(
# prepare query params
params = self._prepare_ingest_options(opts)

# override the default header and set the value from the passed parameter
res = self.session.post(
path, data=payload, headers=headers, params=params
)
status_snake = decamelize(res.json())
return from_dict(IngestStatus, status_snake)
try:
# override the default header and set the value from the passed parameter
res = self.session.post(
path, data=payload, headers=headers, params=params
)
status_snake = decamelize(res.json())
return from_dict(IngestStatus, status_snake)
except AxiomError as err:
# Do not crash the app if we cannot save to the logs to Axiom's servers
# Log the error to stdout, since we cannot send it to Axiom
print(err)
return IngestStatus(
ingested=0,
failed=1,
failures=[],
processed_bytes=0,
blocks_created=0,
wal_length=0,
)

def ingest_events(
self,
Expand Down
16 changes: 16 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ def test_retries(self):
self.client.datasets.get("test")
assert len(responses.calls) == 3

@responses.activate
def test_backend_failures(self):
axiomUrl = os.getenv("AXIOM_URL") or ""
url = f"{axiomUrl}/v1/datasets/{self.dataset_name}/ingest"
responses.add(responses.POST, url, status=503)
responses.add(responses.POST, url, status=503)
responses.add(responses.POST, url, status=503)
responses.add(responses.POST, url, status=503)

try:
self.client.ingest_events(self.dataset_name, self.events)
except: # noqa: E722
# fail the test if we crash during ingestion
assert False
assert True

def test_step001_ingest(self):
"""Tests the ingest endpoint"""
data: bytes = ujson.dumps(self.events).encode()
Expand Down