From d59793db251f624a582b64474bd0ee40fe4c1b8f Mon Sep 17 00:00:00 2001 From: Dimitrios Christidis Date: Fri, 2 Aug 2024 09:51:34 +0200 Subject: [PATCH 1/7] ATLAS: Explicitely run with Python3 --- atlas/check_injecting_rules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atlas/check_injecting_rules b/atlas/check_injecting_rules index 4d70e3b..5befa84 100755 --- a/atlas/check_injecting_rules +++ b/atlas/check_injecting_rules @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Copyright European Organization for Nuclear Research (CERN) 2013 # # Licensed under the Apache License, Version 2.0 (the "License"); From 8f2a5e2e24786ececef76ec0c1f9b2a7cf21fc22 Mon Sep 17 00:00:00 2001 From: Dimitrios Christidis Date: Fri, 2 Aug 2024 09:52:28 +0200 Subject: [PATCH 2/7] ATLAS: Use standard file header --- atlas/check_injecting_rules | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/atlas/check_injecting_rules b/atlas/check_injecting_rules index 5befa84..fa1f1e4 100755 --- a/atlas/check_injecting_rules +++ b/atlas/check_injecting_rules @@ -1,15 +1,17 @@ #!/usr/bin/env python3 -# Copyright European Organization for Nuclear Research (CERN) 2013 +# Copyright European Organization for Nuclear Research (CERN) since 2012 # # Licensed under the Apache License, Version 2.0 (the "License"); -# You may not use this file except in compliance with the License. -# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# Authors: -# - Martin Barisits, , 2016 -# - Thomas Beermann, , 2019 -# - Donata Mielaikaite, , 2020 -# - Eric Vaandering, , 2020 +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. """ Probe to check the backlog of injecting rules. From 26a29e4151bf5af238eeadd3c44f9b2184edaca8 Mon Sep 17 00:00:00 2001 From: Dimitrios Christidis Date: Fri, 2 Aug 2024 09:54:55 +0200 Subject: [PATCH 3/7] ATLAS: Port query to SQLAlchemy 2.0 syntax --- atlas/check_injecting_rules | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/atlas/check_injecting_rules b/atlas/check_injecting_rules index fa1f1e4..ab4f644 100755 --- a/atlas/check_injecting_rules +++ b/atlas/check_injecting_rules @@ -21,11 +21,12 @@ import sys import traceback from prometheus_client import CollectorRegistry, Gauge, push_to_gateway +from sqlalchemy import func, select + from rucio.common.config import config_get from rucio.db.sqla import models from rucio.db.sqla.constants import RuleState from rucio.db.sqla.session import get_session -from rucio.db.sqla.util import get_count from utils import probe_metrics @@ -40,8 +41,16 @@ if __name__ == "__main__": try: registry = CollectorRegistry() session = get_session() - query = session.query(models.ReplicationRule.scope).filter(models.ReplicationRule.state == RuleState.INJECT) - result = get_count(query) + + query = select( + func.count() + ).select_from( + models.ReplicationRule + ).where( + models.ReplicationRule.state == RuleState.INJECT + ) + + result = session.execute(query).scalar_one() probe_metrics.gauge('judge.injecting_rules').set(result) Gauge('judge_injecting_rules', '', registry=registry).set(result) From 17d7b56002099833da740f4eec711fc26a438ce3 Mon Sep 17 00:00:00 2001 From: Dimitrios Christidis Date: Fri, 2 Aug 2024 09:55:49 +0200 Subject: [PATCH 4/7] ATLAS: Simplify configuration handling --- atlas/check_injecting_rules | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/atlas/check_injecting_rules b/atlas/check_injecting_rules index ab4f644..a3f9784 100755 --- a/atlas/check_injecting_rules +++ b/atlas/check_injecting_rules @@ -23,7 +23,7 @@ import traceback from prometheus_client import CollectorRegistry, Gauge, push_to_gateway from sqlalchemy import func, select -from rucio.common.config import config_get +from rucio.common.config import config_get_list from rucio.db.sqla import models from rucio.db.sqla.constants import RuleState from rucio.db.sqla.session import get_session @@ -33,9 +33,7 @@ from utils import probe_metrics # Exit statuses OK, WARNING, CRITICAL, UNKNOWN = 0, 1, 2, 3 -PROM_SERVERS = config_get('monitor', 'prometheus_servers', raise_exception=False, default='') -if PROM_SERVERS != '': - PROM_SERVERS = PROM_SERVERS.split(',') +PROM_SERVERS = config_get_list('monitor', 'prometheus_servers', raise_exception=False, default=[]) if __name__ == "__main__": try: @@ -54,12 +52,11 @@ if __name__ == "__main__": probe_metrics.gauge('judge.injecting_rules').set(result) Gauge('judge_injecting_rules', '', registry=registry).set(result) - if len(PROM_SERVERS): - for server in PROM_SERVERS: - try: - push_to_gateway(server.strip(), job='check_injecting_rules', registry=registry) - except: - continue + for server in PROM_SERVERS: + try: + push_to_gateway(server.strip(), job='check_injecting_rules', registry=registry) + except: + continue print(result) except: From d41fd8634fadaf114b177ed64a8e3a9c6badacf0 Mon Sep 17 00:00:00 2001 From: Dimitrios Christidis Date: Fri, 2 Aug 2024 09:56:09 +0200 Subject: [PATCH 5/7] ATLAS: Avoid bare except keyword --- atlas/check_injecting_rules | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atlas/check_injecting_rules b/atlas/check_injecting_rules index a3f9784..c0f08ae 100755 --- a/atlas/check_injecting_rules +++ b/atlas/check_injecting_rules @@ -55,11 +55,11 @@ if __name__ == "__main__": for server in PROM_SERVERS: try: push_to_gateway(server.strip(), job='check_injecting_rules', registry=registry) - except: + except Exception: continue print(result) - except: + except Exception: print(traceback.format_exc()) sys.exit(UNKNOWN) sys.exit(OK) From 179d4c6d591c44773bb6b229cd9ec1cd38339264 Mon Sep 17 00:00:00 2001 From: Dimitrios Christidis Date: Fri, 2 Aug 2024 09:56:21 +0200 Subject: [PATCH 6/7] ATLAS: Use quotes consistently --- atlas/check_injecting_rules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atlas/check_injecting_rules b/atlas/check_injecting_rules index c0f08ae..56866a9 100755 --- a/atlas/check_injecting_rules +++ b/atlas/check_injecting_rules @@ -35,7 +35,7 @@ OK, WARNING, CRITICAL, UNKNOWN = 0, 1, 2, 3 PROM_SERVERS = config_get_list('monitor', 'prometheus_servers', raise_exception=False, default=[]) -if __name__ == "__main__": +if __name__ == '__main__': try: registry = CollectorRegistry() session = get_session() From cf1eec6af205523b17f77b86154a4b2d09198202 Mon Sep 17 00:00:00 2001 From: Dimitrios Christidis Date: Fri, 2 Aug 2024 10:01:24 +0200 Subject: [PATCH 7/7] ATLAS: Remove unnecessary use of str.strip() --- atlas/check_injecting_rules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atlas/check_injecting_rules b/atlas/check_injecting_rules index 56866a9..a829501 100755 --- a/atlas/check_injecting_rules +++ b/atlas/check_injecting_rules @@ -54,7 +54,7 @@ if __name__ == '__main__': for server in PROM_SERVERS: try: - push_to_gateway(server.strip(), job='check_injecting_rules', registry=registry) + push_to_gateway(server, job='check_injecting_rules', registry=registry) except Exception: continue