Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
StTysh committed Oct 31, 2024
1 parent fcf1c26 commit d689aa2
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 322 deletions.
10 changes: 1 addition & 9 deletions docs/autoapi/jasmin_metrics_client/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,13 @@ jasmin_metrics_client



Subpackages
-----------

.. toctree::
:maxdepth: 1

/autoapi/jasmin_metrics_client/tests/index


Submodules
----------

.. toctree::
:maxdepth: 1

/autoapi/jasmin_metrics_client/main/index
/autoapi/jasmin_metrics_client/tests/index


6 changes: 0 additions & 6 deletions docs/autoapi/jasmin_metrics_client/main/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ Module Contents

.. py:class:: MetricsClient(token: Optional[str] = None)
.. py:attribute:: hosts
.. py:attribute:: kwargs
.. py:method:: get_all_metrics() -> Optional[List[str]]
Retrieve all unique metric names from the Elasticsearch index.
Expand Down
4 changes: 2 additions & 2 deletions docs/autoapi/jasmin_metrics_client/tests/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ jasmin_metrics_client.tests
.. py:module:: jasmin_metrics_client.tests
Subpackages
-----------
Submodules
----------

.. toctree::
:maxdepth: 1
Expand Down
28 changes: 15 additions & 13 deletions jasmin_metrics_client/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any, Dict, List, Optional, Union

import pandas as pd
from elasticsearch import Elasticsearch, ElasticsearchException
from elasticsearch import Elasticsearch, ElasticsearchWarning


class MetricsClient:
Expand All @@ -15,20 +15,22 @@ def __init__(self, token: Optional[str] = None) -> None:
token (Optional[str]): The authentication token. Defaults to None.
"""
hosts = [f"es{i}.ceda.ac.uk:9200" for i in range(1, 9)]
kwargs = {"hosts": hosts, "use_ssl": True, "ca_certs": "path/to/CA_ROOT"}
if token:
kwargs["headers"] = {"Authorization": f"Bearer {token}"}
else:

# Define headers if token is provided
headers = {"Authorization": f"Bearer {token}"} if token else {}

if not token:
logging.error("No authentication token provided.")

try:
# Initialize the Elasticsearch client without the `use_ssl` parameter
self.es = Elasticsearch(
hosts=kwargs.get("hosts"),
use_ssl=kwargs.get("use_ssl"),
ca_certs=kwargs.get("ca_certs"),
headers=kwargs.get("headers", {}),
hosts=hosts,
headers=headers,
# ca_certs="path/to/CA_ROOT"
)
logging.info("Elasticsearch client initialized successfully.")
except ElasticsearchException as e:
except ElasticsearchWarning as e:
logging.error(f"Error initializing Elasticsearch client: {str(e)}")
raise e
except Exception as e:
Expand Down Expand Up @@ -58,7 +60,7 @@ def get_all_metrics(self) -> Optional[List[str]]:
response = None
try:
response = self.es.search(index="jasmin-metrics-production", query=query)
except ElasticsearchException as e:
except ElasticsearchWarning as e:
logging.error(f"Error fetching all metrics: {str(e)}")
return None
except Exception as e:
Expand Down Expand Up @@ -95,7 +97,7 @@ def get_metric_labels(self, metric_name: str) -> Optional[List[str]]:
try:
response = self.es.search(index="jasmin-metrics-production", query=query)

except ElasticsearchException as e:
except ElasticsearchWarning as e:
logging.error(f"Error fetching metric labels for {metric_name}: {str(e)}")
return None

Expand Down Expand Up @@ -131,7 +133,7 @@ def get_metric(
response = None
try:
response = self.es.search(index="jasmin-metrics-production", query=query)
except ElasticsearchException as e:
except ElasticsearchWarning as e:
logging.error(f"Error fetching metric {metric_name}: {str(e)}")
return None
except Exception as e:
Expand Down
Loading

0 comments on commit d689aa2

Please sign in to comment.