opensearch-project / opensearch-py

Python Client for OpenSearch
https://opensearch.org/docs/latest/clients/python/
Apache License 2.0
338 stars 170 forks source link

`Service Time` measurement Trail_Approach_1 #679

Closed saimedhi closed 6 months ago

saimedhi commented 7 months ago

Description

Issues Resolved

Related to #678

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. For more information on following Developer Certificate of Origin and signing off your commits, please check here.

saimedhi commented 7 months ago

Sample usage

host = 'localhost'
port = 9200
auth = ('admin', 'admin') # For testing only. Don't store credentials in code.

client = OpenSearch(
    hosts = [{'host': host, 'port': port}],
    http_auth = auth,
    use_ssl = True,
    verify_certs = False,
    connection_class = RequestsHttpConnection,
    calculate_service_time = True,
)

client.info()

{'name': 'c3b344c0372b', 'cluster_name': 'docker-cluster', 'cluster_uuid': 'f6p2z4YRQvGW8nknOPgPeg', 'version': {'distribution': 'opensearch', 'number': '2.11.1', 'build_type': 'tar', 'build_hash': '6b1986e964d440be9137eba1413015c31c5a7752', 'build_date': '2023-11-29T21:45:35.524809067Z', 'build_snapshot': False, 'lucene_version': '9.7.0', 'minimum_wire_compatibility_version': '7.10.0', 'minimum_index_compatibility_version': '7.0.0'}, 'tagline': 'The OpenSearch Project: https://opensearch.org/', '__client': {'Service_Time': '0.43622279167175293'}}

codecov[bot] commented 7 months ago

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (4b69c09) 72.14% compared to head (921cd55) 72.13%.

Files Patch % Lines
opensearchpy/connection/http_requests.py 62.50% 3 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #679 +/- ## ========================================== - Coverage 72.14% 72.13% -0.02% ========================================== Files 89 89 Lines 7945 7952 +7 ========================================== + Hits 5732 5736 +4 - Misses 2213 2216 +3 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

dblock commented 7 months ago

This is a good start and shows what we're trying to achieve.

What do you think about an idea where we first expose "events", then add "metrics"? Googling I found https://stackoverflow.com/questions/443885/python-callbacks-delegates-what-is-common and https://pypi.org/project/Events/ that could be a start. The client could expose events such as "request started", "finished", "errored", etc., and then another class called Metrics or Measurements could collect time information using this event system.