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

Correct checking instance type of get data response #15554

Merged
merged 6 commits into from
Aug 16, 2023
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
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
Loading