Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions holmes/plugins/toolsets/grafana/base_grafana_toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
CallablePrerequisite,
)
from holmes.plugins.toolsets.grafana.common import GrafanaConfig
from holmes.plugins.toolsets.grafana.grafana_api import get_health
from holmes.plugins.toolsets.grafana.grafana_api import grafana_health_check
from holmes.plugins.toolsets.utils import TOOLSET_CONFIG_MISSING_ERROR


Expand Down Expand Up @@ -42,7 +42,7 @@ def prerequisites_callable(self, config: dict[str, Any]) -> Tuple[bool, str]:

try:
self._grafana_config = self.config_class(**config)
return get_health(self._grafana_config)
return grafana_health_check(self._grafana_config)

except Exception as e:
logging.exception(f"Failed to set up grafana toolset {self.name}")
Expand Down
8 changes: 4 additions & 4 deletions holmes/plugins/toolsets/grafana/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ def build_headers(api_key: Optional[str], additional_headers: Optional[Dict[str,


def format_log(log: Dict) -> str:
log_str = log.get("log")
log_str = log.get("log", "")
timestamp_nanoseconds = log.get("timestamp")
if not log_str:
log_str = json.dumps(log)
elif timestamp_nanoseconds:
if timestamp_nanoseconds:
timestamp_seconds = int(timestamp_nanoseconds) // 1_000_000_000
dt = datetime.datetime.fromtimestamp(timestamp_seconds)
log_str = dt.strftime("%Y-%m-%dT%H:%M:%SZ") + " " + log_str
else:
log_str = json.dumps(log)

return log_str

Expand Down
2 changes: 1 addition & 1 deletion holmes/plugins/toolsets/grafana/grafana_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
giveup=lambda e: isinstance(e, requests.exceptions.HTTPError)
and e.response.status_code < 500,
)
def get_health(config: GrafanaConfig) -> Tuple[bool, str]:
def grafana_health_check(config: GrafanaConfig) -> Tuple[bool, str]:
base_url = get_base_url(config)

# Both loki and tempo provide the same /ready api
Expand Down
8 changes: 4 additions & 4 deletions holmes/plugins/toolsets/grafana/loki_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ def query_loki_logs_by_label(
headers: Optional[Dict[str, str]],
namespace: str,
label_value: str,
filter_regexp: Optional[str],
match: Optional[str],
start: Union[int, str],
end: Union[int, str],
label: str,
namespace_search_key: str = "namespace",
limit: int = 200,
) -> List[Dict]:
query = f'{{{namespace_search_key}="{namespace}", {label}=~"{label_value}"}}'
if filter_regexp:
query += f' |~ "{filter_regexp}"'
query = f'{{{namespace_search_key}="{namespace}", {label}="{label_value}"}}'
if match:
query += f' |= "{match}"'
return execute_loki_query(
base_url=base_url,
api_key=api_key,
Expand Down
Loading