Skip to content

misc: Pagerduty issue template change #4796

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

Merged
merged 7 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
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
73 changes: 58 additions & 15 deletions .github/ISSUE_TEMPLATE/pager-duty.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,66 @@ body:
description: "A clear and concise description of what the bug is."
placeholder: "It bugs out when ..."
- type: dropdown
id: criticality
id: affected-areas
attributes:
label: "Criticality"
description: "How critical is the issue? Please include the impact in the "
label: "Affected areas"
description: "What areas of Devtron are impacted by the issue?"
options:
- P0 - Critical/Blocking
- P1 - High
- P2 - Medium
- P3 - Low
- Devtron dashboard completely down
- Login issues
- RBAC Issues
- CI
- CD
- App creation
- Deployment from Chart store
- Security features
- CI/CD Plugins
- Other CRITICAL functionality
- Other NON-CRITICAL functionality
- type: dropdown
id: additional-affected-areas
attributes:
label: "Additional affected areas"
description: "Are there any additional affected areas?"
options:
- Devtron dashboard completely down
- Login issues
- RBAC Issues
- CI
- CD
- App creation
- Deployment from Chart store
- Security features
- CI/CD Plugins
- Other CRITICAL functionality
- Other NON-CRITICAL functionality
- type: dropdown
id: prod-environment
attributes:
label: "Prod/Non-prod environments?"
description: "Is the issue affecting Prod environments?"
options:
- Prod
- Non-prod
- type: dropdown
id: user-unblocked
attributes:
label: "Is User unblocked?"
description: "Is the User unblocked?"
options:
- Yes
- No
- type: dropdown
id: user-unblocked-reason
attributes:
label: "How was the user un-blocked?"
description: "If the user was unblocked. How was the user un-blocked?"
options:
- TEMPORARILY - By disabling a CRITICAL functionality
- TEMPORARILY - By disabling a NON-CRITICAL functionality
- TEMPORARILY - By doing some changes from the backend/DB
- PERMANENTLY - By giving a workaround (From outside Devtron)
- PERMANENTLY - By giving a workaround (Within Devtron)
- type: textarea
id: impact
validations:
Expand Down Expand Up @@ -91,14 +142,6 @@ body:
- Something Else
validations:
required: true
- type: textarea
id: environment
validations:
required: false
attributes:
label: "🧱 Your Environment"
description: "Is your environment customized in any way? Provide your Browser version as well."
placeholder: "I use XYZ for ..."
- type: textarea
id: solution
validations:
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/github_pagerduty_score_calculation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Issue Created
on:
issues:
types: [opened]

jobs:
extract-issue-body:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Check if pager-duty template is used
if: ${{ contains(github.event.issue.labels.*.name, 'pager-duty') && contains(github.event.issue.labels.*.name, 'bug') }}
run: |
echo "Issue was created using pager-duty template"
python3 scripts/utilities/github_pagerduty_issue_score_calculation.py
env:
ISSUE_NUMBER: ${{ github.event.issue.number }}
ISSUE_BODY: ${{ github.event.issue.body }}
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
PAGERDUTY_SCORE_THRESHOLD: ${{ vars.PAGERDUTY_SCORE_THRESHOLD }}
139 changes: 139 additions & 0 deletions scripts/utilities/github_pagerduty_issue_score_calculation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import os
import sys
import re
import subprocess

# Dictionaries to store different options
affected_areas = {
"Devtron dashboard completely down": 100,
"Login issues": 50,
"RBAC Issues": 40,
"CI": 50,
"CD": 50,
"App creation": 30,
"Deployment from Chart store": 40,
"Security features": 50,
"CI/CD Plugins": 30,
"Other CRITICAL functionality": 30,
"Other NON-CRITICAL functionality": 20,
"None": 0
}

additional_affected_areas = {
"Devtron dashboard completely down": 100,
"Login issues": 50,
"RBAC Issues": 40,
"CI": 50,
"CD": 50,
"App creation": 30,
"Deployment from Chart store": 40,
"Security features": 50,
"CI/CD Plugins": 30,
"Other CRITICAL functionality": 30,
"Other NON-CRITICAL functionality": 20,
"None": 0
}

prod_environment = {
"Prod": 2,
"Non-prod": 1,
"None": 1
}

user_unblocked = {
"Yes": 1,
"No": 2,
"None": 1
}

