Skip to content

Commit

Permalink
Correct checking instance type of get data response (#15554)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivek-datadog committed Aug 16, 2023
1 parent 0cbcab5 commit 8726262
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions elastic/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

***Fixed***:

* Correct checking instance type of get data response ([#15554](https://github.com/DataDog/integrations-core/pull/15554))
* Avoid collecting template metrics on unsupported ES versions. ([#15550](https://github.com/DataDog/integrations-core/pull/15550))

## 6.0.0 / 2023-08-10
Expand Down
2 changes: 1 addition & 1 deletion elastic/datadog_checks/elastic/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def _get_data(self, url, send_sc=True, data=None):
resp.raise_for_status()
except Exception as e:
# this means we've hit a particular kind of auth error that means the config is broken
if resp and resp.status_code == 400:
if isinstance(resp, requests.Response) and resp.status_code == 400:
raise AuthenticationError("The ElasticSearch credentials are incorrect")

if send_sc:
Expand Down
31 changes: 30 additions & 1 deletion elastic/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from datadog_checks.base import ConfigurationError
from datadog_checks.dev.http import MockResponse
from datadog_checks.elastic import ESCheck
from datadog_checks.elastic.elastic import get_value_from_path
from datadog_checks.elastic.elastic import AuthenticationError, get_value_from_path

from .common import URL, get_fixture_path

Expand Down Expand Up @@ -147,6 +147,35 @@ def test_get_value_from_path():
assert value == "foo"


def test__get_data_throws_authentication_error(instance):
with mock.patch(
'requests.get',
return_value=MockResponse(status_code=400),
):
check = ESCheck('elastic', {}, instances=[instance])

with pytest.raises(AuthenticationError):
check._get_data(url='test.com')


def test__get_data_creates_critical_service_alert(aggregator, instance):
with mock.patch(
'requests.get',
return_value=MockResponse(status_code=500),
):
check = ESCheck('elastic', {}, instances=[instance])

with pytest.raises(Exception):
check._get_data(url='test.com')

aggregator.assert_service_check(
check.SERVICE_CHECK_CONNECT_NAME,
status=check.CRITICAL,
tags=check._config.service_check_tags,
message="Error 500 Server Error: None for url: None when hitting test.com",
)


@pytest.mark.parametrize(
'version, return_value',
[
Expand Down

0 comments on commit 8726262

Please sign in to comment.