Skip to content

Commit

Permalink
Remove references to 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
alopezz committed Aug 21, 2023
1 parent c03b5b8 commit 78f2251
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 74 deletions.
13 changes: 2 additions & 11 deletions harbor/datadog_checks/harbor/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions harbor/datadog_checks/harbor/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
31 changes: 6 additions & 25 deletions harbor/datadog_checks/harbor/harbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
10 changes: 0 additions & 10 deletions harbor/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 4 additions & 10 deletions harbor/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -131,19 +127,17 @@ 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')
elif match(args[0], CHARTREPO_HEALTH_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:
Expand Down
9 changes: 3 additions & 6 deletions harbor/tests/test_harbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)])
12 changes: 4 additions & 8 deletions harbor/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,17 @@
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")
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")
Expand Down

0 comments on commit 78f2251

Please sign in to comment.