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

added root_cause when source is opsgenie #39

Merged
merged 2 commits into from
Dec 23, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)