Skip to content

Commit

Permalink
Introduced service time metrics to OpenSearch-Py client.
Browse files Browse the repository at this point in the history
Signed-off-by: saimedhi <saimedhi@amazon.com>
  • Loading branch information
saimedhi committed Mar 6, 2024
1 parent 3dca007 commit 97135a2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions opensearchpy/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@


class TimeMetrics:
def __init__(self):
def __init__(self) -> None:
self.events = Events()
self.start_time = 0
self.end_time = 0
self.service_time = 0
self.start_time = None
self.end_time = None
self.service_time = None

# Subscribe to the server_request_start and server_request_end events
self.events.server_request_start += self.server_request_start
self.events.server_request_end += self.server_request_end

def server_request_start(self):
def server_request_start(self) -> None:
self.start_time = time.perf_counter()

def server_request_end(self):
def server_request_end(self) -> None:
self.end_time = time.perf_counter()
self.service_time = self.end_time - self.start_time

0 comments on commit 97135a2

Please sign in to comment.