From 9d77c634df32033e8154447175bbc756634098ce Mon Sep 17 00:00:00 2001 From: voetberg Date: Thu, 28 Aug 2025 14:58:31 -0500 Subject: [PATCH] Common: Update query to use sqlalchemy #127 --- common/check_updated_dids | 41 ++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/common/check_updated_dids b/common/check_updated_dids index 756aad8a..f88a1e83 100755 --- a/common/check_updated_dids +++ b/common/check_updated_dids @@ -1,14 +1,17 @@ -#!/usr/bin/env python -# Copyright European Organization for Nuclear Research (CERN) 2013 +#!/usr/bin/env python3 +# 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: -# - Vincent Garonne, , 2013 -# - Thomas Beermann, , 2019 -# - Eric Vaandering , 2020-2021 +# 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 updated dids. @@ -19,10 +22,11 @@ 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.session import get_session -from rucio.db.sqla.util import get_count from utils.common import probe_metrics @@ -37,8 +41,12 @@ if __name__ == "__main__": try: registry = CollectorRegistry() session = get_session() - query = session.query(models.UpdatedDID) - result = get_count(query) + statement = select( + func.count() + ).select_from( + models.UpdatedDID + ) + result = session.execute(statement).scalar_one() probe_metrics.gauge(name='judge.updated_dids').set(result) Gauge('judge_updated_dids', '', registry=registry).set(result) @@ -48,17 +56,6 @@ if __name__ == "__main__": push_to_gateway(server.strip(), job='check_updated_dids', registry=registry) except: continue - - # created_at, count, max, min, avg, stdev = 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 - # result = session.execute('select * from atlas_rucio.concurency_stats where created_at > sysdate - 1/1440') - # for row in result: - # created_at, count, max, min, avg, stdev = row - # monitor.record_gauge(stat='judge.updated_dids_per_min.count', value=count or 0) - # monitor.record_gauge(stat='judge.updated_dids_per_min.max', value=max or 0) - # monitor.record_gauge(stat='judge.updated_dids_per_min.min', value=min or 0) - # monitor.record_gauge(stat='judge.updated_dids_per_min.avg', value=avg or 0) - # monitor.record_gauge(stat='judge.updated_dids_per_min.stdev', value=stdev or 0) - # print created_at, count, max, min, avg, stdev except: print(traceback.format_exc()) sys.exit(UNKNOWN)