Skip to content

Commit

Permalink
Merge pull request #230 from stefan-k/fix_es
Browse files Browse the repository at this point in the history
Set elasticsearch client version to >=7.17,<8.0.0
  • Loading branch information
giffels committed Apr 14, 2022
2 parents 8f1cd47 + 0eb31b1 commit add98d8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def get_cryptography_version():
"cobald>=0.12.3",
"asyncssh",
"aiotelegraf",
"elasticsearch",
"elasticsearch>=7.17,<8.0.0",
"aioprometheus>=21.9.0",
"kubernetes_asyncio",
"pydantic",
Expand Down
6 changes: 4 additions & 2 deletions tardis/plugins/elasticsearchmonitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def __init__(self):
self._index = config.index
self._meta = getattr(config, "meta", "")

self._es = Elasticsearch([{"host": config.host, "port": config.port}])
self._es = Elasticsearch(
[{"scheme": "http", "host": config.host, "port": config.port}]
)

async def notify(self, state: State, resource_attributes: AttributeDict) -> None:
"""
Expand All @@ -47,7 +49,7 @@ async def notify(self, state: State, resource_attributes: AttributeDict) -> None
"state": str(state),
"meta": self._meta,
"timestamp": int(time() * 1000),
"resource_status": str(resource_attributes["resource_status"]),
"resource_status": str(resource_attributes.get("resource_status", "")),
}

await self.async_execute(document)
Expand Down
36 changes: 36 additions & 0 deletions tests/plugins_t/test_elasticsearchmonitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,39 @@ def test_notify(self):
id=f"{test_param.drone_uuid}-2",
index=f"{self.plugin._index}-{self.mock_datetime.now.return_value.strftime.return_value}", # noqa: B950
)

def test_notify_resource_status_missing(self):
test_param = AttributeDict(
site_name="test-site",
machine_type="test_machine_type",
created=datetime.now(),
updated=datetime.now(),
drone_uuid="test-drone",
)

test_param_ext = {
**test_param,
"state": str(CleanupState()),
"meta": self.plugin._meta,
"timestamp": int(self.mock_time.return_value * 1000),
"resource_status": "",
"revision": 2,
}

self.mock_elasticsearch.return_value.search.return_value = {
"hits": {"total": {"value": 2}}
}

run_async(
self.plugin.notify, state=CleanupState(), resource_attributes=test_param
)

self.mock_elasticsearch.return_value.search.assert_called_with(
index=f"{self.plugin._index}*",
body={"query": {"term": {"drone_uuid.keyword": test_param.drone_uuid}}},
)
self.mock_elasticsearch.return_value.create.assert_called_with(
body=test_param_ext,
id=f"{test_param.drone_uuid}-2",
index=f"{self.plugin._index}-{self.mock_datetime.now.return_value.strftime.return_value}", # noqa: B950
)

0 comments on commit add98d8

Please sign in to comment.