forked from opensearch-project/opensearch-py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced metrics to opensearch-py client
Signed-off-by: saimedhi <[email protected]>
- Loading branch information
Showing
8 changed files
with
161 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# The OpenSearch Contributors require contributions made to | ||
# this file be licensed under the Apache-2.0 license or a | ||
# compatible open source license. | ||
# | ||
# Modifications Copyright OpenSearch Contributors. See | ||
# GitHub history for details. | ||
|
||
|
||
import time | ||
from abc import ABC, abstractmethod, abstractproperty | ||
|
||
from events import Events | ||
|
||
|
||
class Metrics(ABC): | ||
@abstractmethod | ||
def request_start(self) -> None: | ||
pass | ||
|
||
@abstractmethod | ||
def request_end(self) -> None: | ||
pass | ||
|
||
|
||
class MetricsEvents(Metrics): | ||
def __init__(self) -> None: | ||
self.events = Events() | ||
self.service_time = 0.0 | ||
|
||
# Subscribe to the request_start and request_end events | ||
self.events.request_start += self._on_request_start | ||
self.events.request_end += self._on_request_end | ||
|
||
def request_start(self) -> None: | ||
self.events.request_start() | ||
|
||
def _on_request_start(self) -> None: | ||
self.start_time = time.perf_counter() | ||
|
||
def request_end(self) -> None: | ||
self.events.request_end() | ||
|
||
def _on_request_end(self) -> None: | ||
self.end_time = time.perf_counter() | ||
self.service_time = self.end_time - self.start_time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters