Skip to content

Commit 7992510

Browse files
committed
Common: Replace string formatter with f-strings, format context message uniformly #129
Changes to metric names include: * undertaker_expired_dids -> expired_dids.total * fts3.{hostname}.submitted -> fts_backlog.submitted.{hostname} * hermes_queues_messages.queues.messages -> messages_to_submit.queues.messages * transmogrifier_new_dids -> new_dids * judge_stuck_rules_without_missing_source_replica -> stuck_rules.{source_status} (source_status = [without_missing_source_replica, with_missing_source_replica]) * check_transfer_queues_status -> transfer_queues_status * judge.waiting_dids -> unevaluated_dids * reaper.unlocked_replicas -> unlocked_replicas.{replica_status} (replica_status = [expired, unlocked]) * judge.updated_dids -> updated_dids
1 parent 072758c commit 7992510

7 files changed

Lines changed: 108 additions & 84 deletions

common/check_expired_dids

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ if __name__ == "__main__":
4141
# Possible check against a threshold. If result > max_value then sys.exit(CRITICAL)
4242

4343
manager.gauge('expired_dids.total',
44-
documentation="All expired dids").set(result)
44+
documentation="All expired dids"
45+
).set(result)
4546

4647
except:
4748
print(traceback.format_exc())

common/check_fts_backlog

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ if __name__ == "__main__":
7878

7979
errmsg = ''
8080
for ftshost in FTSHOSTS.split(','):
81-
print("=== %s ===" % ftshost)
81+
print(f"=== {ftshost} ===")
8282
parsed_url = urlparse(ftshost)
8383
scheme, hostname, port = parsed_url.scheme, parsed_url.hostname, parsed_url.port
8484
retvalue = CRITICAL
85-
url = '%s/fts3/ftsmon/overview?dest_se=&source_se=&time_window=1&vo=%s' % (ftshost, VO)
85+
url = f'{ftshost}/fts3/ftsmon/overview?dest_se=&source_se=&time_window=1&vo={VO}'
8686
busy_channels = []
8787
busylimit = 5000
8888
for attempt in range(0, 5):
@@ -108,7 +108,7 @@ if __name__ == "__main__":
108108
pass
109109

110110
if CHECK_BUSY and 'submitted' in channel and channel['submitted'] >= busylimit:
111-
url_activities = '%s/fts3/ftsmon/config/activities/%s?source_se=%s&dest_se=%s' % (ftshost, VO, src, dst)
111+
url_activities = f'{ftshost}/fts3/ftsmon/config/activities/{VO}?source_se={src}&dest_se={dst}'
112112
activities = {}
113113
try:
114114
s = requests.get(url_activities, verify=False, cert=(PROXY, PROXY))
@@ -120,36 +120,33 @@ if __name__ == "__main__":
120120
'activities': activities})
121121
summary = res['summary']
122122
hostname = hostname.replace('.', '_')
123-
# If printing these indiv is important, why not monitor them seperately?
124-
print('%s : Submitted : %s' % (hostname, summary['submitted']))
125-
print('%s : Active : %s' % (hostname, summary['active']))
126-
print('%s : Staging : %s' % (hostname, summary['staging']))
127-
print('%s : Started : %s' % (hostname, summary['started']))
123+
124+
for state in ['submitted', 'active', 'staging', 'started']:
125+
print(f'{hostname} : {state.capitalize()} : {summary[state]}')
126+
128127

129128
if busy_channels != []:
130-
print('Busy channels (>%s submitted):' % busylimit)
129+
print(f'Busy channels (>{busylimit} submitted):')
131130
for bc in busy_channels:
132-
activities_str = ", ".join([("%s: %s" % (key, val)) for key, val in bc['activities'].items()])
133-
print(' %s to %s : %s submitted jobs (%s)' % (bc['src'], bc['dst'], bc['submitted'],
134-
str(activities_str)))
131+
activities_str = ", ".join([(f"{key}: {val}") for key, val in bc['activities'].items()])
132+
print(f'{bc['src']} to {bc['dst']} : {bc['submitted']} submitted jobs {activities_str}')
135133

136134
# Add to metrics
137135
backlog_count = summary['submitted'] + summary['active'] + summary['staging'] + summary['started']
138-
manager.gauge(
139-
"fts_backlog.submitted.{hostname}",
140-
documentation="All submitted, active, staged, or stated in FTS queue").labels(hostname=hostname).set(backlog_count)
136+
manager.gauge("fts_backlog.submitted.{hostname}",
137+
documentation="All submitted, active, staged, or stated in FTS queue"
138+
).labels(hostname=hostname).set(backlog_count)
141139

142140
retvalue = OK
143141
break
144142
except Exception as error:
145143
retvalue = CRITICAL
146144
if result and result.status_code:
147-
errmsg = 'Error when trying to get info from %s : HTTP status code %s. [%s]' % (
148-
ftshost, str(result.status_code), str(error))
145+
errmsg = f'Error when trying to get info from {ftshost} : HTTP status code {result.status_code}. {error}'
149146
else:
150-
errmsg = 'Error when trying to get info from %s. %s' % (ftshost, str(error))
147+
errmsg = f'Error when trying to get info from {ftshost}. {error}'
151148
if retvalue == CRITICAL:
152-
print("All attempts failed. %s" % errmsg)
149+
print(f"All attempts failed. {errmsg}")
153150
WORST_RETVALUE = max(retvalue, WORST_RETVALUE)
154151

155152

@@ -179,7 +176,6 @@ if __name__ == "__main__":
179176
except:
180177
sys.exit(WORST_RETVALUE)
181178

182-
# Does this not do the same thing as the query? Why the duplicate?
183179
for source_rse, dest_rse in se_matrix:
184180
for source_rse_id in se_map[source_rse]:
185181
for dest_rse_id in se_map[dest_rse]:

common/check_messages_to_submit

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ if __name__ == "__main__":
4141

4242
manager.gauge(
4343
"messages_to_submit.queues.messages",
44-
documentation="Messages in queue, to submit").set(message_count)
44+
documentation="Messages in queue, to submit"
45+
).set(message_count)
4546

4647
if message_count > 100000:
4748
sys.exit(WARNING)

common/check_obsolete_replicas

Lines changed: 80 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
# Copyright European Organization for Nuclear Research (CERN) 2013
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -8,77 +8,101 @@
88
# Authors:
99
# - Vincent Garonne, <vincent.garonne@cern.ch>, 2015
1010
# - Cedric Serfon, <cedric.serfon@cern.ch>, 2018
11+
# - Maggie Voetberg, <maggiev@fnal.gov>, 2024
1112

1213
'''
1314
Probe to check the backlog of obsolete replicas.
1415
'''
1516

1617
import sys
18+
import traceback
19+
from sqlalchemy.sql import text
20+
from rucio.db.sqla.session import BASE, get_session
21+
from utils.common import PrometheusPusher
1722

18-
from rucio.db.sqla.session import get_session
23+
if BASE.metadata.schema:
24+
schema = BASE.metadata.schema + '.'
25+
else:
26+
schema = ''
1927

2028
# Exit statuses
2129
OK, WARNING, CRITICAL, UNKNOWN = 0, 1, 2, 3
2230

2331

