Skip to content

Commit

Permalink
fix(kayenta): handle exceptions from Kayenta (#2058)
Browse files Browse the repository at this point in the history
  • Loading branch information
robfletcher committed Mar 15, 2018
1 parent 5eaec77 commit b97d741
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ data class CanaryResults(
val startTimeIso: Instant?,
val endTimeIso: Instant?,
val storageAccountName: String?,
val exception: String?
val exception: Map<String, Any>?
) {
@JsonIgnore
val executionStatus = ExecutionStatus.valueOf(status.toUpperCase())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.netflix.spinnaker.orca.kayenta.config.KayentaConfiguration
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import retrofit.Endpoint
Expand Down Expand Up @@ -124,9 +125,11 @@ object KayentaServiceTest : Spek({

describe("fetching canary results") {

val canaryId = "666fa25b-b0c6-421b-b84f-f93826932994"
given("a successful canary result") {
val canaryId = "666fa25b-b0c6-421b-b84f-f93826932994"
val storageAccountName = "my-google-account"

val responseJson = """
val responseJson = """
{
"application": "myapp",
"parentPipelineExecutionId": "9cf4ec2e-29fb-4968-ae60-9182b575b30a",
Expand Down Expand Up @@ -401,30 +404,96 @@ object KayentaServiceTest : Spek({
}
"""

beforeGroup {
stubFor(
get(urlPathEqualTo("/canary/$canaryId"))
.withQueryParam("storageAccountName", equalTo("whatever"))
.willReturn(
aResponse()
.withHeader("Content-Type", "application/json")
.withBody(responseJson)
)
)
beforeGroup {
stubFor(
get(urlPathEqualTo("/canary/$canaryId"))
.withQueryParam("storageAccountName", equalTo(storageAccountName))
.willReturn(
aResponse()
.withHeader("Content-Type", "application/json")
.withBody(responseJson)
)
)
}

it("parses the JSON response correctly") {
subject.getCanaryResults(storageAccountName, canaryId)
.let { response ->
assertThat(response.complete).isTrue()
assertThat(response.buildTimeIso).isEqualTo(Instant.ofEpochMilli(1521059331684))
assertThat(response.endTimeIso).isEqualTo(Instant.ofEpochMilli(1521059341101))
assertThat(response.startTimeIso).isEqualTo(Instant.ofEpochMilli(1521059331909))
assertThat(response.result!!.application).isEqualTo("myapp")
assertThat(response.result!!.canaryDuration).isEqualTo(Duration.ofHours(1))
assertThat(response.result!!.judgeResult.score.score).isEqualTo(33)
assertThat(response.exception).isNull()
}
}
}

it("parses the JSON response correctly") {
subject.getCanaryResults("whatever", canaryId)
.let { response ->
assertThat(response.complete).isTrue()
assertThat(response.buildTimeIso).isEqualTo(Instant.ofEpochMilli(1521059331684))
assertThat(response.endTimeIso).isEqualTo(Instant.ofEpochMilli(1521059341101))
assertThat(response.startTimeIso).isEqualTo(Instant.ofEpochMilli(1521059331909))
assertThat(response.result!!.application).isEqualTo("myapp")
assertThat(response.result!!.canaryDuration).isEqualTo(Duration.ofHours(1))
assertThat(response.result!!.judgeResult.score.score).isEqualTo(33)
assertThat(response.exception).isNull()
}
given("an exception") {

val canaryId = "02a95d21-290c-49f9-8be1-fb0b7779a73a"
val storageAccountName = "my-google-account"

val responseJson = """
{
"application": "myapp",
"parentPipelineExecutionId": "88086da2-3e5a-4a9e-ada7-089ab70a9578",
"pipelineId": "02a95d21-290c-49f9-8be1-fb0b7779a73a",
"stageStatus": {
"fetchControl0": "terminal",
"mixMetrics": "not_started",
"fetchExperiment0": "terminal",
"judge": "not_started",
"setupContext": "succeeded"
},
"complete": true,
"status": "terminal",
"exception": {
"timestamp": 1521127342802,
"exceptionType": "IllegalArgumentException",
"operation": "prometheusFetch",
"details": {
"stackTrace": "java.lang.IllegalArgumentException: Either a resource type or a custom filter is required.\n\tat com.netflix.kayenta.prometheus.metrics.PrometheusMetricsService.addScopeFilter(PrometheusMetricsService.java:112)\n\tat com.netflix.kayenta.prometheus.metrics.PrometheusMetricsService.queryMetrics(PrometheusMetricsService.java:222)\n",
"error": "Unexpected Task Failure",
"errors": [
"Either a resource type or a custom filter is required."
]
},
"shouldRetry": false
},
"buildTimeMillis": 1521127342562,
"buildTimeIso": "2018-03-15T15:22:22.562Z",
"startTimeMillis": 1521127342569,
"startTimeIso": "2018-03-15T15:22:22.569Z",
"endTimeMillis": 1521127342887,
"endTimeIso": "2018-03-15T15:22:22.887Z",
"storageAccountName": "my-google-account"
}
"""

beforeGroup {
stubFor(
get(urlPathEqualTo("/canary/$canaryId"))
.withQueryParam("storageAccountName", equalTo(storageAccountName))
.willReturn(
aResponse()
.withHeader("Content-Type", "application/json")
.withBody(responseJson)
)
)
}

it("parses the JSON response correctly") {
subject.getCanaryResults(storageAccountName, canaryId)
.let { response ->
assertThat(response.complete).isTrue()
assertThat(response.result).isNull()
assertThat(response.exception)
.containsEntry("exceptionType", "IllegalArgumentException")
}
}
}
}
}
Expand Down

0 comments on commit b97d741

Please sign in to comment.