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
63 changes: 63 additions & 0 deletions holmes/core/supabase_dal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import logging
import os
from datetime import datetime
from typing import Dict, Optional

from supabase import create_client
from supabase.lib.client_options import ClientOptions
from pydantic import BaseModel

SUPABASE_TIMEOUT_SECONDS = int(os.getenv("SUPABASE_TIMEOUT_SECONDS", 3600))

ISSUES_TABLE = "Issues"
EVIDENCE_TABLE = "Evidence"


class SupabaseDal:
def __init__(
self,
url: str,
key: str,
email: str,
password: str,
):
self.url = url
self.key = key
options = ClientOptions(postgrest_client_timeout=SUPABASE_TIMEOUT_SECONDS)
self.client = create_client(url, key, options)
self.email = email
self.password = password
self.sign_in()

def sign_in(self):
logging.info("Supabase DAL login")
res = self.client.auth.sign_in_with_password({"email": self.email, "password": self.password})
self.client.auth.set_session(res.session.access_token, res.session.refresh_token)
self.client.postgrest.auth(res.session.access_token)

def get_issue_data(self, issue_id: str) -> dict:
# TODO this could be done in a single atomic SELECT, but there is no
# foreign key relation between Issues and Evidence.

try:
issue_data = (
self.client
.table(ISSUES_TABLE)
.select(f"*")
.filter("id", "eq", issue_id)
.execute()
).data[0]
except: # e.g. invalid id format
logging.exception("Supabase error while retrieving issue data")
return None
if not issue_data:
return None
evidence = (
self.client
.table(EVIDENCE_TABLE)
.select(f"*")
.filter("issue_id", "eq", issue_id)
.execute()
)
issue_data["evidence"] = evidence.data
return issue_data
12 changes: 8 additions & 4 deletions holmes/plugins/prompts/generic_investigation.jinja2
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Provide an excrutiatingly terse analysis of the following {{ issue.source_type}} alert/issue and why it is firing.
Provide an excruciatingly terse analysis of the following {{ issue.source_type }} alert/issue and why it is firing.
Use the "five whys" methodology to find the root cause.

This is not a chat session, don't ask any follow-up questions at the end and don't finish your answer
with any suggestions on what more could be done.

Answer in the format:

*<title of root cause>*
Expand All @@ -22,7 +25,7 @@ You must use tools to investigate whenever possible.

If you don't know, just say that the analysis was inconclusive.
If there are multiple possible causes list them in a numbered list.
When possible, be as specific as you can, but only if refering to exact data from the alert or tool output.
When possible, be as specific as you can, but only if referring to exact data from the alert or tool output.
Do not say 'based on the tool output' or explicitly refer to tools at all.

Do not stop investigating until you are at the final root cause you are able to find.
Expand All @@ -40,8 +43,9 @@ If there are incompatibilities between the versions of microservice A and micros
There will often be errors in the data that are not relevant to the alert or that do not have an impact.
Ignore them in your conclusion if you were not able to tie them to the error itself.

Do not start your reply with 'The issue is occuring because...' rather get straight to the point.
Remove every unecessary word.
Do not start your reply with 'The issue is occurring because...' rather get straight to the point.
Remove every unnecessary word.

`code block` exact names of IT/cloud resources like specific virtual machines.
*Surround the title of the root cause like this*.
Do not use markdown other than what is described above.
Expand Down
Loading