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 service time metrics to OpenSearch-Py client. (opensearch-…
…project#716) * Introduced service time metrics to opensearch-py client Signed-off-by: saimedhi <[email protected]> * Introduced service time metrics to opensearch-py client Signed-off-by: saimedhi <[email protected]> * Introduced service time metrics to opensearch-py client Signed-off-by: saimedhi <[email protected]> * Added service time metrics Signed-off-by: saimedhi <[email protected]> --------- Signed-off-by: saimedhi <[email protected]> Signed-off-by: Sai Medhini Reddy Maryada <[email protected]>
- Loading branch information
Showing
13 changed files
with
336 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ sphinx_rtd_theme | |
jinja2 | ||
pytz | ||
deepmerge | ||
Events | ||
setuptools | ||
|
||
# No wheels for Python 3.10 yet! | ||
|
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,14 @@ | ||
# metrics | ||
|
||
```{eval-rst} | ||
.. autoclass:: opensearchpy.Metrics | ||
``` | ||
|
||
```{eval-rst} | ||
.. autoclass:: opensearchpy.MetricsEvents | ||
``` | ||
|
||
```{eval-rst} | ||
.. autoclass:: opensearchpy.MetricsNone | ||
``` | ||
|
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,18 @@ | ||
# 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. | ||
|
||
from .metrics import Metrics | ||
from .metrics_events import MetricsEvents | ||
from .metrics_none import MetricsNone | ||
|
||
__all__ = [ | ||
"Metrics", | ||
"MetricsEvents", | ||
"MetricsNone", | ||
] |
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,42 @@ | ||
# 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. | ||
|
||
from abc import ABC, abstractmethod | ||
from typing import Optional | ||
|
||
|
||
class Metrics(ABC): | ||
""" | ||
The Metrics class defines methods and properties for managing | ||
request metrics, including start time, end time, and service time, | ||
serving as a blueprint for concrete implementations. | ||
""" | ||
|
||
@abstractmethod | ||
def request_start(self) -> None: | ||
pass | ||
|
||
@abstractmethod | ||
def request_end(self) -> None: | ||
pass | ||
|
||
@property | ||
@abstractmethod | ||
def start_time(self) -> Optional[float]: | ||
pass | ||
|
||
@property | ||
@abstractmethod | ||
def end_time(self) -> Optional[float]: | ||
pass | ||
|
||
@property | ||
@abstractmethod | ||
def service_time(self) -> Optional[float]: | ||
pass |
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,61 @@ | ||
# 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 typing import Optional | ||
|
||
from events import Events | ||
|
||
from opensearchpy.metrics.metrics import Metrics | ||
|
||
|
||
class MetricsEvents(Metrics): | ||
""" | ||
The MetricsEvents class implements the Metrics abstract base class | ||
and tracks metrics such as start time, end time, and service time | ||
during request processing. | ||
""" | ||
|
||
@property | ||
def start_time(self) -> Optional[float]: | ||
return self._start_time | ||
|
||
@property | ||
def end_time(self) -> Optional[float]: | ||
return self._end_time | ||
|
||
@property | ||
def service_time(self) -> Optional[float]: | ||
return self._service_time | ||
|
||
def __init__(self) -> None: | ||
self.events = Events() | ||
self._start_time: Optional[float] = None | ||
self._end_time: Optional[float] = None | ||
self._service_time: Optional[float] = None | ||
|
||
# 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() | ||
self._end_time = None | ||
self._service_time = None | ||
|
||
def request_end(self) -> None: | ||
self.events.request_end() | ||
|
||
def _on_request_end(self) -> None: | ||
self._end_time = time.perf_counter() | ||
if self._start_time is not None: | ||
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
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. | ||
|
||
from typing import Optional | ||
|
||
from opensearchpy.metrics.metrics import Metrics | ||
|
||
|
||
class MetricsNone(Metrics): | ||
""" | ||
Default metrics class. It sets the start time, end time, and service time to None. | ||
""" | ||
|
||
@property | ||
def start_time(self) -> Optional[float]: | ||
return self._start_time | ||
|
||
@property | ||
def end_time(self) -> Optional[float]: | ||
return self._end_time | ||
|
||
@property | ||
def service_time(self) -> Optional[float]: | ||
return self._service_time | ||
|
||
def __init__(self) -> None: | ||
self._start_time: Optional[float] = None | ||
self._end_time: Optional[float] = None | ||
self._service_time: Optional[float] = None | ||
|
||
# request_start and request_end are placeholders, | ||
# not implementing actual metrics collection in this subclass. | ||
|
||
def request_start(self) -> None: | ||
self._start_time = None | ||
self._end_time = None | ||
self._service_time = None | ||
|
||
def request_end(self) -> None: | ||
self._end_time = None | ||
self._service_time = None |
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
Oops, something went wrong.