holmesgpt 0.13.3a0__py3-none-any.whl → 0.14.1a0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of holmesgpt might be problematic. Click here for more details.
- holmes/__init__.py +1 -1
- holmes/clients/robusta_client.py +10 -2
- holmes/common/env_vars.py +8 -1
- holmes/config.py +66 -139
- holmes/core/investigation.py +1 -2
- holmes/core/llm.py +256 -51
- holmes/core/models.py +2 -0
- holmes/core/safeguards.py +4 -4
- holmes/core/supabase_dal.py +14 -8
- holmes/core/tool_calling_llm.py +193 -176
- holmes/core/tools.py +260 -25
- holmes/core/tools_utils/data_types.py +81 -0
- holmes/core/tools_utils/tool_context_window_limiter.py +33 -0
- holmes/core/tools_utils/tool_executor.py +2 -2
- holmes/core/toolset_manager.py +150 -3
- holmes/core/tracing.py +6 -1
- holmes/core/transformers/__init__.py +23 -0
- holmes/core/transformers/base.py +62 -0
- holmes/core/transformers/llm_summarize.py +174 -0
- holmes/core/transformers/registry.py +122 -0
- holmes/core/transformers/transformer.py +31 -0
- holmes/main.py +5 -0
- holmes/plugins/toolsets/aks-node-health.yaml +46 -0
- holmes/plugins/toolsets/aks.yaml +64 -0
- holmes/plugins/toolsets/atlas_mongodb/mongodb_atlas.py +17 -15
- holmes/plugins/toolsets/azure_sql/tools/analyze_connection_failures.py +8 -4
- holmes/plugins/toolsets/azure_sql/tools/analyze_database_connections.py +7 -3
- holmes/plugins/toolsets/azure_sql/tools/analyze_database_health_status.py +3 -3
- holmes/plugins/toolsets/azure_sql/tools/analyze_database_performance.py +3 -3
- holmes/plugins/toolsets/azure_sql/tools/analyze_database_storage.py +7 -3
- holmes/plugins/toolsets/azure_sql/tools/get_active_alerts.py +4 -4
- holmes/plugins/toolsets/azure_sql/tools/get_slow_queries.py +7 -3
- holmes/plugins/toolsets/azure_sql/tools/get_top_cpu_queries.py +7 -3
- holmes/plugins/toolsets/azure_sql/tools/get_top_data_io_queries.py +7 -3
- holmes/plugins/toolsets/azure_sql/tools/get_top_log_io_queries.py +7 -3
- holmes/plugins/toolsets/bash/bash_toolset.py +6 -6
- holmes/plugins/toolsets/bash/common/bash.py +7 -7
- holmes/plugins/toolsets/coralogix/toolset_coralogix_logs.py +5 -3
- holmes/plugins/toolsets/datadog/toolset_datadog_general.py +16 -17
- holmes/plugins/toolsets/datadog/toolset_datadog_logs.py +9 -10
- holmes/plugins/toolsets/datadog/toolset_datadog_metrics.py +21 -22
- holmes/plugins/toolsets/datadog/toolset_datadog_rds.py +8 -8
- holmes/plugins/toolsets/datadog/toolset_datadog_traces.py +18 -19
- holmes/plugins/toolsets/git.py +22 -22
- holmes/plugins/toolsets/grafana/common.py +14 -2
- holmes/plugins/toolsets/grafana/grafana_tempo_api.py +473 -0
- holmes/plugins/toolsets/grafana/toolset_grafana.py +4 -4
- holmes/plugins/toolsets/grafana/toolset_grafana_loki.py +3 -3
- holmes/plugins/toolsets/grafana/toolset_grafana_tempo.jinja2 +246 -11
- holmes/plugins/toolsets/grafana/toolset_grafana_tempo.py +662 -290
- holmes/plugins/toolsets/grafana/trace_parser.py +1 -1
- holmes/plugins/toolsets/internet/internet.py +3 -3
- holmes/plugins/toolsets/internet/notion.py +3 -3
- holmes/plugins/toolsets/investigator/core_investigation.py +3 -3
- holmes/plugins/toolsets/kafka.py +18 -18
- holmes/plugins/toolsets/kubernetes.yaml +58 -0
- holmes/plugins/toolsets/kubernetes_logs.py +6 -6
- holmes/plugins/toolsets/kubernetes_logs.yaml +32 -0
- holmes/plugins/toolsets/mcp/toolset_mcp.py +4 -4
- holmes/plugins/toolsets/newrelic.py +8 -8
- holmes/plugins/toolsets/opensearch/opensearch.py +5 -5
- holmes/plugins/toolsets/opensearch/opensearch_logs.py +7 -7
- holmes/plugins/toolsets/opensearch/opensearch_traces.py +10 -10
- holmes/plugins/toolsets/prometheus/prometheus.py +172 -39
- holmes/plugins/toolsets/prometheus/prometheus_instructions.jinja2 +25 -0
- holmes/plugins/toolsets/prometheus/utils.py +28 -0
- holmes/plugins/toolsets/rabbitmq/toolset_rabbitmq.py +6 -4
- holmes/plugins/toolsets/robusta/robusta.py +10 -10
- holmes/plugins/toolsets/runbook/runbook_fetcher.py +4 -4
- holmes/plugins/toolsets/servicenow/servicenow.py +6 -6
- holmes/plugins/toolsets/utils.py +88 -0
- holmes/utils/config_utils.py +91 -0
- holmes/utils/env.py +7 -0
- holmes/utils/holmes_status.py +2 -1
- holmes/utils/sentry_helper.py +41 -0
- holmes/utils/stream.py +9 -0
- {holmesgpt-0.13.3a0.dist-info → holmesgpt-0.14.1a0.dist-info}/METADATA +10 -14
- {holmesgpt-0.13.3a0.dist-info → holmesgpt-0.14.1a0.dist-info}/RECORD +81 -71
- holmes/plugins/toolsets/grafana/tempo_api.py +0 -124
- {holmesgpt-0.13.3a0.dist-info → holmesgpt-0.14.1a0.dist-info}/LICENSE.txt +0 -0
- {holmesgpt-0.13.3a0.dist-info → holmesgpt-0.14.1a0.dist-info}/WHEEL +0 -0
- {holmesgpt-0.13.3a0.dist-info → holmesgpt-0.14.1a0.dist-info}/entry_points.txt +0 -0
|
@@ -1,55 +1,35 @@
|
|
|
1
1
|
import os
|
|
2
|
-
import
|
|
3
|
-
from typing import Any, Dict, List, cast
|
|
2
|
+
from typing import Any, Dict, Tuple, cast, List
|
|
4
3
|
|
|
5
|
-
import requests # type: ignore
|
|
6
4
|
import yaml # type: ignore
|
|
7
|
-
from pydantic import BaseModel
|
|
8
5
|
|
|
9
|
-
from holmes.common.env_vars import load_bool
|
|
6
|
+
from holmes.common.env_vars import load_bool, MAX_GRAPH_POINTS
|
|
10
7
|
from holmes.core.tools import (
|
|
11
8
|
StructuredToolResult,
|
|
12
9
|
Tool,
|
|
13
10
|
ToolParameter,
|
|
14
|
-
|
|
11
|
+
StructuredToolResultStatus,
|
|
15
12
|
)
|
|
13
|
+
from holmes.plugins.toolsets.consts import STANDARD_END_DATETIME_TOOL_PARAM_DESCRIPTION
|
|
16
14
|
from holmes.plugins.toolsets.grafana.base_grafana_toolset import BaseGrafanaToolset
|
|
17
15
|
from holmes.plugins.toolsets.grafana.common import (
|
|
18
|
-
|
|
19
|
-
build_headers,
|
|
20
|
-
get_base_url,
|
|
16
|
+
GrafanaTempoConfig,
|
|
21
17
|
)
|
|
22
|
-
from holmes.plugins.toolsets.grafana.
|
|
23
|
-
query_tempo_trace_by_id,
|
|
24
|
-
query_tempo_traces,
|
|
25
|
-
)
|
|
26
|
-
from holmes.plugins.toolsets.grafana.trace_parser import format_traces_list
|
|
18
|
+
from holmes.plugins.toolsets.grafana.grafana_tempo_api import GrafanaTempoAPI
|
|
27
19
|
from holmes.plugins.toolsets.logging_utils.logging_api import (
|
|
28
|
-
|
|
20
|
+
DEFAULT_GRAPH_TIME_SPAN_SECONDS,
|
|
29
21
|
)
|
|
30
22
|
from holmes.plugins.toolsets.utils import (
|
|
31
|
-
get_param_or_raise,
|
|
32
|
-
process_timestamps_to_int,
|
|
33
23
|
toolset_name_for_one_liner,
|
|
24
|
+
process_timestamps_to_int,
|
|
25
|
+
standard_start_datetime_tool_param_description,
|
|
26
|
+
adjust_step_for_max_points,
|
|
27
|
+
seconds_to_duration_string,
|
|
28
|
+
duration_string_to_seconds,
|
|
34
29
|
)
|
|
35
30
|
|
|
36
31
|
TEMPO_LABELS_ADD_PREFIX = load_bool("TEMPO_LABELS_ADD_PREFIX", True)
|
|
37
|
-
|
|
38
|
-
ONE_HOUR_IN_SECONDS = 3600
|
|
39
|
-
DEFAULT_TRACES_TIME_SPAN_SECONDS = DEFAULT_TIME_SPAN_SECONDS # 7 days
|
|
40
|
-
DEFAULT_TAGS_TIME_SPAN_SECONDS = 8 * ONE_HOUR_IN_SECONDS # 8 hours
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
class GrafanaTempoLabelsConfig(BaseModel):
|
|
44
|
-
pod: str = "k8s.pod.name"
|
|
45
|
-
namespace: str = "k8s.namespace.name"
|
|
46
|
-
deployment: str = "k8s.deployment.name"
|
|
47
|
-
node: str = "k8s.node.name"
|
|
48
|
-
service: str = "service.name"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
class GrafanaTempoConfig(GrafanaConfig):
|
|
52
|
-
labels: GrafanaTempoLabelsConfig = GrafanaTempoLabelsConfig()
|
|
32
|
+
TEMPO_API_USE_POST = False # Use GET method for direct API mapping
|
|
53
33
|
|
|
54
34
|
|
|
55
35
|
class BaseGrafanaTempoToolset(BaseGrafanaToolset):
|
|
@@ -67,6 +47,23 @@ class BaseGrafanaTempoToolset(BaseGrafanaToolset):
|
|
|
67
47
|
def grafana_config(self) -> GrafanaTempoConfig:
|
|
68
48
|
return cast(GrafanaTempoConfig, self._grafana_config)
|
|
69
49
|
|
|
50
|
+
def prerequisites_callable(self, config: dict[str, Any]) -> Tuple[bool, str]:
|
|
51
|
+
"""Check Tempo connectivity using the echo endpoint."""
|
|
52
|
+
# First call parent to validate config
|
|
53
|
+
success, msg = super().prerequisites_callable(config)
|
|
54
|
+
if not success:
|
|
55
|
+
return success, msg
|
|
56
|
+
|
|
57
|
+
# Then check Tempo-specific echo endpoint
|
|
58
|
+
try:
|
|
59
|
+
api = GrafanaTempoAPI(self.grafana_config, use_post=TEMPO_API_USE_POST)
|
|
60
|
+
if api.query_echo_endpoint():
|
|
61
|
+
return True, "Successfully connected to Tempo"
|
|
62
|
+
else:
|
|
63
|
+
return False, "Failed to connect to Tempo echo endpoint"
|
|
64
|
+
except Exception as e:
|
|
65
|
+
return False, f"Failed to connect to Tempo: {str(e)}"
|
|
66
|
+
|
|
70
67
|
def build_k8s_filters(
|
|
71
68
|
self, params: Dict[str, Any], use_exact_match: bool
|
|
72
69
|
) -> List[str]:
|
|
@@ -107,228 +104,25 @@ class BaseGrafanaTempoToolset(BaseGrafanaToolset):
|
|
|
107
104
|
escaped_value = value.replace('"', '\\"')
|
|
108
105
|
filters.append(f'{prefix}{label}="{escaped_value}"')
|
|
109
106
|
else:
|
|
110
|
-
#
|
|
111
|
-
|
|
112
|
-
filters.append(f'{prefix}{label}=~".*{
|
|
107
|
+
# For partial match, use simple substring matching
|
|
108
|
+
# Don't escape anything - let Tempo handle the regex
|
|
109
|
+
filters.append(f'{prefix}{label}=~".*{value}.*"')
|
|
113
110
|
|
|
114
111
|
return filters
|
|
115
112
|
|
|
116
|
-
|
|
117
|
-
def
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return f"At least one of the following argument is expected but none were set: {expected_params}"
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
class GetTempoTraces(Tool):
|
|
126
|
-
def __init__(self, toolset: BaseGrafanaTempoToolset):
|
|
127
|
-
super().__init__(
|
|
128
|
-
name="fetch_tempo_traces",
|
|
129
|
-
description="""Lists Tempo traces. At least one of `service_name`, `pod_name` or `deployment_name` argument is required.""",
|
|
130
|
-
parameters={
|
|
131
|
-
"min_duration": ToolParameter(
|
|
132
|
-
description="The minimum duration of traces to fetch, e.g., '5s' for 5 seconds.",
|
|
133
|
-
type="string",
|
|
134
|
-
required=True,
|
|
135
|
-
),
|
|
136
|
-
"service_name": ToolParameter(
|
|
137
|
-
description="Filter traces by service name",
|
|
138
|
-
type="string",
|
|
139
|
-
required=False,
|
|
140
|
-
),
|
|
141
|
-
"pod_name": ToolParameter(
|
|
142
|
-
description="Filter traces by pod name",
|
|
143
|
-
type="string",
|
|
144
|
-
required=False,
|
|
145
|
-
),
|
|
146
|
-
"namespace_name": ToolParameter(
|
|
147
|
-
description="Filter traces by namespace",
|
|
148
|
-
type="string",
|
|
149
|
-
required=False,
|
|
150
|
-
),
|
|
151
|
-
"deployment_name": ToolParameter(
|
|
152
|
-
description="Filter traces by deployment name",
|
|
153
|
-
type="string",
|
|
154
|
-
required=False,
|
|
155
|
-
),
|
|
156
|
-
"node_name": ToolParameter(
|
|
157
|
-
description="Filter traces by node",
|
|
158
|
-
type="string",
|
|
159
|
-
required=False,
|
|
160
|
-
),
|
|
161
|
-
"start_datetime": ToolParameter(
|
|
162
|
-
description=f"The beginning time boundary for the trace search period. String in RFC3339 format. If a negative integer, the number of seconds relative to the end_timestamp. Defaults to -{DEFAULT_TRACES_TIME_SPAN_SECONDS}",
|
|
163
|
-
type="string",
|
|
164
|
-
required=False,
|
|
165
|
-
),
|
|
166
|
-
"end_datetime": ToolParameter(
|
|
167
|
-
description="The ending time boundary for the trace search period. String in RFC3339 format. Defaults to NOW().",
|
|
168
|
-
type="string",
|
|
169
|
-
required=False,
|
|
170
|
-
),
|
|
171
|
-
"limit": ToolParameter(
|
|
172
|
-
description="Maximum number of traces to return. Defaults to 50",
|
|
173
|
-
type="string",
|
|
174
|
-
required=False,
|
|
175
|
-
),
|
|
176
|
-
"sort": ToolParameter(
|
|
177
|
-
description="One of 'descending', 'ascending' or 'none' for no sorting. Defaults to descending",
|
|
178
|
-
type="string",
|
|
179
|
-
required=False,
|
|
180
|
-
),
|
|
181
|
-
},
|
|
182
|
-
)
|
|
183
|
-
self._toolset = toolset
|
|
184
|
-
|
|
185
|
-
def _invoke(
|
|
186
|
-
self, params: dict, user_approved: bool = False
|
|
187
|
-
) -> StructuredToolResult:
|
|
188
|
-
api_key = self._toolset.grafana_config.api_key
|
|
189
|
-
headers = self._toolset.grafana_config.headers
|
|
190
|
-
|
|
191
|
-
invalid_params_error = validate_params(
|
|
192
|
-
params, ["service_name", "pod_name", "deployment_name"]
|
|
193
|
-
)
|
|
194
|
-
if invalid_params_error:
|
|
195
|
-
return StructuredToolResult(
|
|
196
|
-
status=ToolResultStatus.ERROR,
|
|
197
|
-
error=invalid_params_error,
|
|
198
|
-
params=params,
|
|
199
|
-
)
|
|
200
|
-
|
|
201
|
-
start, end = process_timestamps_to_int(
|
|
202
|
-
params.get("start_datetime"),
|
|
203
|
-
params.get("end_datetime"),
|
|
204
|
-
default_time_span_seconds=DEFAULT_TRACES_TIME_SPAN_SECONDS,
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
filters = self._toolset.build_k8s_filters(params, use_exact_match=True)
|
|
208
|
-
|
|
209
|
-
filters.append(f'duration>{get_param_or_raise(params, "min_duration")}')
|
|
210
|
-
|
|
211
|
-
query = " && ".join(filters)
|
|
212
|
-
query = f"{{{query}}}"
|
|
213
|
-
|
|
214
|
-
base_url = get_base_url(self._toolset.grafana_config)
|
|
215
|
-
traces = query_tempo_traces(
|
|
216
|
-
base_url=base_url,
|
|
217
|
-
api_key=api_key,
|
|
218
|
-
headers=headers,
|
|
219
|
-
query=query,
|
|
220
|
-
start=start,
|
|
221
|
-
end=end,
|
|
222
|
-
limit=params.get("limit", 50),
|
|
223
|
-
)
|
|
224
|
-
return StructuredToolResult(
|
|
225
|
-
status=ToolResultStatus.SUCCESS,
|
|
226
|
-
data=format_traces_list(traces),
|
|
227
|
-
params=params,
|
|
228
|
-
invocation=query,
|
|
113
|
+
@staticmethod
|
|
114
|
+
def adjust_start_end_time(params: Dict) -> Tuple[int, int]:
|
|
115
|
+
return process_timestamps_to_int(
|
|
116
|
+
start=params.get("start"),
|
|
117
|
+
end=params.get("end"),
|
|
118
|
+
default_time_span_seconds=DEFAULT_GRAPH_TIME_SPAN_SECONDS,
|
|
229
119
|
)
|
|
230
120
|
|
|
231
|
-
def get_parameterized_one_liner(self, params: Dict) -> str:
|
|
232
|
-
return f"{toolset_name_for_one_liner(self._toolset.name)}: Fetched Tempo Traces (min_duration={params.get('min_duration')})"
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
class GetTempoTags(Tool):
|
|
236
|
-
def __init__(self, toolset: BaseGrafanaTempoToolset):
|
|
237
|
-
super().__init__(
|
|
238
|
-
name="fetch_tempo_tags",
|
|
239
|
-
description="List the tags available in Tempo",
|
|
240
|
-
parameters={
|
|
241
|
-
"start_datetime": ToolParameter(
|
|
242
|
-
description=f"The beginning time boundary for the search period. String in RFC3339 format. If a negative integer, the number of seconds relative to the end_timestamp. Defaults to -{DEFAULT_TAGS_TIME_SPAN_SECONDS}",
|
|
243
|
-
type="string",
|
|
244
|
-
required=False,
|
|
245
|
-
),
|
|
246
|
-
"end_datetime": ToolParameter(
|
|
247
|
-
description="The ending time boundary for the search period. String in RFC3339 format. Defaults to NOW().",
|
|
248
|
-
type="string",
|
|
249
|
-
required=False,
|
|
250
|
-
),
|
|
251
|
-
},
|
|
252
|
-
)
|
|
253
|
-
self._toolset = toolset
|
|
254
|
-
|
|
255
|
-
def _invoke(
|
|
256
|
-
self, params: dict, user_approved: bool = False
|
|
257
|
-
) -> StructuredToolResult:
|
|
258
|
-
api_key = self._toolset.grafana_config.api_key
|
|
259
|
-
headers = self._toolset.grafana_config.headers
|
|
260
|
-
start, end = process_timestamps_to_int(
|
|
261
|
-
start=params.get("start_datetime"),
|
|
262
|
-
end=params.get("end_datetime"),
|
|
263
|
-
default_time_span_seconds=DEFAULT_TAGS_TIME_SPAN_SECONDS,
|
|
264
|
-
)
|
|
265
|
-
|
|
266
|
-
base_url = get_base_url(self._toolset.grafana_config)
|
|
267
|
-
url = f"{base_url}/api/v2/search/tags?start={start}&end={end}"
|
|
268
|
-
|
|
269
|
-
try:
|
|
270
|
-
response = requests.get(
|
|
271
|
-
url,
|
|
272
|
-
headers=build_headers(api_key=api_key, additional_headers=headers),
|
|
273
|
-
timeout=60,
|
|
274
|
-
)
|
|
275
|
-
response.raise_for_status() # Raise an error for non-2xx responses
|
|
276
|
-
data = response.json()
|
|
277
|
-
return StructuredToolResult(
|
|
278
|
-
status=ToolResultStatus.SUCCESS,
|
|
279
|
-
data=yaml.dump(data.get("scopes")),
|
|
280
|
-
params=params,
|
|
281
|
-
)
|
|
282
|
-
except requests.exceptions.RequestException as e:
|
|
283
|
-
raise Exception(f"Failed to retrieve tags: {e} \n for URL: {url}")
|
|
284
|
-
|
|
285
|
-
def get_parameterized_one_liner(self, params: Dict) -> str:
|
|
286
|
-
return f"{toolset_name_for_one_liner(self._toolset.name)}: Fetched Tempo tags"
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
class GetTempoTraceById(Tool):
|
|
290
|
-
def __init__(self, toolset: BaseGrafanaTempoToolset):
|
|
291
|
-
super().__init__(
|
|
292
|
-
name="fetch_tempo_trace_by_id",
|
|
293
|
-
description="""Retrieves detailed information about a Tempo trace using its trace ID. Use this to investigate a trace.""",
|
|
294
|
-
parameters={
|
|
295
|
-
"trace_id": ToolParameter(
|
|
296
|
-
description="The unique trace ID to fetch.",
|
|
297
|
-
type="string",
|
|
298
|
-
required=True,
|
|
299
|
-
),
|
|
300
|
-
},
|
|
301
|
-
)
|
|
302
|
-
self._toolset = toolset
|
|
303
|
-
|
|
304
|
-
def _invoke(
|
|
305
|
-
self, params: dict, user_approved: bool = False
|
|
306
|
-
) -> StructuredToolResult:
|
|
307
|
-
labels_mapping = self._toolset.grafana_config.labels
|
|
308
|
-
labels = list(labels_mapping.model_dump().values())
|
|
309
|
-
|
|
310
|
-
base_url = get_base_url(self._toolset.grafana_config)
|
|
311
|
-
trace_data = query_tempo_trace_by_id(
|
|
312
|
-
base_url=base_url,
|
|
313
|
-
api_key=self._toolset.grafana_config.api_key,
|
|
314
|
-
headers=self._toolset.grafana_config.headers,
|
|
315
|
-
trace_id=get_param_or_raise(params, "trace_id"),
|
|
316
|
-
key_labels=labels,
|
|
317
|
-
)
|
|
318
|
-
return StructuredToolResult(
|
|
319
|
-
status=ToolResultStatus.SUCCESS,
|
|
320
|
-
data=trace_data,
|
|
321
|
-
params=params,
|
|
322
|
-
)
|
|
323
|
-
|
|
324
|
-
def get_parameterized_one_liner(self, params: Dict) -> str:
|
|
325
|
-
return f"{toolset_name_for_one_liner(self._toolset.name)}: Fetched Tempo Trace (trace_id={params.get('trace_id')})"
|
|
326
|
-
|
|
327
121
|
|
|
328
122
|
class FetchTracesSimpleComparison(Tool):
|
|
329
123
|
def __init__(self, toolset: BaseGrafanaTempoToolset):
|
|
330
124
|
super().__init__(
|
|
331
|
-
name="
|
|
125
|
+
name="tempo_fetch_traces_comparative_sample",
|
|
332
126
|
description="""Fetches statistics and representative samples of fast, slow, and typical traces for performance analysis. Requires either a `base_query` OR at least one of `service_name`, `pod_name`, `namespace_name`, `deployment_name`, `node_name`.
|
|
333
127
|
|
|
334
128
|
Important: call this tool first when investigating performance issues via traces. This tool provides comprehensive analysis for identifying patterns.
|
|
@@ -364,7 +158,11 @@ Examples:
|
|
|
364
158
|
required=False,
|
|
365
159
|
),
|
|
366
160
|
"base_query": ToolParameter(
|
|
367
|
-
description=
|
|
161
|
+
description=(
|
|
162
|
+
"Custom TraceQL filter. Supports span/resource attributes, "
|
|
163
|
+
"duration, and aggregates (count(), avg(), min(), max(), sum()). "
|
|
164
|
+
"Examples: '{span.http.status_code>=400}', '{duration>100ms}'"
|
|
165
|
+
),
|
|
368
166
|
type="string",
|
|
369
167
|
required=False,
|
|
370
168
|
),
|
|
@@ -373,13 +171,15 @@ Examples:
|
|
|
373
171
|
type="integer",
|
|
374
172
|
required=False,
|
|
375
173
|
),
|
|
376
|
-
"
|
|
377
|
-
description=
|
|
174
|
+
"start": ToolParameter(
|
|
175
|
+
description=standard_start_datetime_tool_param_description(
|
|
176
|
+
DEFAULT_GRAPH_TIME_SPAN_SECONDS
|
|
177
|
+
),
|
|
378
178
|
type="string",
|
|
379
179
|
required=False,
|
|
380
180
|
),
|
|
381
|
-
"
|
|
382
|
-
description=
|
|
181
|
+
"end": ToolParameter(
|
|
182
|
+
description=STANDARD_END_DATETIME_TOOL_PARAM_DESCRIPTION,
|
|
383
183
|
type="string",
|
|
384
184
|
required=False,
|
|
385
185
|
),
|
|
@@ -387,6 +187,14 @@ Examples:
|
|
|
387
187
|
)
|
|
388
188
|
self._toolset = toolset
|
|
389
189
|
|
|
190
|
+
@staticmethod
|
|
191
|
+
def validate_params(params: Dict[str, Any], expected_params: List[str]):
|
|
192
|
+
for param in expected_params:
|
|
193
|
+
if param in params and params[param] not in (None, "", [], {}):
|
|
194
|
+
return None
|
|
195
|
+
|
|
196
|
+
return f"At least one of the following argument is expected but none were set: {expected_params}"
|
|
197
|
+
|
|
390
198
|
def _invoke(
|
|
391
199
|
self, params: dict, user_approved: bool = False
|
|
392
200
|
) -> StructuredToolResult:
|
|
@@ -399,7 +207,7 @@ Examples:
|
|
|
399
207
|
filters = self._toolset.build_k8s_filters(params, use_exact_match=False)
|
|
400
208
|
|
|
401
209
|
# Validate that at least one parameter was provided
|
|
402
|
-
invalid_params_error = validate_params(
|
|
210
|
+
invalid_params_error = FetchTracesSimpleComparison.validate_params(
|
|
403
211
|
params,
|
|
404
212
|
[
|
|
405
213
|
"service_name",
|
|
@@ -411,7 +219,7 @@ Examples:
|
|
|
411
219
|
)
|
|
412
220
|
if invalid_params_error:
|
|
413
221
|
return StructuredToolResult(
|
|
414
|
-
status=
|
|
222
|
+
status=StructuredToolResultStatus.ERROR,
|
|
415
223
|
error=invalid_params_error,
|
|
416
224
|
params=params,
|
|
417
225
|
)
|
|
@@ -420,30 +228,37 @@ Examples:
|
|
|
420
228
|
|
|
421
229
|
sample_count = params.get("sample_count", 3)
|
|
422
230
|
|
|
423
|
-
start, end =
|
|
424
|
-
params.get("start_datetime"),
|
|
425
|
-
params.get("end_datetime"),
|
|
426
|
-
default_time_span_seconds=DEFAULT_TRACES_TIME_SPAN_SECONDS,
|
|
427
|
-
)
|
|
231
|
+
start, end = BaseGrafanaTempoToolset.adjust_start_end_time(params)
|
|
428
232
|
|
|
429
|
-
|
|
233
|
+
# Create API instance
|
|
234
|
+
api = GrafanaTempoAPI(
|
|
235
|
+
self._toolset.grafana_config, use_post=TEMPO_API_USE_POST
|
|
236
|
+
)
|
|
430
237
|
|
|
431
238
|
# Step 1: Get all trace summaries
|
|
432
239
|
stats_query = f"{{{base_query}}}"
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
240
|
+
|
|
241
|
+
# Debug log the query (useful for troubleshooting)
|
|
242
|
+
import logging
|
|
243
|
+
|
|
244
|
+
logger = logging.getLogger(__name__)
|
|
245
|
+
logger.info(f"Tempo query: {stats_query}")
|
|
246
|
+
|
|
247
|
+
logger.info(f"start: {start}, end: {end}")
|
|
248
|
+
|
|
249
|
+
all_traces_response = api.search_traces_by_query(
|
|
250
|
+
q=stats_query,
|
|
438
251
|
start=start,
|
|
439
252
|
end=end,
|
|
440
253
|
limit=1000,
|
|
441
254
|
)
|
|
442
255
|
|
|
256
|
+
logger.info(f"Response: {all_traces_response}")
|
|
257
|
+
|
|
443
258
|
traces = all_traces_response.get("traces", [])
|
|
444
259
|
if not traces:
|
|
445
260
|
return StructuredToolResult(
|
|
446
|
-
status=
|
|
261
|
+
status=StructuredToolResultStatus.SUCCESS,
|
|
447
262
|
data="No traces found matching the query",
|
|
448
263
|
params=params,
|
|
449
264
|
)
|
|
@@ -488,39 +303,22 @@ Examples:
|
|
|
488
303
|
return None
|
|
489
304
|
|
|
490
305
|
try:
|
|
491
|
-
|
|
492
|
-
response = requests.get(
|
|
493
|
-
url,
|
|
494
|
-
headers=build_headers(
|
|
495
|
-
api_key=self._toolset.grafana_config.api_key,
|
|
496
|
-
additional_headers=self._toolset.grafana_config.headers,
|
|
497
|
-
),
|
|
498
|
-
timeout=5,
|
|
499
|
-
)
|
|
500
|
-
response.raise_for_status()
|
|
306
|
+
trace_data = api.query_trace_by_id_v2(trace_id=trace_id)
|
|
501
307
|
return {
|
|
502
308
|
"traceID": trace_id,
|
|
503
309
|
"durationMs": trace_summary.get("durationMs", 0),
|
|
504
310
|
"rootServiceName": trace_summary.get(
|
|
505
311
|
"rootServiceName", "unknown"
|
|
506
312
|
),
|
|
507
|
-
"traceData":
|
|
313
|
+
"traceData": trace_data, # Raw trace data
|
|
508
314
|
}
|
|
509
|
-
except
|
|
315
|
+
except Exception as e:
|
|
510
316
|
error_msg = f"Failed to fetch full trace: {str(e)}"
|
|
511
|
-
if hasattr(e, "response") and e.response is not None:
|
|
512
|
-
error_msg += f" (Status: {e.response.status_code})"
|
|
513
317
|
return {
|
|
514
318
|
"traceID": trace_id,
|
|
515
319
|
"durationMs": trace_summary.get("durationMs", 0),
|
|
516
320
|
"error": error_msg,
|
|
517
321
|
}
|
|
518
|
-
except (ValueError, KeyError) as e:
|
|
519
|
-
return {
|
|
520
|
-
"traceID": trace_id,
|
|
521
|
-
"durationMs": trace_summary.get("durationMs", 0),
|
|
522
|
-
"error": f"Failed to parse trace data: {str(e)}",
|
|
523
|
-
}
|
|
524
322
|
|
|
525
323
|
# Fetch the selected traces
|
|
526
324
|
result = {
|
|
@@ -537,14 +335,14 @@ Examples:
|
|
|
537
335
|
|
|
538
336
|
# Return as YAML for readability
|
|
539
337
|
return StructuredToolResult(
|
|
540
|
-
status=
|
|
338
|
+
status=StructuredToolResultStatus.SUCCESS,
|
|
541
339
|
data=yaml.dump(result, default_flow_style=False, sort_keys=False),
|
|
542
340
|
params=params,
|
|
543
341
|
)
|
|
544
342
|
|
|
545
343
|
except Exception as e:
|
|
546
344
|
return StructuredToolResult(
|
|
547
|
-
status=
|
|
345
|
+
status=StructuredToolResultStatus.ERROR,
|
|
548
346
|
error=f"Error fetching traces: {str(e)}",
|
|
549
347
|
params=params,
|
|
550
348
|
)
|
|
@@ -553,6 +351,576 @@ Examples:
|
|
|
553
351
|
return f"{toolset_name_for_one_liner(self._toolset.name)}: Simple Tempo Traces Comparison"
|
|
554
352
|
|
|
555
353
|
|
|
354
|
+
class SearchTracesByQuery(Tool):
|
|
355
|
+
def __init__(self, toolset: BaseGrafanaTempoToolset):
|
|
356
|
+
super().__init__(
|
|
357
|
+
name="tempo_search_traces_by_query",
|
|
358
|
+
description=(
|
|
359
|
+
"Search for traces using TraceQL query language. "
|
|
360
|
+
"Uses the Tempo API endpoint: GET /api/search with 'q' parameter.\n\n"
|
|
361
|
+
"TraceQL can select traces based on:\n"
|
|
362
|
+
"- Span and resource attributes\n"
|
|
363
|
+
"- Timing and duration\n"
|
|
364
|
+
"- Aggregate functions:\n"
|
|
365
|
+
" • count() - Count number of spans\n"
|
|
366
|
+
" • avg(attribute) - Calculate average\n"
|
|
367
|
+
" • min(attribute) - Find minimum value\n"
|
|
368
|
+
" • max(attribute) - Find maximum value\n"
|
|
369
|
+
" • sum(attribute) - Sum values\n\n"
|
|
370
|
+
"Examples:\n"
|
|
371
|
+
'- Specific operation: {resource.service.name = "frontend" && name = "POST /api/orders"}\n'
|
|
372
|
+
'- Error traces: {resource.service.name="frontend" && name = "POST /api/orders" && status = error}\n'
|
|
373
|
+
'- HTTP errors: {resource.service.name="frontend" && name = "POST /api/orders" && span.http.status_code >= 500}\n'
|
|
374
|
+
'- Multi-service: {span.service.name="frontend" && name = "GET /api/products/{id}"} && {span.db.system="postgresql"}\n'
|
|
375
|
+
"- With aggregates: { status = error } | by(resource.service.name) | count() > 1"
|
|
376
|
+
),
|
|
377
|
+
parameters={
|
|
378
|
+
"q": ToolParameter(
|
|
379
|
+
description=(
|
|
380
|
+
"TraceQL query. Supports filtering by span/resource attributes, "
|
|
381
|
+
"duration, and aggregate functions (count(), avg(), min(), max(), sum()). "
|
|
382
|
+
"Examples: '{resource.service.name = \"frontend\"}', "
|
|
383
|
+
'\'{resource.service.name="frontend" && name = "POST /api/orders" && status = error}\', '
|
|
384
|
+
'\'{resource.service.name="frontend" && name = "POST /api/orders" && span.http.status_code >= 500}\', '
|
|
385
|
+
"'{} | count() > 10'"
|
|
386
|
+
),
|
|
387
|
+
type="string",
|
|
388
|
+
required=True,
|
|
389
|
+
),
|
|
390
|
+
"limit": ToolParameter(
|
|
391
|
+
description="Maximum number of traces to return",
|
|
392
|
+
type="integer",
|
|
393
|
+
required=False,
|
|
394
|
+
),
|
|
395
|
+
"start": ToolParameter(
|
|
396
|
+
description=standard_start_datetime_tool_param_description(
|
|
397
|
+
DEFAULT_GRAPH_TIME_SPAN_SECONDS
|
|
398
|
+
),
|
|
399
|
+
type="string",
|
|
400
|
+
required=False,
|
|
401
|
+
),
|
|
402
|
+
"end": ToolParameter(
|
|
403
|
+
description=STANDARD_END_DATETIME_TOOL_PARAM_DESCRIPTION,
|
|
404
|
+
type="string",
|
|
405
|
+
required=False,
|
|
406
|
+
),
|
|
407
|
+
"spss": ToolParameter(
|
|
408
|
+
description="Spans per span set",
|
|
409
|
+
type="integer",
|
|
410
|
+
required=False,
|
|
411
|
+
),
|
|
412
|
+
},
|
|
413
|
+
)
|
|
414
|
+
self._toolset = toolset
|
|
415
|
+
|
|
416
|
+
def _invoke(
|
|
417
|
+
self, params: Dict, user_approved: bool = False
|
|
418
|
+
) -> StructuredToolResult:
|
|
419
|
+
api = GrafanaTempoAPI(self._toolset.grafana_config, use_post=TEMPO_API_USE_POST)
|
|
420
|
+
|
|
421
|
+
start, end = BaseGrafanaTempoToolset.adjust_start_end_time(params)
|
|
422
|
+
|
|
423
|
+
try:
|
|
424
|
+
result = api.search_traces_by_query(
|
|
425
|
+
q=params["q"],
|
|
426
|
+
limit=params.get("limit"),
|
|
427
|
+
start=start,
|
|
428
|
+
end=end,
|
|
429
|
+
spss=params.get("spss"),
|
|
430
|
+
)
|
|
431
|
+
return StructuredToolResult(
|
|
432
|
+
status=StructuredToolResultStatus.SUCCESS,
|
|
433
|
+
data=yaml.dump(result, default_flow_style=False),
|
|
434
|
+
params=params,
|
|
435
|
+
)
|
|
436
|
+
except Exception as e:
|
|
437
|
+
return StructuredToolResult(
|
|
438
|
+
status=StructuredToolResultStatus.ERROR,
|
|
439
|
+
error=str(e),
|
|
440
|
+
params=params,
|
|
441
|
+
)
|
|
442
|
+
|
|
443
|
+
def get_parameterized_one_liner(self, params: Dict) -> str:
|
|
444
|
+
return f"{toolset_name_for_one_liner(self._toolset.name)}: Searched traces with TraceQL"
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
class SearchTracesByTags(Tool):
|
|
448
|
+
def __init__(self, toolset: BaseGrafanaTempoToolset):
|
|
449
|
+
super().__init__(
|
|
450
|
+
name="tempo_search_traces_by_tags",
|
|
451
|
+
description=(
|
|
452
|
+
"Search for traces using logfmt-encoded tags. "
|
|
453
|
+
"Uses the Tempo API endpoint: GET /api/search with 'tags' parameter. "
|
|
454
|
+
'Example: service.name="api" http.status_code="500"'
|
|
455
|
+
),
|
|
456
|
+
parameters={
|
|
457
|
+
"tags": ToolParameter(
|
|
458
|
+
description='Logfmt-encoded span/process attributes (e.g., \'service.name="api" http.status_code="500"\')',
|
|
459
|
+
type="string",
|
|
460
|
+
required=True,
|
|
461
|
+
),
|
|
462
|
+
"min_duration": ToolParameter(
|
|
463
|
+
description="Minimum trace duration (e.g., '5s', '100ms')",
|
|
464
|
+
type="string",
|
|
465
|
+
required=False,
|
|
466
|
+
),
|
|
467
|
+
"max_duration": ToolParameter(
|
|
468
|
+
description="Maximum trace duration (e.g., '10s', '1000ms')",
|
|
469
|
+
type="string",
|
|
470
|
+
required=False,
|
|
471
|
+
),
|
|
472
|
+
"limit": ToolParameter(
|
|
473
|
+
description="Maximum number of traces to return",
|
|
474
|
+
type="integer",
|
|
475
|
+
required=False,
|
|
476
|
+
),
|
|
477
|
+
"start": ToolParameter(
|
|
478
|
+
description=standard_start_datetime_tool_param_description(
|
|
479
|
+
DEFAULT_GRAPH_TIME_SPAN_SECONDS
|
|
480
|
+
),
|
|
481
|
+
type="string",
|
|
482
|
+
required=False,
|
|
483
|
+
),
|
|
484
|
+
"end": ToolParameter(
|
|
485
|
+
description=STANDARD_END_DATETIME_TOOL_PARAM_DESCRIPTION,
|
|
486
|
+
type="string",
|
|
487
|
+
required=False,
|
|
488
|
+
),
|
|
489
|
+
"spss": ToolParameter(
|
|
490
|
+
description="Spans per span set",
|
|
491
|
+
type="integer",
|
|
492
|
+
required=False,
|
|
493
|
+
),
|
|
494
|
+
},
|
|
495
|
+
)
|
|
496
|
+
self._toolset = toolset
|
|
497
|
+
|
|
498
|
+
def _invoke(
|
|
499
|
+
self, params: Dict, user_approved: bool = False
|
|
500
|
+
) -> StructuredToolResult:
|
|
501
|
+
api = GrafanaTempoAPI(self._toolset.grafana_config, use_post=TEMPO_API_USE_POST)
|
|
502
|
+
|
|
503
|
+
start, end = BaseGrafanaTempoToolset.adjust_start_end_time(params)
|
|
504
|
+
|
|
505
|
+
try:
|
|
506
|
+
result = api.search_traces_by_tags(
|
|
507
|
+
tags=params["tags"],
|
|
508
|
+
min_duration=params.get("min_duration"),
|
|
509
|
+
max_duration=params.get("max_duration"),
|
|
510
|
+
limit=params.get("limit"),
|
|
511
|
+
start=start,
|
|
512
|
+
end=end,
|
|
513
|
+
spss=params.get("spss"),
|
|
514
|
+
)
|
|
515
|
+
return StructuredToolResult(
|
|
516
|
+
status=StructuredToolResultStatus.SUCCESS,
|
|
517
|
+
data=yaml.dump(result, default_flow_style=False),
|
|
518
|
+
params=params,
|
|
519
|
+
)
|
|
520
|
+
except Exception as e:
|
|
521
|
+
return StructuredToolResult(
|
|
522
|
+
status=StructuredToolResultStatus.ERROR,
|
|
523
|
+
error=str(e),
|
|
524
|
+
params=params,
|
|
525
|
+
)
|
|
526
|
+
|
|
527
|
+
def get_parameterized_one_liner(self, params: Dict) -> str:
|
|
528
|
+
return f"{toolset_name_for_one_liner(self._toolset.name)}: Searched traces with tags"
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
class QueryTraceById(Tool):
|
|
532
|
+
def __init__(self, toolset: BaseGrafanaTempoToolset):
|
|
533
|
+
super().__init__(
|
|
534
|
+
name="tempo_query_trace_by_id",
|
|
535
|
+
description=(
|
|
536
|
+
"Retrieve detailed trace information by trace ID. "
|
|
537
|
+
"Uses the Tempo API endpoint: GET /api/v2/traces/{trace_id}. "
|
|
538
|
+
"Returns the full trace data in OpenTelemetry format."
|
|
539
|
+
),
|
|
540
|
+
parameters={
|
|
541
|
+
"trace_id": ToolParameter(
|
|
542
|
+
description="The unique trace ID to fetch",
|
|
543
|
+
type="string",
|
|
544
|
+
required=True,
|
|
545
|
+
),
|
|
546
|
+
"start": ToolParameter(
|
|
547
|
+
description=standard_start_datetime_tool_param_description(
|
|
548
|
+
DEFAULT_GRAPH_TIME_SPAN_SECONDS
|
|
549
|
+
),
|
|
550
|
+
type="string",
|
|
551
|
+
required=False,
|
|
552
|
+
),
|
|
553
|
+
"end": ToolParameter(
|
|
554
|
+
description=STANDARD_END_DATETIME_TOOL_PARAM_DESCRIPTION,
|
|
555
|
+
type="string",
|
|
556
|
+
required=False,
|
|
557
|
+
),
|
|
558
|
+
},
|
|
559
|
+
)
|
|
560
|
+
self._toolset = toolset
|
|
561
|
+
|
|
562
|
+
def _invoke(
|
|
563
|
+
self, params: Dict, user_approved: bool = False
|
|
564
|
+
) -> StructuredToolResult:
|
|
565
|
+
api = GrafanaTempoAPI(self._toolset.grafana_config, use_post=TEMPO_API_USE_POST)
|
|
566
|
+
|
|
567
|
+
start, end = BaseGrafanaTempoToolset.adjust_start_end_time(params)
|
|
568
|
+
|
|
569
|
+
try:
|
|
570
|
+
trace_data = api.query_trace_by_id_v2(
|
|
571
|
+
trace_id=params["trace_id"],
|
|
572
|
+
start=start,
|
|
573
|
+
end=end,
|
|
574
|
+
)
|
|
575
|
+
|
|
576
|
+
# Return raw trace data as YAML for readability
|
|
577
|
+
return StructuredToolResult(
|
|
578
|
+
status=StructuredToolResultStatus.SUCCESS,
|
|
579
|
+
data=yaml.dump(trace_data, default_flow_style=False),
|
|
580
|
+
params=params,
|
|
581
|
+
)
|
|
582
|
+
except Exception as e:
|
|
583
|
+
return StructuredToolResult(
|
|
584
|
+
status=StructuredToolResultStatus.ERROR,
|
|
585
|
+
error=str(e),
|
|
586
|
+
params=params,
|
|
587
|
+
)
|
|
588
|
+
|
|
589
|
+
def get_parameterized_one_liner(self, params: Dict) -> str:
|
|
590
|
+
return f"{toolset_name_for_one_liner(self._toolset.name)}: Retrieved trace {params.get('trace_id')}"
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
class SearchTagNames(Tool):
|
|
594
|
+
def __init__(self, toolset: BaseGrafanaTempoToolset):
|
|
595
|
+
super().__init__(
|
|
596
|
+
name="tempo_search_tag_names",
|
|
597
|
+
description=(
|
|
598
|
+
"Discover available tag names across traces. "
|
|
599
|
+
"Uses the Tempo API endpoint: GET /api/v2/search/tags. "
|
|
600
|
+
"Returns tags organized by scope (resource, span, intrinsic)."
|
|
601
|
+
),
|
|
602
|
+
parameters={
|
|
603
|
+
"scope": ToolParameter(
|
|
604
|
+
description="Filter by scope: 'resource', 'span', or 'intrinsic'",
|
|
605
|
+
type="string",
|
|
606
|
+
required=False,
|
|
607
|
+
),
|
|
608
|
+
"q": ToolParameter(
|
|
609
|
+
description="TraceQL query to filter tags (e.g., '{resource.cluster=\"us-east-1\"}')",
|
|
610
|
+
type="string",
|
|
611
|
+
required=False,
|
|
612
|
+
),
|
|
613
|
+
"start": ToolParameter(
|
|
614
|
+
description=standard_start_datetime_tool_param_description(
|
|
615
|
+
DEFAULT_GRAPH_TIME_SPAN_SECONDS
|
|
616
|
+
),
|
|
617
|
+
type="string",
|
|
618
|
+
required=False,
|
|
619
|
+
),
|
|
620
|
+
"end": ToolParameter(
|
|
621
|
+
description=STANDARD_END_DATETIME_TOOL_PARAM_DESCRIPTION,
|
|
622
|
+
type="string",
|
|
623
|
+
required=False,
|
|
624
|
+
),
|
|
625
|
+
"limit": ToolParameter(
|
|
626
|
+
description="Maximum number of tag names to return",
|
|
627
|
+
type="integer",
|
|
628
|
+
required=False,
|
|
629
|
+
),
|
|
630
|
+
"max_stale_values": ToolParameter(
|
|
631
|
+
description="Maximum stale values parameter",
|
|
632
|
+
type="integer",
|
|
633
|
+
required=False,
|
|
634
|
+
),
|
|
635
|
+
},
|
|
636
|
+
)
|
|
637
|
+
self._toolset = toolset
|
|
638
|
+
|
|
639
|
+
def _invoke(
|
|
640
|
+
self, params: Dict, user_approved: bool = False
|
|
641
|
+
) -> StructuredToolResult:
|
|
642
|
+
api = GrafanaTempoAPI(self._toolset.grafana_config, use_post=TEMPO_API_USE_POST)
|
|
643
|
+
|
|
644
|
+
start, end = BaseGrafanaTempoToolset.adjust_start_end_time(params)
|
|
645
|
+
|
|
646
|
+
try:
|
|
647
|
+
result = api.search_tag_names_v2(
|
|
648
|
+
scope=params.get("scope"),
|
|
649
|
+
q=params.get("q"),
|
|
650
|
+
start=start,
|
|
651
|
+
end=end,
|
|
652
|
+
limit=params.get("limit"),
|
|
653
|
+
max_stale_values=params.get("max_stale_values"),
|
|
654
|
+
)
|
|
655
|
+
return StructuredToolResult(
|
|
656
|
+
status=StructuredToolResultStatus.SUCCESS,
|
|
657
|
+
data=yaml.dump(result, default_flow_style=False),
|
|
658
|
+
params=params,
|
|
659
|
+
)
|
|
660
|
+
except Exception as e:
|
|
661
|
+
return StructuredToolResult(
|
|
662
|
+
status=StructuredToolResultStatus.ERROR,
|
|
663
|
+
error=str(e),
|
|
664
|
+
params=params,
|
|
665
|
+
)
|
|
666
|
+
|
|
667
|
+
def get_parameterized_one_liner(self, params: Dict) -> str:
|
|
668
|
+
return f"{toolset_name_for_one_liner(self._toolset.name)}: Discovered tag names"
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
class SearchTagValues(Tool):
|
|
672
|
+
def __init__(self, toolset: BaseGrafanaTempoToolset):
|
|
673
|
+
super().__init__(
|
|
674
|
+
name="tempo_search_tag_values",
|
|
675
|
+
description=(
|
|
676
|
+
"Get all values for a specific tag. "
|
|
677
|
+
"Uses the Tempo API endpoint: GET /api/v2/search/tag/{tag}/values. "
|
|
678
|
+
"Useful for discovering what values exist for a given tag."
|
|
679
|
+
),
|
|
680
|
+
parameters={
|
|
681
|
+
"tag": ToolParameter(
|
|
682
|
+
description="The tag name to get values for (e.g., 'resource.service.name', 'http.status_code')",
|
|
683
|
+
type="string",
|
|
684
|
+
required=True,
|
|
685
|
+
),
|
|
686
|
+
"q": ToolParameter(
|
|
687
|
+
description="TraceQL query to filter tag values (e.g., '{resource.cluster=\"us-east-1\"}')",
|
|
688
|
+
type="string",
|
|
689
|
+
required=False,
|
|
690
|
+
),
|
|
691
|
+
"start": ToolParameter(
|
|
692
|
+
description=standard_start_datetime_tool_param_description(
|
|
693
|
+
DEFAULT_GRAPH_TIME_SPAN_SECONDS
|
|
694
|
+
),
|
|
695
|
+
type="string",
|
|
696
|
+
required=False,
|
|
697
|
+
),
|
|
698
|
+
"end": ToolParameter(
|
|
699
|
+
description=STANDARD_END_DATETIME_TOOL_PARAM_DESCRIPTION,
|
|
700
|
+
type="string",
|
|
701
|
+
required=False,
|
|
702
|
+
),
|
|
703
|
+
"limit": ToolParameter(
|
|
704
|
+
description="Maximum number of values to return",
|
|
705
|
+
type="integer",
|
|
706
|
+
required=False,
|
|
707
|
+
),
|
|
708
|
+
"max_stale_values": ToolParameter(
|
|
709
|
+
description="Maximum stale values parameter",
|
|
710
|
+
type="integer",
|
|
711
|
+
required=False,
|
|
712
|
+
),
|
|
713
|
+
},
|
|
714
|
+
)
|
|
715
|
+
self._toolset = toolset
|
|
716
|
+
|
|
717
|
+
def _invoke(
|
|
718
|
+
self, params: Dict, user_approved: bool = False
|
|
719
|
+
) -> StructuredToolResult:
|
|
720
|
+
api = GrafanaTempoAPI(self._toolset.grafana_config, use_post=TEMPO_API_USE_POST)
|
|
721
|
+
|
|
722
|
+
start, end = BaseGrafanaTempoToolset.adjust_start_end_time(params)
|
|
723
|
+
|
|
724
|
+
try:
|
|
725
|
+
result = api.search_tag_values_v2(
|
|
726
|
+
tag=params["tag"],
|
|
727
|
+
q=params.get("q"),
|
|
728
|
+
start=start,
|
|
729
|
+
end=end,
|
|
730
|
+
limit=params.get("limit"),
|
|
731
|
+
max_stale_values=params.get("max_stale_values"),
|
|
732
|
+
)
|
|
733
|
+
return StructuredToolResult(
|
|
734
|
+
status=StructuredToolResultStatus.SUCCESS,
|
|
735
|
+
data=yaml.dump(result, default_flow_style=False),
|
|
736
|
+
params=params,
|
|
737
|
+
)
|
|
738
|
+
except Exception as e:
|
|
739
|
+
return StructuredToolResult(
|
|
740
|
+
status=StructuredToolResultStatus.ERROR,
|
|
741
|
+
error=str(e),
|
|
742
|
+
params=params,
|
|
743
|
+
)
|
|
744
|
+
|
|
745
|
+
def get_parameterized_one_liner(self, params: Dict) -> str:
|
|
746
|
+
return f"{toolset_name_for_one_liner(self._toolset.name)}: Retrieved values for tag '{params.get('tag')}'"
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
class QueryMetricsInstant(Tool):
|
|
750
|
+
def __init__(self, toolset: BaseGrafanaTempoToolset):
|
|
751
|
+
super().__init__(
|
|
752
|
+
name="tempo_query_metrics_instant",
|
|
753
|
+
description=(
|
|
754
|
+
"Compute a single TraceQL metric value across time range. "
|
|
755
|
+
"Uses the Tempo API endpoint: GET /api/metrics/query. "
|
|
756
|
+
"TraceQL metrics compute aggregated metrics from trace data. "
|
|
757
|
+
"Returns a single value for the entire time range. "
|
|
758
|
+
"Basic syntax: {selector} | function(attribute) [by (grouping)]\n\n"
|
|
759
|
+
"TraceQL metrics can help answer questions like:\n"
|
|
760
|
+
"- How many database calls across all systems are downstream of your application?\n"
|
|
761
|
+
"- What services beneath a given endpoint are failing?\n"
|
|
762
|
+
"- What services beneath an endpoint are slow?\n\n"
|
|
763
|
+
"TraceQL metrics help you answer these questions by parsing your traces in aggregate. "
|
|
764
|
+
"The instant version returns a single value for the query and is preferred over "
|
|
765
|
+
"query_metrics_range when you don't need the granularity of a full time-series but want "
|
|
766
|
+
"a total sum or single value computed across the whole time range."
|
|
767
|
+
),
|
|
768
|
+
parameters={
|
|
769
|
+
"q": ToolParameter(
|
|
770
|
+
description=(
|
|
771
|
+
"TraceQL metrics query. Supported functions: rate, count_over_time, "
|
|
772
|
+
"sum_over_time, max_over_time, min_over_time, avg_over_time, "
|
|
773
|
+
"quantile_over_time, histogram_over_time, compare. "
|
|
774
|
+
"Can use topk or bottomk modifiers. "
|
|
775
|
+
"Syntax: {selector} | function(attribute) [by (grouping)]. "
|
|
776
|
+
'Example: {resource.service.name="api"} | avg_over_time(duration)'
|
|
777
|
+
),
|
|
778
|
+
type="string",
|
|
779
|
+
required=True,
|
|
780
|
+
),
|
|
781
|
+
"start": ToolParameter(
|
|
782
|
+
description=standard_start_datetime_tool_param_description(
|
|
783
|
+
DEFAULT_GRAPH_TIME_SPAN_SECONDS
|
|
784
|
+
),
|
|
785
|
+
type="string",
|
|
786
|
+
required=False,
|
|
787
|
+
),
|
|
788
|
+
"end": ToolParameter(
|
|
789
|
+
description=STANDARD_END_DATETIME_TOOL_PARAM_DESCRIPTION,
|
|
790
|
+
type="string",
|
|
791
|
+
required=False,
|
|
792
|
+
),
|
|
793
|
+
},
|
|
794
|
+
)
|
|
795
|
+
self._toolset = toolset
|
|
796
|
+
|
|
797
|
+
def _invoke(
|
|
798
|
+
self, params: Dict, user_approved: bool = False
|
|
799
|
+
) -> StructuredToolResult:
|
|
800
|
+
api = GrafanaTempoAPI(self._toolset.grafana_config, use_post=TEMPO_API_USE_POST)
|
|
801
|
+
|
|
802
|
+
start, end = BaseGrafanaTempoToolset.adjust_start_end_time(params)
|
|
803
|
+
|
|
804
|
+
try:
|
|
805
|
+
result = api.query_metrics_instant(
|
|
806
|
+
q=params["q"],
|
|
807
|
+
start=start,
|
|
808
|
+
end=end,
|
|
809
|
+
)
|
|
810
|
+
return StructuredToolResult(
|
|
811
|
+
status=StructuredToolResultStatus.SUCCESS,
|
|
812
|
+
data=yaml.dump(result, default_flow_style=False),
|
|
813
|
+
params=params,
|
|
814
|
+
)
|
|
815
|
+
except Exception as e:
|
|
816
|
+
return StructuredToolResult(
|
|
817
|
+
status=StructuredToolResultStatus.ERROR,
|
|
818
|
+
error=str(e),
|
|
819
|
+
params=params,
|
|
820
|
+
)
|
|
821
|
+
|
|
822
|
+
def get_parameterized_one_liner(self, params: Dict) -> str:
|
|
823
|
+
return (
|
|
824
|
+
f"{toolset_name_for_one_liner(self._toolset.name)}: Computed TraceQL metric"
|
|
825
|
+
)
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
class QueryMetricsRange(Tool):
|
|
829
|
+
def __init__(self, toolset: BaseGrafanaTempoToolset):
|
|
830
|
+
super().__init__(
|
|
831
|
+
name="tempo_query_metrics_range",
|
|
832
|
+
description=(
|
|
833
|
+
"Get time series data from TraceQL metrics queries. "
|
|
834
|
+
"Uses the Tempo API endpoint: GET /api/metrics/query_range. "
|
|
835
|
+
"Returns metrics computed at regular intervals (controlled by 'step' parameter). "
|
|
836
|
+
"Use this for graphing metrics over time or analyzing trends. "
|
|
837
|
+
"Basic syntax: {selector} | function(attribute) [by (grouping)]\n\n"
|
|
838
|
+
"TraceQL metrics can help answer questions like:\n"
|
|
839
|
+
"- How many database calls across all systems are downstream of your application?\n"
|
|
840
|
+
"- What services beneath a given endpoint are failing?\n"
|
|
841
|
+
"- What services beneath an endpoint are slow?\n\n"
|
|
842
|
+
"TraceQL metrics help you answer these questions by parsing your traces in aggregate."
|
|
843
|
+
),
|
|
844
|
+
parameters={
|
|
845
|
+
"q": ToolParameter(
|
|
846
|
+
description=(
|
|
847
|
+
"TraceQL metrics query. Supported functions: rate, count_over_time, "
|
|
848
|
+
"sum_over_time, max_over_time, min_over_time, avg_over_time, "
|
|
849
|
+
"quantile_over_time, histogram_over_time, compare. "
|
|
850
|
+
"Can use topk or bottomk modifiers. "
|
|
851
|
+
"Syntax: {selector} | function(attribute) [by (grouping)]. "
|
|
852
|
+
'Example: {resource.service.name="api"} | avg_over_time(duration)'
|
|
853
|
+
),
|
|
854
|
+
type="string",
|
|
855
|
+
required=True,
|
|
856
|
+
),
|
|
857
|
+
"step": ToolParameter(
|
|
858
|
+
description="Time series granularity (e.g., '1m', '5m', '1h')",
|
|
859
|
+
type="string",
|
|
860
|
+
required=False,
|
|
861
|
+
),
|
|
862
|
+
"start": ToolParameter(
|
|
863
|
+
description=standard_start_datetime_tool_param_description(
|
|
864
|
+
DEFAULT_GRAPH_TIME_SPAN_SECONDS
|
|
865
|
+
),
|
|
866
|
+
type="string",
|
|
867
|
+
required=False,
|
|
868
|
+
),
|
|
869
|
+
"end": ToolParameter(
|
|
870
|
+
description=STANDARD_END_DATETIME_TOOL_PARAM_DESCRIPTION,
|
|
871
|
+
type="string",
|
|
872
|
+
required=False,
|
|
873
|
+
),
|
|
874
|
+
"exemplars": ToolParameter(
|
|
875
|
+
description="Maximum number of exemplars to return",
|
|
876
|
+
type="integer",
|
|
877
|
+
required=False,
|
|
878
|
+
),
|
|
879
|
+
},
|
|
880
|
+
)
|
|
881
|
+
self._toolset = toolset
|
|
882
|
+
|
|
883
|
+
def _invoke(
|
|
884
|
+
self, params: Dict, user_approved: bool = False
|
|
885
|
+
) -> StructuredToolResult:
|
|
886
|
+
api = GrafanaTempoAPI(self._toolset.grafana_config, use_post=TEMPO_API_USE_POST)
|
|
887
|
+
|
|
888
|
+
start, end = BaseGrafanaTempoToolset.adjust_start_end_time(params)
|
|
889
|
+
|
|
890
|
+
# Calculate appropriate step
|
|
891
|
+
step_param = params.get("step")
|
|
892
|
+
step_seconds = duration_string_to_seconds(step_param) if step_param else None
|
|
893
|
+
adjusted_step = adjust_step_for_max_points(
|
|
894
|
+
end - start,
|
|
895
|
+
int(MAX_GRAPH_POINTS),
|
|
896
|
+
step_seconds,
|
|
897
|
+
)
|
|
898
|
+
step = seconds_to_duration_string(adjusted_step)
|
|
899
|
+
|
|
900
|
+
try:
|
|
901
|
+
result = api.query_metrics_range(
|
|
902
|
+
q=params["q"],
|
|
903
|
+
step=step,
|
|
904
|
+
start=start,
|
|
905
|
+
end=end,
|
|
906
|
+
exemplars=params.get("exemplars"),
|
|
907
|
+
)
|
|
908
|
+
return StructuredToolResult(
|
|
909
|
+
status=StructuredToolResultStatus.SUCCESS,
|
|
910
|
+
data=yaml.dump(result, default_flow_style=False),
|
|
911
|
+
params=params,
|
|
912
|
+
)
|
|
913
|
+
except Exception as e:
|
|
914
|
+
return StructuredToolResult(
|
|
915
|
+
status=StructuredToolResultStatus.ERROR,
|
|
916
|
+
error=str(e),
|
|
917
|
+
params=params,
|
|
918
|
+
)
|
|
919
|
+
|
|
920
|
+
def get_parameterized_one_liner(self, params: Dict) -> str:
|
|
921
|
+
return f"{toolset_name_for_one_liner(self._toolset.name)}: Retrieved TraceQL metrics time series"
|
|
922
|
+
|
|
923
|
+
|
|
556
924
|
class GrafanaTempoToolset(BaseGrafanaTempoToolset):
|
|
557
925
|
def __init__(self):
|
|
558
926
|
super().__init__(
|
|
@@ -562,9 +930,13 @@ class GrafanaTempoToolset(BaseGrafanaTempoToolset):
|
|
|
562
930
|
docs_url="https://holmesgpt.dev/data-sources/builtin-toolsets/grafanatempo/",
|
|
563
931
|
tools=[
|
|
564
932
|
FetchTracesSimpleComparison(self),
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
933
|
+
SearchTracesByQuery(self),
|
|
934
|
+
SearchTracesByTags(self),
|
|
935
|
+
QueryTraceById(self),
|
|
936
|
+
SearchTagNames(self),
|
|
937
|
+
SearchTagValues(self),
|
|
938
|
+
QueryMetricsInstant(self),
|
|
939
|
+
QueryMetricsRange(self),
|
|
568
940
|
],
|
|
569
941
|
)
|
|
570
942
|
template_file_path = os.path.abspath(
|