Skip to content

Commit

Permalink
Automate incidents creation
Browse files Browse the repository at this point in the history
Add a subscription module `create_incidents.py` to
create incidents automatically when builds and tests
objects match with issue patterns.

Signed-off-by: Jeny Sadadia <[email protected]>
  • Loading branch information
Jeny Sadadia committed Oct 4, 2024
1 parent f0326c7 commit 0fe4538
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions kcidb/monitor/subscriptions/create_incidents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
from kcidb.tools import kcidb_match
import kcidb

CLIENT = None


def get_client():
global CLIENT
if not CLIENT:
project_id = os.environ.get('GCP_PROJECT')
topic_name = os.environ.get('KCIDB_LOAD_QUEUE_TOPIC')
if project_id and topic_name:
CLIENT = kcidb.Client(project_id=project_id, topic_name=topic_name)
return CLIENT


def match_test(test):
client = get_client()
if client:
incident_generator = kcidb_match.IncidentGenerator()
incidents = incident_generator.generate_incidents_from_test(test)
client.submit(incidents)


def match_build(build):
client = get_client()
if client:
incident_generator = kcidb_match.IncidentGenerator()
incidents = incident_generator.generate_incidents_from_build(build)
client.submit(incidents)


def match_issue(issue):
incident_generator = kcidb_match.IncidentGenerator()
incident_generator.db.update_patterns(issue)

0 comments on commit 0fe4538

Please sign in to comment.