From 72ea5b887d791d95e9a164aece94b0d78ed57741 Mon Sep 17 00:00:00 2001 From: Alex Thomae Date: Thu, 20 Jun 2024 09:50:52 +0200 Subject: [PATCH 1/2] Add debug for bad unhandled image name --- cioban/cioban.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cioban/cioban.py b/cioban/cioban.py index fb808c6..64146b0 100644 --- a/cioban/cioban.py +++ b/cioban/cioban.py @@ -223,7 +223,14 @@ def get_services(self): # this will allow us to set a metric `service_info` for service in self.docker.services.list(): image = service.attrs['Spec']['TaskTemplate']['ContainerSpec']['Image'].split('@sha256:') - prometheus.PROM_SVC_INFO.labels(service.name,service.id,service.short_id,image[0],image[1]).set(1) + try: + prometheus.PROM_SVC_INFO.labels(service.name,service.id,service.short_id,image[0],image[1]).set(1) + except IndexError as e: + log.warning( + 'Cought an error parsing ' + f'{service.attrs['Spec']['TaskTemplate']['ContainerSpec']['Image']}: ' + f'{e}' + ) services = self.docker.services.list(filters=self.settings['filter_services']) for blacklist_service in self.settings['blacklist_services']: From 04baeffea4d38c8194d90959e9e576f80e2b527f Mon Sep 17 00:00:00 2001 From: Alex Thomae Date: Thu, 20 Jun 2024 10:01:41 +0200 Subject: [PATCH 2/2] Set the image_sha256 to if it doesn't exist --- cioban/cioban.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/cioban/cioban.py b/cioban/cioban.py index 64146b0..341b16f 100644 --- a/cioban/cioban.py +++ b/cioban/cioban.py @@ -224,13 +224,21 @@ def get_services(self): for service in self.docker.services.list(): image = service.attrs['Spec']['TaskTemplate']['ContainerSpec']['Image'].split('@sha256:') try: - prometheus.PROM_SVC_INFO.labels(service.name,service.id,service.short_id,image[0],image[1]).set(1) - except IndexError as e: - log.warning( - 'Cought an error parsing ' - f'{service.attrs['Spec']['TaskTemplate']['ContainerSpec']['Image']}: ' - f'{e}' - ) + prometheus.PROM_SVC_INFO.labels( + name=service.name, + id=service.id, + short_id=service.short_id, + image_name=image[0], + image_sha256=image[1] + ).set(1) + except IndexError: + prometheus.PROM_SVC_INFO.labels( + name=service.name, + id=service.id, + short_id=service.short_id, + image_name=image[0], + image_sha256='N/A' + ).set(1) services = self.docker.services.list(filters=self.settings['filter_services']) for blacklist_service in self.settings['blacklist_services']: