Skip to content

Commit ac462ef

Browse files
committed
feat: enrich WMSHistory with sites metadata
1 parent f6d1af3 commit ac462ef

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/DIRAC/MonitoringSystem/Client/Types/WMSHistory.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def __init__(self):
3030
"MinorStatus",
3131
"ApplicationStatus",
3232
"JobSplitType",
33+
"Tier",
34+
"Type",
3335
]
3436

3537
self.monitoringFields = ["Jobs", "Reschedules"]
@@ -46,6 +48,8 @@ def __init__(self):
4648
"User": {"type": "keyword"},
4749
"JobGroup": {"type": "keyword"},
4850
"UserGroup": {"type": "keyword"},
51+
"Tier": {"type": "keyword"},
52+
"Type": {"type": "keyword"},
4953
}
5054
)
5155
# {'timestamp': {'type': 'date'}} will be added for all monitoring types

src/DIRAC/WorkloadManagementSystem/Agent/StatesAccountingAgent.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
"""
1010
import datetime
1111

12-
from DIRAC import S_ERROR, S_OK
12+
from DIRAC import S_ERROR, S_OK, gConfig
1313
from DIRAC.AccountingSystem.Client.DataStoreClient import DataStoreClient
1414
from DIRAC.AccountingSystem.Client.Types.WMSHistory import WMSHistory
1515
from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations
16+
from DIRAC.ConfigurationSystem.Client.Helpers.Resources import getSites
1617
from DIRAC.Core.Base.AgentModule import AgentModule
1718
from DIRAC.Core.Utilities import TimeUtilities
1819
from DIRAC.MonitoringSystem.Client.MonitoringReporter import MonitoringReporter
@@ -77,6 +78,8 @@ def initialize(self):
7778
def execute(self):
7879
"""Main execution method"""
7980

81+
site_metadata = self._getSitesMetadata()
82+
8083
# on the first iteration of the agent, do nothing in order to avoid double committing after a restart
8184
if self.am_getModuleParam("cyclesDone") == 0:
8285
self.log.notice("Skipping the first iteration of the agent")
@@ -131,6 +134,9 @@ def execute(self):
131134

132135
for backend in self.datastores:
133136
if backend.lower() == "monitoring":
137+
site_name = rD["Site"]
138+
rD["Tier"] = site_metadata[site_name]["Tier"]
139+
rD["Type"] = site_metadata[site_name]["Type"]
134140
rD["timestamp"] = int(TimeUtilities.toEpochMilliSeconds(now))
135141
self.datastores["Monitoring"].addRecord(rD)
136142

@@ -154,3 +160,30 @@ def execute(self):
154160
self.log.verbose(f"Done committing WMSHistory to {backend} backend")
155161

156162
return S_OK()
163+
164+
def _getSitesMetadata(self):
165+
"""Get the metadata for the sites"""
166+
res = getSites()
167+
if not res["OK"]:
168+
return res
169+
sites = res["Value"]
170+
site_metadata = {}
171+
172+
for site in sites:
173+
site_metadata[site] = {}
174+
175+
# Get the site metadata from the Configuration System
176+
grid = site.split(".")[0]
177+
res = gConfig.getOptionsDict(f"Resources/Sites/{grid}/{site}")
178+
if not res["OK"]:
179+
self.log.error("Failure getting options dict for site", f"{site}: {res['Message']}")
180+
continue
181+
siteInfoCS = res["Value"]
182+
183+
# The site tier is normally 1 or 2. Few VOs may define tier 3.
184+
# If the tier is not defined, we assume it is 4, with 4 meaning "not pledged" (opportunistic).
185+
site_metadata[site]["Tier"] = siteInfoCS.get("MoUTierLevel", "4")
186+
# The site type is defined by the first part of the site name.
187+
# It needs to be interpreted at the Monitoring side (e.g. in Grafana).
188+
site_metadata[site]["Type"] = site.split(".")[0]
189+
return site_metadata

tests/Integration/Monitoring/Test_MonitoringSystem.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def test_listUniqueKeyValues(putAndDelete):
8282
"User": [],
8383
"JobGroup": [],
8484
"UserGroup": [],
85+
"Tier": [],
86+
"Type": [],
8587
}
8688

8789

0 commit comments

Comments
 (0)