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

[ORCA-4263] Support for incident custom fields for Event Orchestration #749

Merged
merged 9 commits into from
Feb 26, 2024

Conversation

swbradshaw
Copy link
Contributor

@swbradshaw swbradshaw commented Sep 28, 2023

This PR adds support for incident custom fields on event orchestration.

Changes:

  • (Temporary) Points to the tagged go-lang client that supports Custom Fields (Relavent PR).
  • Added support for incident_custom_field_update action on Event Orchestration.
  • Updated tests to include this action.
  • Updated Event Orchestration documentation to include examples and usage. Also fixed some other documentation errors.

Notice: Custom Fields on Event Orchestration are not available in production. This will need appropriate permission to apply correctly when it is released (ETA Jan/Feb 2024).

Example stack which uses the new custom field. This can be run today but will produce a warning.

# Configure the PagerDuty provider
terraform {
  required_providers {
    pagerduty = {
      source  = "pagerduty/pagerduty"
      version = ">= 2.2.1"
    }
  }
}

resource "pagerduty_team" "test_team" {
  name = "TF Test Team"
}

resource "pagerduty_user" "example" {
  name  = "Terraform User"
  email = "[email protected]"
}

resource "pagerduty_team_membership" "foo" {
  user_id = pagerduty_user.example.id
  team_id = pagerduty_team.test_team.id
  role    = "manager"
}

provider "pagerduty" {
  token = "u+yn5DMNPMq3LQ_oCRyQ"

}

resource "pagerduty_escalation_policy" "example" {
  name      = "Engineering Escalation Policy"
  num_loops = 2

  rule {
    escalation_delay_in_minutes = 60
    target {
      type = "user_reference"
      id   = pagerduty_user.example.id
    }
  }
}

resource "pagerduty_incident_custom_field" "cs_impact" {
  name       = "impact"
  display_name = "Impact"
  data_type  = "string"
  field_type = "single_value"
}

resource "pagerduty_incident_custom_field" "another" {
  name       = "another"
  display_name = "another"
  data_type  = "string"
  field_type = "single_value"
}

resource "pagerduty_service" "example" {
  name                    = "TF test"
  auto_resolve_timeout    = 14400
  acknowledgement_timeout = 600
  escalation_policy       = pagerduty_escalation_policy.example.id
  alert_creation          = "create_alerts_and_incidents"
}

resource "pagerduty_event_orchestration_service" "www" {
  service = pagerduty_service.example.id
  enable_event_orchestration_for_service = true
  set {
    id = "start"
    rule {
      label = "Always apply some consistent event transformations to all events"
      actions {
        variable {
          name = "hostname"
          path = "event.component"
          value = "hostname: (.*)"
          type = "regex"
        }
        extraction {
          # Demonstrating a template-style extraction
          template = "{{variables.hostname}}"
          target = "event.custom_details.hostname"
        }
        extraction {
          # Demonstrating a regex-style extraction
          source = "event.source"
          regex = "www (.*) service"
          target = "event.source"
        }
        incident_custom_field_update {
          id = pagerduty_incident_custom_field.cs_impact.id
          value = "High"
        }

        incident_custom_field_update {
          id = pagerduty_incident_custom_field.another.id
          value = "zzzz"
        }
        # Id of the next set
        route_to = "step-two"
      }
    }
  }
  set {
    id = "step-two"
    rule {
      label = "If there's something wrong on the canary let the team know about it in our deployments Slack channel"
      condition {
        expression = "event.custom_details.hostname matches part 'canary'"
      }
      # create webhook action with parameters and headers
      actions {
        automation_action {
          name = "Canary Slack Notification"
          url = "https://our-slack-listerner.test/canary-notification"
          auto_send = true
          parameter {
            key = "channel"
            value = "#my-team-channel"
          }
          parameter {
            key = "message"
            value = "something is wrong with the canary deployment"
          }
          header {
            key = "X-Notification-Source"
            value = "PagerDuty Incident Webhook"
          }
        }
      }
    }
    rule {
      label = "Never bother the on-call for info-level events outside of work hours"
      condition {
        expression = "event.severity matches 'info' and not (now in Mon,Tue,Wed,Thu,Fri 09:00:00 to 17:00:00 America/Los_Angeles)"
      }
      actions {
        suppress = true
      }
    }
  }
  catch_all {
    actions { }
  }
}

go.mod Outdated Show resolved Hide resolved
Copy link
Contributor

@alenapan alenapan left a comment

Choose a reason for hiding this comment

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

Added a question in the markdown file, otherwise LGTM 👍

website/docs/r/event_orchestration_global.html.markdown Outdated Show resolved Hide resolved
Copy link
Contributor

@imjaroiswebdev imjaroiswebdev left a comment

Choose a reason for hiding this comment

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

Vendored dependencies should be updated to reflect latest changes on heimweh/go-pagerduty#139, otherwise LGTM 👍🏽

@imjaroiswebdev imjaroiswebdev marked this pull request as ready for review February 26, 2024 20:21
@imjaroiswebdev imjaroiswebdev self-requested a review February 26, 2024 20:22
Copy link
Contributor

@imjaroiswebdev imjaroiswebdev left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

@imjaroiswebdev imjaroiswebdev merged commit 50c2c13 into PagerDuty:master Feb 26, 2024
1 check passed
@swbradshaw swbradshaw deleted the ORCA-4263 branch February 26, 2024 20:23
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.

3 participants