Skip to content

Commit

Permalink
regexp regardless source value
Browse files Browse the repository at this point in the history
  • Loading branch information
solopiu authored and italolelis committed Dec 23, 2021
1 parent 536f616 commit 0e4f85c
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +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,
CASE WHEN source LIKE 'opsgenie' THEN regexp_substr(json_extract_path_text(json_serialize(metadata), 'alert', 'note'),'[^:\s]*$')
ELSE ''
end as root_cause
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
Expand All @@ -27,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
)

0 comments on commit 0e4f85c

Please sign in to comment.