Skip to content

Commit ec9ee71

Browse files
committed
chore: address PR comments
1 parent 4504acf commit ec9ee71

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

holmes/plugins/toolsets/prometheus/prometheus.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class PrometheusConfig(BaseModel):
5656
rules_cache_duration_seconds: Union[int, None] = 1800 # 30 minutes
5757
additional_labels: Optional[Dict[str, str]] = None
5858
prometheus_ssl_enabled: bool = True
59+
query_response_size_limit: Optional[int] = (
60+
80000 # Limit the max number of characters in a query result to proactively prevent truncation and advise LLM to query less data
61+
)
5962

6063
@field_validator("prometheus_url")
6164
def ensure_trailing_slash(cls, v: Optional[str]) -> Optional[str]:
@@ -833,8 +836,12 @@ def _invoke(
833836
data_str_preview = json.dumps(result_data)
834837
data_size_chars = len(data_str_preview)
835838

836-
# If data is too large (>80K chars), provide summary instead
837-
if data_size_chars > 80000:
839+
# Provide summary if data is too large
840+
if (
841+
self.toolset.config.query_response_size_limit
842+
and data_size_chars
843+
> self.toolset.config.query_response_size_limit
844+
):
838845
response_data["data_summary"] = (
839846
create_data_summary_for_large_result(
840847
result_data,
@@ -1020,8 +1027,12 @@ def _invoke(
10201027
data_str_preview = json.dumps(result_data)
10211028
data_size_chars = len(data_str_preview)
10221029

1023-
# If data is too large (>80K chars), provide summary instead
1024-
if data_size_chars > 80000:
1030+
# Provide summary if data is too large
1031+
if (
1032+
self.toolset.config.query_response_size_limit
1033+
and data_size_chars
1034+
> self.toolset.config.query_response_size_limit
1035+
):
10251036
response_data["data_summary"] = (
10261037
create_data_summary_for_large_result(
10271038
result_data, query, data_size_chars, is_range_query=True

holmes/plugins/toolsets/prometheus/prometheus_instructions.jinja2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
## Handling High-Cardinality Metrics
2424
* CRITICAL: When querying metrics that may return many time series (>10), ALWAYS use aggregation to limit results
25-
* ALWAYS use `topk()` to limit the number of series returned
25+
* ALWAYS use `topk()` or `bottomk()` to limit the number of series returned
2626
* Standard pattern for high-cardinality queries:
2727
- Use `topk(5, <your_query>)` to get the top 5 series
2828
- Example: `topk(5, rate(container_cpu_usage_seconds_total{namespace="default"}[5m]))`

holmes/plugins/toolsets/prometheus/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import re
2-
from typing import Optional
3-
4-
from git import Union
2+
from typing import Optional, Union
53

64

75
def parse_duration_to_seconds(v: Optional[Union[str, float, int]]) -> Optional[float]:

0 commit comments

Comments
 (0)