diff --git a/configs/migrations/redshift/20211215141537_create_incidents_view.up.sql b/configs/migrations/redshift/20211215141537_create_incidents_view.up.sql index 8c766fd..a195a51 100644 --- a/configs/migrations/redshift/20211215141537_create_incidents_view.up.sql +++ b/configs/migrations/redshift/20211215141537_create_incidents_view.up.sql @@ -14,8 +14,9 @@ CREATE OR REPLACE VIEW watchops.incidents AS ( end as time_created, CASE WHEN source LIKE 'github%' THEN TO_TIMESTAMP(json_extract_path_text(json_serialize(metadata), 'issue', 'closed_at'), 'YYYY-MM-DD HH24:MI:SS') WHEN source LIKE 'gitlab%' THEN TO_TIMESTAMP(json_extract_path_text(json_serialize(metadata), 'object_attributes', 'closed_at'), 'YYYY-MM-DD HH24:MI:SS') - WHEN source LIKE 'opsgenie' THEN dateadd(ms, CAST(json_extract_path_text(json_extract_path_text(json_serialize(metadata), 'alert'), 'updatedAt') AS bigint), '1970-01-01') + WHEN source LIKE 'opsgenie' THEN dateadd(ms, CAST(json_extract_path_text(json_extract_path_text(json_serialize(metadata), 'alert'), 'updatedAt') AS bigint)/1000000, '1970-01-01') end as time_resolved, + regexp_substr(json_serialize(metadata), '(?<=root cause: )(.*?)(?=\")', 1, 1,'p') as root_cause, CASE WHEN source LIKE 'github%' THEN json_extract_path_text(json_serialize(metadata), 'issue', 'labels') like '%bug%' WHEN source LIKE 'gitlab%' THEN json_extract_path_text(json_serialize(metadata), 'object_attributes', 'labels','title') like '%ncident%' WHEN source LIKE 'opsgenie' THEN true @@ -24,12 +25,13 @@ CREATE OR REPLACE VIEW watchops.incidents AS ( WHERE event_type LIKE '%issue%' OR (event_type = 'note' and json_extract_path_text(json_serialize(metadata), 'object_attributes', 'noteable_type') = 'Issue') OR source = 'opsgenie' ) SELECT - source, - incident_id, - date_trunc('second',MIN(time_created)::timestamp) as time_created, - date_trunc('second',MAX(time_resolved)::timestamp) as time_resolved - FROM issue + issue.source, + issue.incident_id, + date_trunc('second',MIN(issue.time_created)::timestamp) as time_created, + date_trunc('second',MAX(issue.time_resolved)::timestamp) as time_resolved, + LISTAGG(issue.root_cause IGNORE NULLS) changes + FROM issue LEFT JOIN watchops.deployments d on d.main_commit = root_cause WHERE bug = true and time_resolved >= TO_DATE('1900-01-01', 'YYYY-MM-DD') --filter null time_resolved - GROUP BY source, incident_id + GROUP BY issue.source, issue.incident_id )