Skip to content

Commit

Permalink
[sink.elasticsearch] Add support for index_prefix (#46)
Browse files Browse the repository at this point in the history
Fixes: #12

### Test Plan

Not tested, lint and unit test only
  • Loading branch information
nhairs authored Oct 18, 2024
1 parent 97cd3c9 commit 7476820
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/migrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Use a `.elasticsearch:Elasticsearch` Sink.
- `timeout`: moved to `client.timeout`.
- `cert_path`: moved to `client.cert_path`.
- `index_suffix`: no changes.
- `index_prefix`: not supported - [GitHub Issue #12](https://github.com/nhairs/parsedmarc-fork/issues/12).
- `index_prefix`: no changes.
- `monthly_indexes`: no changes.
- `number_of_shards`: no changes.
- `number_of_replicas`: no changes.
Expand Down
5 changes: 3 additions & 2 deletions src/parsedmarc/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def __init__( # pylint: disable=too-many-positional-arguments
api_key: str | None = None,
timeout: float = 60.0,
index_suffix: str | None = None,
index_prefix: str = "",
monthly_indexes: bool = True,
number_of_shards: int = 1,
number_of_replicas: int = 0,
Expand Down Expand Up @@ -230,8 +231,8 @@ def __init__( # pylint: disable=too-many-positional-arguments
self.client = Elasticsearch(**conn_params) # type: ignore[arg-type]

## Other settings
self.aggregate_index_base = "dmarc_aggregate"
self.forensic_index_base = "dmarc_forensic"
self.aggregate_index_base = f"{index_prefix}dmarc_aggregate"
self.forensic_index_base = f"{index_prefix}dmarc_forensic"

if index_suffix:
self.aggregate_index_base += f"_{index_suffix}"
Expand Down
2 changes: 2 additions & 0 deletions src/parsedmarc/sink/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def setup(self) -> None:
api_key=self.config.client.api_key,
timeout=self.config.client.timeout,
index_suffix=self.config.index_suffix,
index_prefix=self.config.index_prefix,
monthly_indexes=self.config.monthly_indexes,
number_of_shards=self.config.number_of_shards,
number_of_replicas=self.config.number_of_replicas,
Expand Down Expand Up @@ -85,6 +86,7 @@ class ElasticsearchConfig(BaseConfig):

client: ElasticsearchClientConfig
index_suffix: Union[str, None] = None
index_prefix: str = ""
monthly_indexes: bool = True
number_of_shards: int = 1
number_of_replicas: int = 0
Expand Down

0 comments on commit 7476820

Please sign in to comment.