Skip to content

Commit

Permalink
Remove support for harbor < 1.10 (#15634)
Browse files Browse the repository at this point in the history
* Remove references to version 1.5

* Remove references to version 1.6

* Remove references to version 1.7

* Remove references to 1.8

* Add changelog
  • Loading branch information
alopezz authored Aug 28, 2023
1 parent 79eccb3 commit 75081d7
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 100 deletions.
4 changes: 4 additions & 0 deletions harbor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

***Removed***:

* Remove support for harbor < 1.10 ([#15634](https://github.com/DataDog/integrations-core/pull/15634))

## 2.3.1 / 2023-08-18

***Fixed***:
Expand Down
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
7 changes: 0 additions & 7 deletions harbor/datadog_checks/harbor/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@
SYSTEM_INFO_URL = "{base_url}/api/systeminfo/"
API_VERSION_URL = "{base_url}/api/version"
LOGIN_URL = "{base_url}/c/login/"
LOGIN_PRE_1_7_URL = "{base_url}/login/"
HEALTH_URL = "{base_url}/api/health/"
PING_URL = "{base_url}/api/ping/"
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_5 = [1, 5, 0]
VERSION_1_7 = [1, 7, 0]
VERSION_1_8 = [1, 8, 0]

HEALTHY = 'healthy'
34 changes: 6 additions & 28 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_5, VERSION_1_8
from .common import HEALTHY

CAN_CONNECT = 'harbor.can_connect'
REGISTRY_STATUS = 'harbor.registry.status'
Expand All @@ -16,33 +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)
elif api.harbor_version >= VERSION_1_5:
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)
else:
# Before version 1.5, there is no support for a health check.
self.service_check(STATUS, AgentCheck.UNKNOWN, tags=base_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
25 changes: 6 additions & 19 deletions harbor/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

from datadog_checks.dev import get_docker_hostname

VERSION_1_5 = [1, 5, 0]
VERSION_1_6 = [1, 6, 0]
VERSION_1_8 = [1, 8, 0]
VERSION_2_2 = [2, 2, 0]

HARBOR_COMPONENTS = ['chartmuseum', 'registry', 'redis', 'jobservice', 'registryctl', 'portal', 'core', 'database']
Expand All @@ -21,9 +18,8 @@
('harbor.projects.count', False),
('harbor.disk.free', True),
('harbor.disk.total', True),
('harbor.registry.read_only', False),
]
if HARBOR_VERSION >= VERSION_1_5:
HARBOR_METRICS.append(('harbor.registry.read_only', False))

HERE = os.path.dirname(os.path.abspath(__file__))
URL = 'http://{}'.format(get_docker_hostname())
Expand Down Expand Up @@ -77,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 All @@ -100,8 +87,8 @@
VOLUME_INFO_PRE_2_2_FIXTURE = {"storage": {"total": 1e6, "free": 5e5}}
VOLUME_INFO_FIXTURE = {"storage": [{"total": 1e6, "free": 5e5}]}

SYSTEM_INFO_FIXTURE = {"harbor_version": "v{}-25bb24ca".format(os.environ['HARBOR_VERSION'])}
if HARBOR_VERSION >= VERSION_1_5:
SYSTEM_INFO_FIXTURE['read_only'] = False
if HARBOR_VERSION >= VERSION_1_6:
SYSTEM_INFO_FIXTURE['with_chartmuseum'] = True
SYSTEM_INFO_FIXTURE = {
"harbor_version": "v{}-25bb24ca".format(os.environ['HARBOR_VERSION']),
"read_only": False,
"with_chartmuseum": True,
}
20 changes: 6 additions & 14 deletions harbor/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@
from datadog_checks.harbor.common import (
CHARTREPO_HEALTH_URL,
HEALTH_URL,
LOGIN_PRE_1_7_URL,
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 @@ -37,12 +34,9 @@
INSTANCE,
PROJECTS_FIXTURE,
REGISTRIES_FIXTURE,
REGISTRIES_PRE_1_8_FIXTURE,
SYSTEM_INFO_FIXTURE,
URL,
USERS_URL,
VERSION_1_6,
VERSION_1_8,
VERSION_2_2,
VOLUME_INFO_FIXTURE,
VOLUME_INFO_PRE_2_2_FIXTURE,
Expand Down Expand Up @@ -131,21 +125,19 @@ def match(url, *candidates_url):
return True
return False

if match(args[0], LOGIN_PRE_1_7_URL, LOGIN_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) and HARBOR_VERSION >= VERSION_1_6:
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
11 changes: 3 additions & 8 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_5, 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,10 +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)])
elif HARBOR_VERSION >= VERSION_1_5:
aggregator.assert_service_check('harbor.status', status=HarborCheck.OK)
else:
aggregator.assert_service_check('harbor.status', status=HarborCheck.UNKNOWN)
for c in HARBOR_COMPONENTS:
aggregator.assert_service_check('harbor.status', status=mock.ANY, tags=['component:{}'.format(c)])
17 changes: 4 additions & 13 deletions harbor/tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,17 @@
from datadog_checks.base import AgentCheck
from datadog_checks.dev.http import MockResponse

from .common import HARBOR_COMPONENTS, HARBOR_VERSION, VERSION_1_5, VERSION_1_6, 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)])
elif harbor_api.harbor_version >= VERSION_1_6:
aggregator.assert_service_check('harbor.status', AgentCheck.OK, tags=base_tags + ['component:chartmuseum'])
aggregator.assert_service_check('harbor.status', AgentCheck.OK, tags=base_tags)
elif harbor_api.harbor_version >= VERSION_1_5:
aggregator.assert_service_check('harbor.status', AgentCheck.OK, tags=base_tags)
else:
aggregator.assert_service_check('harbor.status', AgentCheck.UNKNOWN, 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 All @@ -53,7 +45,6 @@ def test_submit_disk_metrics(aggregator, harbor_check, harbor_api):


@pytest.mark.usefixtures("patch_requests")
@pytest.mark.skipif(HARBOR_VERSION < VERSION_1_5, reason="The registry.read_only metric is submitted for Harbor 1.5+")
def test_submit_read_only_status(aggregator, harbor_check, harbor_api):
tags = ['tag1:val1', 'tag2']
harbor_check._submit_read_only_status(harbor_api, tags)
Expand Down

0 comments on commit 75081d7

Please sign in to comment.