diff --git a/harbor/datadog_checks/harbor/api.py b/harbor/datadog_checks/harbor/api.py index effcc72fa566d6..ed3418e1f9874e 100644 --- a/harbor/datadog_checks/harbor/api.py +++ b/harbor/datadog_checks/harbor/api.py @@ -7,12 +7,9 @@ HEALTH_URL, PING_URL, PROJECTS_URL, - REGISTRIES_PING_PRE_1_8_URL, REGISTRIES_PING_URL, - REGISTRIES_PRE_1_8_URL, REGISTRIES_URL, SYSTEM_INFO_URL, - VERSION_1_8, VOLUME_INFO_URL, ) @@ -44,17 +41,11 @@ def projects(self): return self._make_paginated_get_request(PROJECTS_URL) def registries(self): - if self.harbor_version >= VERSION_1_8: - return self._make_paginated_get_request(REGISTRIES_URL) - else: - return self._make_paginated_get_request(REGISTRIES_PRE_1_8_URL) + return self._make_paginated_get_request(REGISTRIES_URL) def registry_health(self, registry_id): data = {"id": registry_id} - if self.harbor_version >= VERSION_1_8: - return self._make_post_request(REGISTRIES_PING_URL, data=data) - else: - return self._make_post_request(REGISTRIES_PING_PRE_1_8_URL, data=data) + return self._make_post_request(REGISTRIES_PING_URL, data=data) def volume_info(self): return self._make_get_request(VOLUME_INFO_URL) diff --git a/harbor/datadog_checks/harbor/common.py b/harbor/datadog_checks/harbor/common.py index 8dff0aa630fdb2..f8c588d211eca8 100644 --- a/harbor/datadog_checks/harbor/common.py +++ b/harbor/datadog_checks/harbor/common.py @@ -9,11 +9,7 @@ CHARTREPO_HEALTH_URL = "{base_url}/api/chartrepo/health" PROJECTS_URL = "{base_url}/api/projects/" REGISTRIES_URL = "{base_url}/api/registries/" -REGISTRIES_PRE_1_8_URL = "{base_url}/api/targets/" REGISTRIES_PING_URL = "{base_url}/api/registries/ping/" -REGISTRIES_PING_PRE_1_8_URL = "{base_url}/api/targets/ping/" VOLUME_INFO_URL = "{base_url}/api/systeminfo/volumes/" -VERSION_1_8 = [1, 8, 0] - HEALTHY = 'healthy' diff --git a/harbor/datadog_checks/harbor/harbor.py b/harbor/datadog_checks/harbor/harbor.py index a94b524b6bfef5..251a602a7b5778 100644 --- a/harbor/datadog_checks/harbor/harbor.py +++ b/harbor/datadog_checks/harbor/harbor.py @@ -6,7 +6,7 @@ from datadog_checks.base import AgentCheck from .api import HarborAPI -from .common import HEALTHY, VERSION_1_8 +from .common import HEALTHY CAN_CONNECT = 'harbor.can_connect' REGISTRY_STATUS = 'harbor.registry.status' @@ -16,30 +16,11 @@ class HarborCheck(AgentCheck): def _check_health(self, api, base_tags): """Submits service checks for Harbor individual components.""" - if api.harbor_version >= VERSION_1_8: - health = api.health() - for el in health['components']: - component_status = AgentCheck.OK if el['status'] == HEALTHY else AgentCheck.CRITICAL - tags = base_tags + ['component:{}'.format(el['name'])] - self.service_check(STATUS, component_status, tags=tags) - else: - ping = api.ping() - overall_status = AgentCheck.OK if ping == 'Pong' else AgentCheck.CRITICAL - self.service_check(STATUS, overall_status, tags=base_tags) - if api.with_chartrepo: - try: - chartrepo_health = api.chartrepo_health()[HEALTHY] - except HTTPError as e: - if e.response.status_code in (401, 403): - self.log.info( - "Provided user in harbor integration config is not an admin user. Ignoring chartrepo health" - ) - self.log.debug(e, exc_info=True) - return - raise e - chartrepo_status = AgentCheck.OK if chartrepo_health else AgentCheck.CRITICAL - tags = base_tags + ['component:chartmuseum'] - self.service_check(STATUS, chartrepo_status, tags=tags) + health = api.health() + for el in health['components']: + component_status = AgentCheck.OK if el['status'] == HEALTHY else AgentCheck.CRITICAL + tags = base_tags + ['component:{}'.format(el['name'])] + self.service_check(STATUS, component_status, tags=tags) def _check_registries_health(self, api, base_tags): """A registry here is an external docker registry (DockerHub, ECR, another Harbor...) that this current diff --git a/harbor/tests/common.py b/harbor/tests/common.py index 3b0176568f6483..7433d2be94238f 100644 --- a/harbor/tests/common.py +++ b/harbor/tests/common.py @@ -5,7 +5,6 @@ from datadog_checks.dev import get_docker_hostname -VERSION_1_8 = [1, 8, 0] VERSION_2_2 = [2, 2, 0] HARBOR_COMPONENTS = ['chartmuseum', 'registry', 'redis', 'jobservice', 'registryctl', 'portal', 'core', 'database'] @@ -74,15 +73,6 @@ }, ] -REGISTRIES_PRE_1_8_FIXTURE = [ - { - "id": 1, - "name": "Demo", - "url": "https://demo.goharbor.io/", - "credential": {"type": "basic", "access_key": "*****", "access_secret": "*****"}, - } -] - REGISTRIES_FIXTURE = [ { "id": 1, diff --git a/harbor/tests/conftest.py b/harbor/tests/conftest.py index 11c3c27b1b5f3f..277c82cd841e55 100644 --- a/harbor/tests/conftest.py +++ b/harbor/tests/conftest.py @@ -19,9 +19,7 @@ LOGIN_URL, PING_URL, PROJECTS_URL, - REGISTRIES_PING_PRE_1_8_URL, REGISTRIES_PING_URL, - REGISTRIES_PRE_1_8_URL, REGISTRIES_URL, SYSTEM_INFO_URL, VOLUME_INFO_URL, @@ -36,11 +34,9 @@ INSTANCE, PROJECTS_FIXTURE, REGISTRIES_FIXTURE, - REGISTRIES_PRE_1_8_FIXTURE, SYSTEM_INFO_FIXTURE, URL, USERS_URL, - VERSION_1_8, VERSION_2_2, VOLUME_INFO_FIXTURE, VOLUME_INFO_PRE_2_2_FIXTURE, @@ -131,7 +127,7 @@ def match(url, *candidates_url): if match(args[0], LOGIN_URL): return MockResponse() - elif match(args[0], HEALTH_URL) and HARBOR_VERSION >= VERSION_1_8: + elif match(args[0], HEALTH_URL): return MockResponse(json_data=HEALTH_FIXTURE) elif match(args[0], PING_URL): return MockResponse('Pong') @@ -139,11 +135,9 @@ def match(url, *candidates_url): return MockResponse(json_data=CHARTREPO_HEALTH_FIXTURE) elif match(args[0], PROJECTS_URL): return MockResponse(json_data=PROJECTS_FIXTURE) - elif match(args[0], REGISTRIES_PRE_1_8_URL, REGISTRIES_URL): - if HARBOR_VERSION >= VERSION_1_8: - return MockResponse(json_data=REGISTRIES_FIXTURE) - return MockResponse(json_data=REGISTRIES_PRE_1_8_FIXTURE) - elif match(args[0], REGISTRIES_PING_PRE_1_8_URL, REGISTRIES_PING_URL): + elif match(args[0], REGISTRIES_URL): + return MockResponse(json_data=REGISTRIES_FIXTURE) + elif match(args[0], REGISTRIES_PING_URL): return MockResponse() elif match(args[0], VOLUME_INFO_URL): if HARBOR_VERSION < VERSION_2_2: diff --git a/harbor/tests/test_harbor.py b/harbor/tests/test_harbor.py index 5f01659f646773..4296c7613ad7eb 100644 --- a/harbor/tests/test_harbor.py +++ b/harbor/tests/test_harbor.py @@ -6,7 +6,7 @@ from datadog_checks.harbor import HarborCheck -from .common import HARBOR_COMPONENTS, HARBOR_METRICS, HARBOR_VERSION, VERSION_1_8, VERSION_2_2 +from .common import HARBOR_COMPONENTS, HARBOR_METRICS, HARBOR_VERSION, VERSION_2_2 @pytest.mark.integration @@ -53,8 +53,5 @@ def assert_basic_case(aggregator): def assert_service_checks(aggregator): aggregator.assert_service_check('harbor.can_connect', status=HarborCheck.OK) - if HARBOR_VERSION > VERSION_1_8: - for c in HARBOR_COMPONENTS: - aggregator.assert_service_check('harbor.status', status=mock.ANY, tags=['component:{}'.format(c)]) - else: - aggregator.assert_service_check('harbor.status', status=HarborCheck.OK) + for c in HARBOR_COMPONENTS: + aggregator.assert_service_check('harbor.status', status=mock.ANY, tags=['component:{}'.format(c)]) diff --git a/harbor/tests/test_unit.py b/harbor/tests/test_unit.py index dfb6d58ce170b1..92b588db4fd04f 100644 --- a/harbor/tests/test_unit.py +++ b/harbor/tests/test_unit.py @@ -8,7 +8,7 @@ from datadog_checks.base import AgentCheck from datadog_checks.dev.http import MockResponse -from .common import HARBOR_COMPONENTS, VERSION_1_8 +from .common import HARBOR_COMPONENTS @pytest.mark.usefixtures("patch_requests") @@ -16,13 +16,9 @@ def test_check_health(aggregator, harbor_check, harbor_api): base_tags = ['tag1:val1', 'tag2'] harbor_check._check_health(harbor_api, base_tags) - if harbor_api.harbor_version >= VERSION_1_8: - components = HARBOR_COMPONENTS - for c in components: - aggregator.assert_service_check('harbor.status', AgentCheck.OK, tags=base_tags + ['component:{}'.format(c)]) - else: - aggregator.assert_service_check('harbor.status', AgentCheck.OK, tags=base_tags + ['component:chartmuseum']) - aggregator.assert_service_check('harbor.status', AgentCheck.OK, tags=base_tags) + components = HARBOR_COMPONENTS + for c in components: + aggregator.assert_service_check('harbor.status', AgentCheck.OK, tags=base_tags + ['component:{}'.format(c)]) @pytest.mark.usefixtures("patch_requests")