Skip to content

Split incident alert into Critical and High severity buttons - #369

Merged
nkuba merged 2 commits into
mainfrom
critical-only
Jun 3, 2026
Merged

nkuba merged 2 commits into
mainfrom
critical-only

Conversation

@pdyraga

@pdyraga pdyraga commented Jun 3, 2026

Copy link
Copy Markdown
Member

The single "Wake Someone Up!" button routed every alert through one PagerDuty key, leaving no way to distinguish a security incident or chain halt from other high-severity issues. Replace it with two buttons that page through separate routing keys, so each severity can have its own escalation policy and on-call rotation.

@claude

This comment was marked as outdated.

The single "Wake Someone Up!" button routed every alert through one
PagerDuty key, leaving no way to distinguish a security incident or
chain halt from other high-severity issues. Replace it with two
buttons that page through separate routing keys, so each severity can
have its own escalation policy and on-call rotation.
@claude

This comment was marked as outdated.

Pin to v9, the last major that still supports the Node 18 runtime this
image is built on (pnpm 10 requires Node >=22.13). This is a fix to
unblock build. Separately, we should upgrade CI to Node 26 and
node24-runtime actions.
@claude

claude Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @pdyraga's task —— View job


Code Review for Incident Alert Severity Split

Todo List:

  • Read and analyze discord-scripts/incident-report.ts changes
  • Review infrastructure/docker/Dockerfile modifications
  • Review infrastructure/kube deployment configuration changes
  • Evaluate code quality and best practices
  • Check for potential bugs or issues
  • Assess performance considerations
  • Review security concerns
  • Evaluate test coverage needs
  • Provide comprehensive feedback

Review Feedback

✅ Code Quality and Best Practices

Strong Points:

  • Clean separation of concerns with two distinct routing keys for different severity levels
  • Consistent error handling patterns with proper logging using the robot logger
  • Good use of Discord.js types and patterns with proper type checking
  • Proper environment variable validation with early returns (discord-scripts/incident-report.ts:23-34)
  • Clear, descriptive button labels that differentiate severity levels and provide context to users
  • Follows codebase TypeScript conventions with explicit types and no semicolons per style guide
  • Good UX with guidance text asking users to consider severity before triggering alerts

Suggestions:

  1. Duplicate LINEAR_API_TOKEN in Kubernetes config - There are two identical entries for LINEAR_API_TOKEN in the deployment YAML (infrastructure/kube/thesis-ops/valkyrie-hubot-deployment.yaml:115-119 and 58-62). The duplicate should be removed.

  2. Consider extracting PagerDuty logic - The PagerDuty API calls have significant duplication between critical and high severity handlers. Consider extracting into a shared function:

    async function triggerPagerDutyAlert(routingKey: string, summary: string, robot: Robot) {
      return fetch("https://events.pagerduty.com/v2/enqueue", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({
          payload: { summary, severity: "critical", source: "Mezo" },
          routing_key: routingKey,
          event_action: "trigger",
        }),
      })
    }

⚠️ Potential Issues

Minor Issues:

  1. Comment at line 124 - The comment // PagerDuty does not support "high" explains why both severity levels use "critical" in the PagerDuty payload. This is correct but could be clearer about the business logic.

  2. No validation of routing key format - The code accepts any string for routing keys. Consider adding basic validation if PagerDuty keys have a specific format requirement.

  3. Docker change appears unrelated - The pnpm version pin in infrastructure/docker/Dockerfile:37 seems unrelated to this incident alert feature. Consider separating infrastructure changes from feature changes in commits.

🚀 Performance Considerations

Good Performance Patterns:

  • Efficient event handling with early returns for non-target channels and bot messages
  • Minimal memory footprint with proper event cleanup (message deletion after interaction)
  • No performance bottlenecks identified in the Discord or PagerDuty API calls
  • Appropriate use of async/await for non-blocking operations

🔒 Security Assessment

Strong Security Posture:

  • Environment variables properly stored as Kubernetes secrets ✅
  • No hardcoded sensitive values ✅
  • Channel ID restriction prevents unauthorized usage (discord-scripts/incident-report.ts:47) ✅
  • Bot message filtering prevents infinite loops (discord-scripts/incident-report.ts:37-44) ✅
  • Proper use of allowedMentions: { repliedUser: false } to prevent mention spam
  • Uses HTTPS for PagerDuty API calls ✅

Security Recommendations:

  1. PagerDuty API error logging - Consider sanitizing error objects before logging to prevent potential exposure of sensitive response data. Current implementation at discord-scripts/incident-report.ts:111 and 136 logs the full error object:
    robot.logger.error("❌ Failed to trigger alert:", error.message || "Unknown error")

🧪 Test Coverage

Missing Test Coverage:

  • No existing tests found for the incident reporting functionality
  • The codebase has Jest testing infrastructure but lacks coverage for Discord integrations

Recommended Test Cases:

describe('incidentReport', () => {
  it('should require both routing keys to be set')
  it('should create critical incident alert with correct PagerDuty payload')
  it('should create high severity alert with correct PagerDuty payload') 
  it('should handle PagerDuty API failures gracefully')
  it('should only respond to messages in the configured channel')
  it('should ignore bot messages and non-text channels')
  it('should delete interaction message after button click')
  it('should provide appropriate user feedback for each severity level')
})

📋 Summary

This is a well-implemented solution that successfully addresses the business requirement of separating critical and high severity alerts with different PagerDuty routing keys. The implementation follows good practices with proper error handling, security considerations, and clean separation of concerns.

Key Improvements Made:

  • Replaced single "Wake Someone Up!" button with two severity-specific buttons
  • Added separate CRITICAL_INCIDENT_ROUTING_KEY and HIGH_INCIDENT_ROUTING_KEY environment variables
  • Enhanced button text to provide clear guidance on when to use each severity level
  • Maintained consistent error handling and logging patterns
  • Proper security handling with environment variables stored as Kubernetes secrets
  • Added helpful guidance text to encourage thoughtful incident classification

Action Items:

  1. Critical: Remove duplicate LINEAR_API_TOKEN environment variable in deployment config
  2. Recommended: Add unit tests for the incident reporting functionality
  3. Optional: Extract PagerDuty API logic into shared function to reduce duplication
  4. Optional: Consider more specific error logging to avoid potential sensitive data exposure
  5. Optional: Separate the Docker pnpm pin change into a separate commit if unrelated

Overall Assessment: ✅ Approved - This is a solid implementation that improves the incident management workflow while maintaining code quality and security standards. The separation of critical vs. high severity alerts will enable better on-call management with appropriate escalation policies for different types of incidents.


RUN npm install -g pnpm
# Install pnpm. Pin to v9, the last major that still supports the Node 18
# runtime this image is built on (pnpm 10 requires Node >=22.13).
RUN npm install -g pnpm@9

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workaround to unblock. Separately, we need to do something similar to what was done in https://github.com/mezo-org/web/pull/539.

@nkuba
nkuba merged commit 85adea2 into main Jun 3, 2026
11 checks passed
@nkuba
nkuba deleted the critical-only branch June 3, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants