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

feat(pagerduty): Support multiple applications and keys directly #1797

Merged
merged 1 commit into from
Nov 14, 2017
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 @@ -17,6 +17,8 @@

package com.netflix.spinnaker.orca.echo.tasks

import com.fasterxml.jackson.databind.ObjectMapper

import java.util.concurrent.TimeUnit
import com.netflix.spinnaker.orca.RetryableTask
import com.netflix.spinnaker.orca.TaskResult
Expand Down Expand Up @@ -47,27 +49,46 @@ class PageApplicationOwnerTask implements RetryableTask {
if (!front50Service) {
throw new UnsupportedOperationException("Front50 is not enabled, no way to fetch pager duty. Fix this by setting front50.enabled: true");
}
def application = stage.context.application as String
def applicationPagerDutyKey = fetchApplicationPagerDutyKey(application)
if (!applicationPagerDutyKey) {
throw new IllegalStateException("${application} does not have a pager duty service key!")
def applications = stage.context.applications as List<String>
def incomingPagerDutyKeys = stage.context.keys as List<String>
def allPagerDutyKeys = []
Copy link
Contributor

Choose a reason for hiding this comment

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

You can still simplify this further ...

def allPagerDutyKeys = (stage.context.keys as List<String>) ?: []


if (incomingPagerDutyKeys) {
// Add all arbitrary keys to the pager duty key list
allPagerDutyKeys.addAll(incomingPagerDutyKeys)
}

// Add applications to the pager duty key list if they have a valid key
if (applications) {
def invalidApplications = []
applications.each { application ->
def applicationPagerDutyKey = fetchApplicationPagerDutyKey(application)
if (!applicationPagerDutyKey) {
invalidApplications.push(application)
} else {
allPagerDutyKeys.push(applicationPagerDutyKey)
}
}

if (invalidApplications.size() > 0) {
throw new IllegalStateException("${invalidApplications.join(", ")} ${invalidApplications.size() > 1 ? "do" : "does"} not have a pager duty service key.")
}
}

// echo service will not send a proper response back if there is an error, it will just throw an exception
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally speaking this is common knowledge ... not sure it's worth javadoc?

echoService.create(
new EchoService.Notification(
to: [
applicationPagerDutyKey
],
to: allPagerDutyKeys,
notificationType: EchoService.Notification.Type.PAGER_DUTY,
source: new EchoService.Notification.Source(user: stage.execution.authentication.user),
additionalContext: [
message: stage.context.message
message: stage.context.message,
details: stage.context.details
]
)
)

log.info("Sent page (application: ${application}, message: '${stage.context.message}')")

log.info("Sent page (application(s): ${applications.join(", ")}, message: '${stage.context.message}')")
return new TaskResult(SUCCEEDED)
}

Expand Down