Skip to content

Commit

Permalink
fix: ping command argument parsing and service uptime wrong calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
chaen committed Dec 7, 2023
1 parent b1f5e2b commit 6aa0ada
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/DIRAC/Core/DISET/RequestHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def export_ping(self):
startTime = self.serviceInfoDict["serviceStartTime"]
dInfo["service start time"] = self.serviceInfoDict["serviceStartTime"]
serviceUptime = datetime.datetime.utcnow() - startTime
dInfo["service uptime"] = serviceUptime.days * 3600 + serviceUptime.seconds
dInfo["service uptime"] = int(serviceUptime.total_seconds())
# Load average
dInfo["load"] = " ".join([str(lx) for lx in os.getloadavg()])
dInfo["name"] = self.serviceInfoDict["serviceName"]
Expand Down
2 changes: 1 addition & 1 deletion src/DIRAC/Core/Tornado/Server/TornadoService.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def export_ping(self):
startTime = self._startTime
dInfo["service start time"] = self._startTime
serviceUptime = datetime.utcnow() - startTime
dInfo["service uptime"] = serviceUptime.days * 3600 + serviceUptime.seconds
dInfo["service uptime"] = int(serviceUptime.total_seconds())
# Load average
try:
with open("/proc/loadavg") as oFD:
Expand Down
10 changes: 7 additions & 3 deletions src/DIRAC/Interfaces/API/Dirac.py
Original file line number Diff line number Diff line change
Expand Up @@ -2410,7 +2410,7 @@ def peekJob(self, jobID, printOutput=False):

#############################################################################

def pingService(self, system, service, printOutput=False, url=None):
def pingService(self, system=None, service=None, printOutput=False, url=None):
"""The ping function will attempt to return standard information from a system
service if this is available. If the ping() command is unsuccessful it could
indicate a period of service unavailability.
Expand All @@ -2430,8 +2430,7 @@ def pingService(self, system, service, printOutput=False, url=None):
:type url: string
:returns: S_OK,S_ERROR
"""

if not isinstance(system, str) and isinstance(service, str) and not isinstance(url, str):
if not (system and service) and not url:
return self._errorReport("Expected string for system and service or a url to ping()")
result = S_ERROR()
try:
Expand All @@ -2446,9 +2445,14 @@ def pingService(self, system, service, printOutput=False, url=None):
else:
serviceURL = url
client = Client(url=url)

startTime = time.time()
result = client.ping()
roudtrip_time = time.time() - startTime
if result["OK"]:
result["Value"]["service url"] = serviceURL
result["Value"]["roundtrip_time"] = roudtrip_time

except Exception as x:
self.log.warn(f"ping for {system}/{service} failed with exception:\n{str(x)}")
result["Message"] = str(x)
Expand Down

0 comments on commit 6aa0ada

Please sign in to comment.