user_unblocked_reason = {
"TEMPORARILY - By disabling a CRITICAL functionality": 3,
"TEMPORARILY - By disabling a NON-CRITICAL functionality": 1.2,
"TEMPORARILY - By doing some changes from the backend/DB": 1,
"PERMANENTLY - By giving a workaround (From outside Devtron)": 2,
"PERMANENTLY - By giving a workaround (Within Devtron)": 1,
"None": 1
}
# Function to extract and process information from the issue body
def process_issue_body(issue_body):
# Regular expressions to extract specific sections from the issue body
affected_areas_pattern = r'###\s*Affected\s*areas\s*\n\n(.*?)\n\n###'
additional_affected_areas_pattern = r'###\s*Additional\s*affected\s*areas\s*\n\n(.*?)\n\n###'
prod_non_prod_pattern = r'###\s*Prod/Non-prod\s*environments\?\s*\n\n(.*?)\n\n###'
user_unblocked_pattern = r'###\s*Is\s*User\s*unblocked\?\s*\n\n(.*?)\n\n###'
user_unblocked_reason_pattern = r'###\s*How\s*was\s*the\s*user\s*un-blocked\?\s*\n\n(.*?)\n\n###'

# Matching patterns in the issue body
affected_areas_match = re.search(affected_areas_pattern, issue_body)
additional_affected_areas_match = re.search(additional_affected_areas_pattern, issue_body)
prod_non_prod_match = re.search(prod_non_prod_pattern, issue_body)
user_unblocked_match = re.search(user_unblocked_pattern, issue_body)
user_unblocked_reason_match = re.search(user_unblocked_reason_pattern, issue_body)

# Extracting values from matches or setting default value to "None" if match not found
affected_area_value = affected_areas_match.group(1).strip() if affected_areas_match else "None"
additional_affected_area_value = additional_affected_areas_match.group(1).strip() if additional_affected_areas_match else "None"
prod_non_prod_value = prod_non_prod_match.group(1).strip() if prod_non_prod_match else "None"
user_unblocked_value = user_unblocked_match.group(1).strip() if user_unblocked_match else "None"
user_unblocked_reason_value = user_unblocked_reason_match.group(1).strip() if user_unblocked_reason_match else "None"

# Retrieving values from dictionaries
affected_areas_score = affected_areas.get(affected_area_value, 0)
additional_affected_areas_score = additional_affected_areas.get(additional_affected_area_value, 0)
prod_non_prod_score = prod_environment.get(prod_non_prod_value, 1)
user_unblocked_score = user_unblocked.get(user_unblocked_value, 1)
user_unblocked_reason_score = user_unblocked_reason.get(user_unblocked_reason_value, 1)

print("Affected areas:", affected_area_value)
print("Additional affected areas:", additional_affected_area_value)
print("Prod/Non-prod environments?:", prod_non_prod_value)
print("Is User unblocked?:", user_unblocked_value)
print("How was the user un-blocked?:", user_unblocked_reason_value)

# Checking for required values and skipping execution of script, if not found
if affected_areas_score == 0 or prod_non_prod_score == 0 or user_unblocked_score == 0:
print("One or more required values are missing. Exiting...")
sys.exit(0)

if user_unblocked_reason_score == 0:
user_unblocked_reason_score = 1

# Adding 'urgent' label to the issue if user_unblocked_reason is 'TEMPORARILY - By disabling a CRITICAL functionality' or affected_areas is 'Devtron dashboard completely down'
if user_unblocked_reason_score == 3 or affected_areas_score == 100:
try:

result = subprocess.run(['gh', 'issue', 'edit', str(issue_number), '--add-label', 'urgent'], capture_output=True, check=True, text=True)
print("urgent label added to issue", issue_number)
except subprocess.CalledProcessError as e:
print(e.stderr)
#calculating final score
final_score = affected_areas_score + additional_affected_areas_score * prod_non_prod_score * user_unblocked_score * user_unblocked_reason_score
print("Final Score:", final_score)

# Commenting the final score in the issue
comment = f"Final Score: {final_score}"
try:
result1 = subprocess.run(['gh', 'issue', 'comment', str(issue_number), '--body', comment], capture_output=True, check=True, text=True)
print("Final score commented on issue", issue_number)
except subprocess.CalledProcessError as e:
print(e.stderr)
return final_score

token = os.environ.get('GITHUB_TOKEN')
subprocess.run(['gh', 'auth', 'login', '--with-token'], input=token, text=True, capture_output=True)

# Retrieving environment variables
issue_body = os.environ.get('ISSUE_BODY')
issue_number = os.environ.get('ISSUE_NUMBER')
pagerduty_score_threshold = os.environ.get('PAGERDUTY_SCORE_THRESHOLD')

final_score = process_issue_body(issue_body)


# Removing 'pager-duty' label from issue if final score is below the threshold
if final_score <= int(pagerduty_score_threshold):
try:
result = subprocess.run(['gh', 'issue', 'edit', str(issue_number), '--remove-label', 'pager-duty'])
print("pager-duty label removed from issue", issue_number)
except subprocess.CalledProcessError as e:
print(e)