Skip to content

Commit

Permalink
Merge pull request #90 from SEKOIA-IO/fix/batch_url
Browse files Browse the repository at this point in the history
fix: Fixes batch url computation
  • Loading branch information
Darkheir authored Nov 3, 2023
2 parents bdf09f6 + ae69653 commit aa1101d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fixes batch url computation

## [1.6.0] - 2023-10-20

### Added
Expand Down
4 changes: 2 additions & 2 deletions sekoia_automation/connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from concurrent.futures import wait as wait_futures
from datetime import datetime, time
from functools import cached_property
from os.path import join as urljoin
from typing import Any
from urllib.parse import urljoin

import orjson
import requests
Expand Down Expand Up @@ -150,7 +150,7 @@ def push_events_to_intakes(
self._error_count = 0
self._last_events_time = datetime.utcnow()
intake_host = os.getenv("INTAKE_URL", self.configuration.intake_server)
batch_api = urljoin(intake_host, "/batch")
batch_api = urljoin(intake_host, "batch")

# Dict to collect event_ids for the API
collect_ids: dict[int, list] = {}
Expand Down
22 changes: 22 additions & 0 deletions tests/connectors/test_connector.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from unittest.mock import Mock, PropertyMock, patch

import pytest
Expand Down Expand Up @@ -124,6 +125,27 @@ def test_push_event_to_intake_with_chunks(test_connector, mocked_trigger_logs):
assert result == ["001", "002", "003", "004"]


def test_push_event_to_intake_custom_url(test_connector, mocked_trigger_logs):
url = "https://fra2.app.sekoia.io/v1/intake-http/batch"
batch_mock = mocked_trigger_logs.post(
url, json={"event_ids": ["001"]}, additional_matcher=match_events("foo")
)
# With trailing slash
with patch.dict(
os.environ, {"INTAKE_URL": "https://fra2.app.sekoia.io/v1/intake-http/"}
):
test_connector.push_events_to_intakes(["foo"])
assert batch_mock.call_count == 1

# Without trailing slash
mocked_trigger_logs.reset_mock()
with patch.dict(
os.environ, {"INTAKE_URL": "https://fra2.app.sekoia.io/v1/intake-http"}
):
test_connector.push_events_to_intakes(["foo"])
assert batch_mock.call_count == 1


def test_push_event_to_intake_with_chunks_executor_stopped(
test_connector, mocked_trigger_logs
):
Expand Down

0 comments on commit aa1101d

Please sign in to comment.