Skip to content

Commit

Permalink
Opensearch on server
Browse files Browse the repository at this point in the history
  • Loading branch information
moshemorad committed Jan 22, 2025
1 parent 24c9fe5 commit 9a603c0
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions holmes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,7 @@ def load_from_env(cls):
if val is not None:
kwargs[field_name] = val
kwargs["cluster_name"] = Config.__get_cluster_name()
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)
return cls(**combined)
return cls(**kwargs)

@staticmethod
def __get_cluster_name() -> Optional[str]:
Expand Down Expand Up @@ -196,35 +189,35 @@ def create_console_tool_executor(
for toolset in matching_toolsets:
toolset.enabled = True

matched_default_toolsets_by_name = {
toolsets_by_name = {
toolset.name: toolset for toolset in matching_toolsets
}

toolsets_loaded_from_config = self.load_custom_toolsets_config()
if toolsets_loaded_from_config:
matched_default_toolsets_by_name = (
toolsets_by_name = (
self.merge_and_override_bultin_toolsets_with_toolsets_config(
toolsets_loaded_from_config,
matched_default_toolsets_by_name,
toolsets_by_name,
)
)

if self.toolsets:
loaded_toolsets_from_env = self.load_toolsets_config(self.toolsets, "env")
if loaded_toolsets_from_env:
matched_default_toolsets_by_name = (
toolsets_by_name = (
self.merge_and_override_bultin_toolsets_with_toolsets_config(
loaded_toolsets_from_env,
matched_default_toolsets_by_name,
toolsets_by_name,
)
)

for toolset in matched_default_toolsets_by_name.values():
for toolset in toolsets_by_name.values():
if toolset.enabled:
toolset.check_prerequisites()

enabled_toolsets = []
for ts in matched_default_toolsets_by_name.values():
for ts in toolsets_by_name.values():
if ts.get_status() == ToolsetStatusEnum.ENABLED:
enabled_toolsets.append(ts)
logging.info(f"Loaded toolset {ts.name} from {ts.get_path()}")
Expand All @@ -236,7 +229,7 @@ def create_console_tool_executor(
)

for ts in default_toolsets:
if ts.name not in matched_default_toolsets_by_name.keys():
if ts.name not in toolsets_by_name.keys():
logging.debug(
f"Toolset {ts.name} from {ts.get_path()} was filtered out due to allowed_toolsets value"
)
Expand All @@ -252,24 +245,32 @@ def create_tool_executor(self, dal: Optional[SupabaseDal]) -> ToolExecutor:
Creates ToolExecutor for the server endpoints
"""

all_toolsets = load_builtin_toolsets(
dal=dal, opensearch_clusters=self.opensearch_clusters
)
all_toolsets = load_builtin_toolsets(dal=dal)

toolsets_by_name: dict[str, Toolset] = {
toolset.name: toolset for toolset in all_toolsets
}

toolsets_loaded_from_config = self.load_custom_toolsets_config()
if toolsets_loaded_from_config:
merged_toolsets_by_name: Dict[str, Toolset] = (
toolsets_by_name: Dict[str, Toolset] = (
self.merge_and_override_bultin_toolsets_with_toolsets_config(
toolsets_loaded_from_config,
toolsets_by_name,
)
)

toolsets: list[Toolset] = list(merged_toolsets_by_name.values())
if self.toolsets:
loaded_toolsets_from_env = self.load_toolsets_config(self.toolsets, "env")
if loaded_toolsets_from_env:
toolsets_by_name = (
self.merge_and_override_bultin_toolsets_with_toolsets_config(
loaded_toolsets_from_env,
toolsets_by_name,
)
)

toolsets: list[Toolset] = list(toolsets_by_name.values())

for toolset in toolsets:
if toolset.enabled:
Expand Down Expand Up @@ -448,7 +449,9 @@ def load_toolsets_config(
)
validated_config.set_path(path)
if validated_config.config:
validated_config.config = replace_env_vars_values(validated_config.config)
validated_config.config = replace_env_vars_values(
validated_config.config
)
loaded_toolsets.append(validated_config)
except ValidationError as e:
logging.error(f"Toolset '{name}' is invalid: {e}")
Expand Down

0 comments on commit 9a603c0

Please sign in to comment.