Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record alerts as part of the pipeline #197

Merged
merged 2 commits into from
Dec 5, 2024
Merged

Record alerts as part of the pipeline #197

merged 2 commits into from
Dec 5, 2024

Conversation

aponcedeleonch
Copy link
Contributor

The alerts are recorded in the context of the pipeline execution. At the end of the pipeline the recorded alerts will go into the DB.

  • The alerts are recorded for both input and output pipelines
  • The alerts are recorded in the pipeline steps. If a step took an action an alert gets recorded
  • There are 2 levels of alerts for the moment: INFO and CRITICAL
  • Most of the steps record INFO alerts with the exception of secrets.

@@ -1,99 +1,24 @@
-- name: CreatePrompt :one
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted the unused queries

@@ -28,3 +32,18 @@ async def get_messages() -> List[Conversation]:

conversations = await match_conversations(partial_conversations)
return conversations


@dashboard_router.get("/dashboard/alerts")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second endpoint. I still need to implement some filtering for @peppescg

@@ -11,300 +11,87 @@
from codegate.db import models


CREATE_ALERT = """-- name: create_alert \\:one
INSERT INTO alerts (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file got shrink down when I deleted most of the queries.


def add_code_snippet(self, snippet: CodeSnippet):
self.code_snippets.append(snippet)

def get_snippets_by_language(self, language: str) -> List[CodeSnippet]:
return [s for s in self.code_snippets if s.language.lower() == language.lower()]

def add_alert(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what adds alerts to the context


# Add the remaining content if any
if after:
chunks.append(self._create_chunk(chunk, after))
complete_comment += after

# Add an alert to the context
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add an alert for all code snippets or only those that contain some bad packages (which I know is in progress, asking for later)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial thought was basically to save an alert for everything that we do and have different levels of alerts or notifications: INFO and CRITICAL. We can add more if we want:

  • INFO would be for routinely stuff like "hey we detected this code snippet as part of our pipeline".
  • CRITICAL would be for malicious packages or detected secrets

@@ -69,6 +69,9 @@ async def process(

# If matches are found, add the matched content to context
if len(searched_objects) > 0:
# Add an alert to the context
context.add_alert(self.name, trigger_string=last_user_message_str)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be worth rebasing atop Pankaj's PR to be able to add alerts on different kids of packages (mal/archived/...)

Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine and most importantly allows you and Giuseppe to move forward. We might want to tune what do we alert on just before the release.

The alerts are recorded in the `context` of the pipeline execution.
At the end of the pipeline the recorded alerts will go into the DB.
- The alerts are recorded for both input and output pipelines
- The alerts are recorded in the pipeline steps. If a step took an action an alert gets recorded
- There are 2 levels of alerts for the moment: `INFO` and `CRITICAL`
- Most of the steps record `INFO` alerts with the exception of secrets.
@aponcedeleonch aponcedeleonch merged commit af1fa30 into main Dec 5, 2024
3 checks passed
yrobla pushed a commit that referenced this pull request Dec 5, 2024
Record alerts as part of the pipeline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants