Skip to content

Commit

Permalink
Merge pull request #14 from vidok/vidok/add-user-agent-to-es-client
Browse files Browse the repository at this point in the history
Add user-agent header
  • Loading branch information
dtmirizzi authored Feb 8, 2024
2 parents 8d9b195 + 1d84e55 commit da64d2a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions target_elasticsearch/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
INDEX_FORMAT = "index_format"
INDEX_TEMPLATE_FIELDS = "index_schema_fields"
METADATA_FIELDS = "metadata_fields"
NAME = "target-elasticsearch"


def to_daily(date) -> str:
Expand Down
9 changes: 9 additions & 0 deletions target_elasticsearch/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
ELASTIC_MONTHLY_FORMAT,
ELASTIC_DAILY_FORMAT,
METADATA_FIELDS,
NAME,
to_daily,
to_monthly,
to_yearly,
Expand Down Expand Up @@ -197,6 +198,8 @@ def _authenticated_client(self) -> elasticsearch.Elasticsearch:
else:
self.logger.info("using default elastic search connection config")

config["headers"] = {"user-agent": self._elasticsearch_user_agent()}

return elasticsearch.Elasticsearch(**config)

def write_output(self, records):
Expand Down Expand Up @@ -228,3 +231,9 @@ def clean_up(self) -> None:
"""
self.logger.debug(f"Cleaning up sink for {self.stream_name}")
self.client.close()

def _elasticsearch_user_agent(self) -> str:
"""
Returns a user agent string for the elasticsearch client
"""
return f"meltano-loader-elasticsearch/{PluginBase._get_package_version(NAME)}"

0 comments on commit da64d2a

Please sign in to comment.