Skip to content

Commit

Permalink
added configs to tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Avi-Robusta committed Jan 15, 2025
1 parent de66a4a commit 18ec9af
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
18 changes: 10 additions & 8 deletions holmes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from holmes.utils.pydantic_utils import RobustaBaseConfig, load_model_from_file
from holmes.utils.definitions import CUSTOM_TOOLSET_LOCATION
from pydantic import ValidationError
from holmes.utils.holmes_sync_toolsets import load_custom_toolsets_config, merge_and_override_bultin_toolsets_with_toolsets_config
from holmes.utils.holmes_sync_toolsets import load_custom_toolsets_config, merge_and_override_bultin_toolsets_with_toolsets_config, extract_config_from_custom_toolsets_config
from holmes.core.tools import YAMLToolset
from holmes.common.env_vars import ROBUSTA_CONFIG_PATH
from holmes.utils.definitions import RobustaConfig
Expand Down Expand Up @@ -113,13 +113,15 @@ def load_from_env(cls):
if val is not None:
kwargs[field_name] = val
kwargs["cluster_name"] = Config.__get_cluster_name()
try:
if os.path.exists(DEFAULT_CONFIG_LOCATION):
logging.info(f"Loading config from file with {len(kwargs)} addional params from env")
return cls.load_from_file(config_file=DEFAULT_CONFIG_LOCATION, **kwargs)
except:
logging.exception("Failed to load config from secret, falling back to loading config from env vars")
return cls(**kwargs)
configs = extract_config_from_custom_toolsets_config()
combined = {}
for item in configs:
if isinstance(item, dict):
for key, value in item.items():
combined[key] = value
combined.update(kwargs)
logging.warning(combined)
return cls(**combined)

@staticmethod
def __get_cluster_name() -> Optional[str]:
Expand Down
3 changes: 2 additions & 1 deletion holmes/core/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import shlex
import subprocess
import tempfile
from typing import Dict, List, Literal, Optional, Union
from typing import Dict, List, Literal, Optional, Union, Any
from enum import Enum
from datetime import datetime

Expand Down Expand Up @@ -412,6 +412,7 @@ class ToolsetYamlFromConfig(Toolset):
docs_url: Optional[str] = None
icon_url: Optional[str] = None
installation_instructions: Optional[str] = None
config: Optional[Any] = None


class ToolsetDBModel(BaseModel):
Expand Down
7 changes: 4 additions & 3 deletions holmes/plugins/toolsets/opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ class OpenSearchClient:
def __init__(self, **kwargs):

# Handle http_auth explicitly
http_auth = kwargs.pop("http_auth")
if isinstance(http_auth, dict):
kwargs["http_auth"] = (http_auth.get("username"), http_auth.get("password"))
if "http_auth" in kwargs:
http_auth = kwargs.pop("http_auth")
if isinstance(http_auth, dict):
kwargs["http_auth"] = (http_auth.get("username"), http_auth.get("password"))
# Initialize OpenSearch client
self.client = OpenSearch(**kwargs)

Expand Down
14 changes: 14 additions & 0 deletions holmes/utils/holmes_sync_toolsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ def load_custom_toolsets_config() -> list[ToolsetYamlFromConfig]:
logging.error(f"Toolset '{name}' is invalid: {e}")
return loaded_toolsets

def extract_config_from_custom_toolsets_config():
configs = []
if os.path.isfile(CUSTOM_TOOLSET_LOCATION):
with open(CUSTOM_TOOLSET_LOCATION) as file:
parsed_yaml = yaml.safe_load(file)
toolsets = parsed_yaml.get("toolsets", {})
for name, config in toolsets.items():
try:
validated_config = ToolsetYamlFromConfig(**config, name=name)
if validated_config.config:
configs.append(validated_config.config)
except ValidationError as e:
logging.error(f"Toolset '{name}' is invalid: {e}")
return configs

def merge_and_override_bultin_toolsets_with_toolsets_config(
toolsets_loaded_from_config: list[ToolsetYamlFromConfig],
Expand Down

0 comments on commit 18ec9af

Please sign in to comment.