2432
if __name__ == "__main__":
2533
try:
26-
SESSION = get_session()
27-
QUERY = '''BEGIN
28-
FOR u in (SELECT
29-
a.rse_id AS rse_id,
30-
NVL(b.files, 0) AS files,
31-
NVL(b.bytes, 0) AS bytes,
32-
SYS_EXTRACT_UTC(localtimestamp) AS updated_at
33-
FROM
34-
(
35-
SELECT
36-
id AS rse_id
37-
FROM
38-
atlas_rucio.rses
39-
WHERE
40-
deleted=0) a
41-
LEFT OUTER JOIN
42-
(
43-
SELECT
44-
/*+ INDEX_FFS(replicas REPLICAS_TOMBSTONE_IDX) */
45-
rse_id,
46-
COUNT(1) AS files,
47-
SUM(bytes) AS bytes
48-
FROM
49-
atlas_rucio.replicas
50-
WHERE
51-
(
52-
CASE
53-
WHEN tombstone IS NOT NULL
54-
THEN rse_id
55-
END) IS NOT NULL
56-
AND tombstone=to_date('1-1-1970 00:00:00','MM-DD-YYYY HH24:Mi:SS')
57-
GROUP BY
58-
rse_id) b
59-
ON
60-
a.rse_id=b.rse_id)
34+
session = get_session()
35+
with PrometheusPusher() as manager:
36+
query = '''BEGIN
37+
FOR u in (SELECT
38+
a.rse_id AS rse_id,
39+
NVL(b.files, 0) AS files,
40+
NVL(b.bytes, 0) AS bytes,
41+
SYS_EXTRACT_UTC(localtimestamp) AS updated_at
42+
FROM
43+
(
44+
SELECT
45+
id AS rse_id
46+
FROM
47+
{schema}rses
48+
WHERE
49+
deleted=0) a
50+
LEFT OUTER JOIN
51+
(
52+
SELECT
53+
/*+ INDEX_FFS(replicas REPLICAS_TOMBSTONE_IDX) */
54+
rse_id,
55+
COUNT(1) AS files,
56+
SUM(bytes) AS bytes
57+
FROM
58+
{schema}replicas
59+
WHERE
60+
(
61+
CASE
62+
WHEN tombstone IS NOT NULL
63+
THEN rse_id
64+
END) IS NOT NULL
65+
AND tombstone=to_date('1-1-1970 00:00:00','MM-DD-YYYY HH24:Mi:SS')
66+
GROUP BY
67+
rse_id) b
68+
ON
69+
a.rse_id=b.rse_id)
6170
62-
LOOP
63-
MERGE INTO atlas_rucio.RSE_USAGE
64-
USING DUAL
65-
ON (atlas_rucio.RSE_USAGE.rse_id = u.rse_id and source = 'obsolete')
66-
WHEN NOT MATCHED THEN INSERT(rse_id, source, used, files, updated_at, created_at)
67-
VALUES (u.rse_id, 'obsolete', u.bytes, u.files, u.updated_at, u.updated_at)
68-
WHEN MATCHED THEN UPDATE SET used=u.bytes, files=u.files, updated_at=u.updated_at;
71+
LOOP
72+
MERGE INTO {schema}RSE_USAGE
73+
USING DUAL
74+
ON ({schema}RSE_USAGE.rse_id = u.rse_id and source = 'obsolete')
75+
WHEN NOT MATCHED THEN INSERT(rse_id, source, used, files, updated_at, created_at)
76+
VALUES (u.rse_id, 'obsolete', u.bytes, u.files, u.updated_at, u.updated_at)
77+
WHEN MATCHED THEN UPDATE SET used=u.bytes, files=u.files, updated_at=u.updated_at;
6978
70-
MERGE INTO ATLAS_RUCIO.RSE_USAGE_HISTORY H
71-
USING DUAL
72-
ON (h.rse_id = u.rse_id and h.source = 'obsolete' and h.updated_at = u.updated_at)
73-
WHEN NOT MATCHED THEN INSERT(rse_id, source, used, files, updated_at, created_at)
74-
VALUES (u.rse_id, 'obsolete', u.bytes, u.files, u.updated_at, u.updated_at);
79+
MERGE INTO {schema}RSE_USAGE_HISTORY H
80+
USING DUAL
81+
ON (h.rse_id = u.rse_id and h.source = 'obsolete' and h.updated_at = u.updated_at)
82+
WHEN NOT MATCHED THEN INSERT(rse_id, source, used, files, updated_at, created_at)
83+
VALUES (u.rse_id, 'obsolete', u.bytes, u.files, u.updated_at, u.updated_at);
7584
76-
COMMIT;
77-
END LOOP;
78-
END;
79-
'''
80-
SESSION.execute(QUERY)
81-
except Exception as error:
82-
print error
85+
COMMIT;
86+
END LOOP;
87+
END;'''.format(schema=schema)
88+
89+
for result in session.execute(text(query)):
90+
print(result)
91+
92+
rse_id = result[0]
93+
bytes_sum = result[2]
94+
files_count = result[3]
95+
96+
manager.gauge(name="obsolete_replicas_files.{rse}",
97+
documentation="Probe to check the backlog of obsolete replicas.").labels(rse=rse_id).set(files_count)
98+
99+
manager.gauge(name="obsolete_replicas_bytes.{rse}",
100+
documentation="Probe to check the backlog of obsolete replicas.").labels().set(bytes_sum)
101+
102+
103+
except:
104+
print(traceback.format_exc())
83105
sys.exit(UNKNOWN)
106+
finally:
107+
session.remove()
84108
sys.exit(OK)

common/check_stuck_rules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ if __name__ == "__main__":
4444
with PrometheusPusher() as manager:
4545
for source_status, query in queries.items():
4646
result = session.execute(sql_text(query)).fetchone()[0]
47-
manager.gauge(
48-
"stuck_rules.{source_status}",
49-
documentation="Backlog of stuck rules").labels(source_status=source_status).set(result)
47+
manager.gauge("stuck_rules.{source_status}",
48+
documentation="Backlog of stuck rules"
49+
).labels(source_status=source_status).set(result)
5050

5151
except:
5252
print(traceback.format_exc())

common/check_transfer_queues_status

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ if __name__ == "__main__":
6969
activity = items[3]
7070
external_host = items[4]
7171

72-
manager.gauge("transfer_queues_status.{activity}.{state}.{external_host}").labels(activity=activity, state=state, external_host=external_host).set(count)
72+
manager.gauge(
73+
"transfer_queues_status.{activity}.{state}.{external_host}"
74+
).labels(activity=activity, state=state, external_host=external_host).set(count)
7375

7476
except Exception as e:
7577
print(f"Error: {e}")

common/check_unlocked_replicas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ if __name__ == "__main__":
4141
}
4242

4343
with PrometheusPusher() as manager:
44-
for did_status, query in queries.items():
44+
for replica_status, query in queries.items():
4545
result = session.execute(sql_text(query)).fetchone()[0]
46-
manager.gauge("unlocked_dids.{did_status}").labels(did_status=did_status).set(result)
46+
manager.gauge("unlocked_replicas.{replica_status}").labels(did_status=replica_status).set(result)
4747

4848
except:
4949
sys.exit(UNKNOWN)

0 commit comments

Comments
 (0)