Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connector: use HTTP session #110

Merged
merged 4 commits into from
Feb 19, 2024
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
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.11.1] - 2023-01-29
### Changed

- When forwarding events, use a http session to reuse the existing HTTP connection

## [1.11.1] - 2024-01-29

### Fixed

- Fixes connector configuration file name

## [1.11.0] - 2023-01-17
## [1.11.0] - 2024-01-17

### Changed

Expand Down
9 changes: 7 additions & 2 deletions sekoia_automation/connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ def _retry(self):
reraise=True,
)

@cached_property
def _http_session(self) -> requests.Session:
session = requests.Session()
session.headers.update({"User-Agent": self._connector_user_agent})
return session

@cached_property
def _connector_user_agent(self) -> str:
return f"sekoiaio-connector-{self.configuration.intake_key}"
Expand Down Expand Up @@ -133,10 +139,9 @@ def _send_chunk(

for attempt in self._retry():
with attempt:
res: Response = requests.post(
res: Response = self._http_session.post(
batch_api,
json=request_body,
headers={"User-Agent": self._connector_user_agent},
timeout=30,
)
res.raise_for_status()
Expand Down
Loading