Skip to content

Commit 6aa0ada

Browse files
committed
fix: ping command argument parsing and service uptime wrong calculation
1 parent b1f5e2b commit 6aa0ada

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/DIRAC/Core/DISET/RequestHandler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ def export_ping(self):
500500
startTime = self.serviceInfoDict["serviceStartTime"]
501501
dInfo["service start time"] = self.serviceInfoDict["serviceStartTime"]
502502
serviceUptime = datetime.datetime.utcnow() - startTime
503-
dInfo["service uptime"] = serviceUptime.days * 3600 + serviceUptime.seconds
503+
dInfo["service uptime"] = int(serviceUptime.total_seconds())
504504
# Load average
505505
dInfo["load"] = " ".join([str(lx) for lx in os.getloadavg()])
506506
dInfo["name"] = self.serviceInfoDict["serviceName"]

src/DIRAC/Core/Tornado/Server/TornadoService.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def export_ping(self):
193193
startTime = self._startTime
194194
dInfo["service start time"] = self._startTime
195195
serviceUptime = datetime.utcnow() - startTime
196-
dInfo["service uptime"] = serviceUptime.days * 3600 + serviceUptime.seconds
196+
dInfo["service uptime"] = int(serviceUptime.total_seconds())
197197
# Load average
198198
try:
199199
with open("/proc/loadavg") as oFD:

src/DIRAC/Interfaces/API/Dirac.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,7 +2410,7 @@ def peekJob(self, jobID, printOutput=False):
24102410

24112411
#############################################################################
24122412

2413-
def pingService(self, system, service, printOutput=False, url=None):
2413+
def pingService(self, system=None, service=None, printOutput=False, url=None):
24142414
"""The ping function will attempt to return standard information from a system
24152415
service if this is available. If the ping() command is unsuccessful it could
24162416
indicate a period of service unavailability.
@@ -2430,8 +2430,7 @@ def pingService(self, system, service, printOutput=False, url=None):
24302430
:type url: string
24312431
:returns: S_OK,S_ERROR
24322432
"""
2433-
2434-
if not isinstance(system, str) and isinstance(service, str) and not isinstance(url, str):
2433+
if not (system and service) and not url:
24352434
return self._errorReport("Expected string for system and service or a url to ping()")
24362435
result = S_ERROR()
24372436
try:
@@ -2446,9 +2445,14 @@ def pingService(self, system, service, printOutput=False, url=None):
24462445
else:
24472446
serviceURL = url
24482447
client = Client(url=url)
2448+
2449+
startTime = time.time()
24492450
result = client.ping()
2451+
roudtrip_time = time.time() - startTime
24502452
if result["OK"]:
24512453
result["Value"]["service url"] = serviceURL
2454+
result["Value"]["roundtrip_time"] = roudtrip_time
2455+
24522456
except Exception as x:
24532457
self.log.warn(f"ping for {system}/{service} failed with exception:\n{str(x)}")
24542458
result["Message"] = str(x)

0 commit comments

Comments
 (0)