Skip to content

Commit 7688769

Browse files
committed
feat: enrich WMSHistory with sites metadata
1 parent d32b8cb commit 7688769

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

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: 30 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,8 @@ def execute(self):
131134

132135
for backend in self.datastores:
133136
if backend.lower() == "monitoring":
137+
rD["Tier"] = site_metadata["Tier"]
138+
rD["Type"] = site_metadata["Type"]
134139
rD["timestamp"] = int(TimeUtilities.toEpochMilliSeconds(now))
135140
self.datastores["Monitoring"].addRecord(rD)
136141

@@ -154,3 +159,27 @@ def execute(self):
154159
self.log.verbose(f"Done committing WMSHistory to {backend} backend")
155160

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