Skip to content

Commit

Permalink
feat(v2-canary): canary result endpoint, metric set list pair endpoin…
Browse files Browse the repository at this point in the history
…t, refactoring (#482)
  • Loading branch information
danielpeach authored Dec 4, 2017
1 parent c251f48 commit 4e98950
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,37 @@ class V2CanaryConfigController {

@ApiOperation(value = "Retrieve a list of canary configurations")
@RequestMapping(method = RequestMethod.GET)
List getCanaryConfigs(@RequestParam(value = "application", required = false) String application) {
canaryConfigService.getCanaryConfigs(application)
List getCanaryConfigs(@RequestParam(value = "application", required = false) String application,
@RequestParam(value = "configurationAccountName", required = false) String configurationAccountName) {
canaryConfigService.getCanaryConfigs(application, configurationAccountName)
}

@ApiOperation(value = "Retrieve a canary configuration by id")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
Map getCanaryConfig(@PathVariable String id) {
canaryConfigService.getCanaryConfig(id)
Map getCanaryConfig(@PathVariable String id,
@RequestParam(value = "configurationAccountName", required = false) String configurationAccountName) {
canaryConfigService.getCanaryConfig(id, configurationAccountName)
}

@ApiOperation(value = "Create a canary configuration")
@RequestMapping(method = RequestMethod.POST)
Map createCanaryConfig(@RequestBody Map config) {
canaryConfigService.createCanaryConfig(config)
Map createCanaryConfig(@RequestBody Map config,
@RequestParam(value = "configurationAccountName", required = false) String configurationAccountName) {
canaryConfigService.createCanaryConfig(config, configurationAccountName)
}

@ApiOperation(value = "Update a canary configuration")
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
Map updateCanaryConfig(@PathVariable String id, @RequestBody Map config) {
canaryConfigService.updateCanaryConfig(id, config)
Map updateCanaryConfig(@PathVariable String id,
@RequestParam(value = "configurationAccountName", required = false) String configurationAccountName,
@RequestBody Map config) {
canaryConfigService.updateCanaryConfig(id, config, configurationAccountName)
}

@ApiOperation(value = "Delete a canary configuration")
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
void deleteCanaryConfig(@PathVariable String id) {
canaryConfigService.deleteCanaryConfig(id)
void deleteCanaryConfig(@PathVariable String id,
@RequestParam(value = "configurationAccountName", required = false) String configurationAccountName) {
canaryConfigService.deleteCanaryConfig(id, configurationAccountName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,51 @@

package com.netflix.spinnaker.gate.controllers

import com.netflix.spinnaker.gate.services.internal.KayentaService
import com.netflix.spinnaker.gate.services.V2CanaryService
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping('/v2/canaries')
@ConditionalOnExpression('${services.kayenta.enabled:false}')
class V2CanaryController {

@Autowired
KayentaService kayentaService
V2CanaryService v2CanaryService

@ApiOperation(value = "Retrieve a list of configured Kayenta accounts")
@RequestMapping(value = '/v2/canaries/credentials', method = RequestMethod.GET)
@ApiOperation(value = 'Retrieve a list of configured Kayenta accounts')
@RequestMapping(value = '/credentials', method = RequestMethod.GET)
List listCredentials() {
kayentaService.getCredentials()
v2CanaryService.getCredentials()
}

@ApiOperation(value = "Retrieve a list of all configured canary judges")
@RequestMapping(value = "/v2/canaries/judges", method = RequestMethod.GET)
@ApiOperation(value = 'Retrieve a list of all configured canary judges')
@RequestMapping(value = '/judges', method = RequestMethod.GET)
List listJudges() {
kayentaService.listJudges()
v2CanaryService.listJudges()
}

@ApiOperation(value = "Retrieve a list of canary judge results")
@RequestMapping(value = "/v2/canaries/canaryJudgeResult", method = RequestMethod.GET)
List listResults() {
kayentaService.listResults()
@ApiOperation(value = 'Retrieve a canary result')
@RequestMapping(value = '/canary/{canaryConfigId}/{canaryExecutionId}', method = RequestMethod.GET)
Map getCanaryResult(@PathVariable String canaryConfigId,
@PathVariable String canaryExecutionId,
@RequestParam(value='storageAccountName', required = false) String storageAccountName) {
v2CanaryService.getCanaryResults(canaryConfigId, canaryExecutionId, storageAccountName)
}

@ApiOperation(value = "Retrieve a canary judge result by id")
@RequestMapping(value = "/v2/canaries/canaryJudgeResult/{id}", method = RequestMethod.GET)
Map getResult(@PathVariable String id) {
kayentaService.getResult(id)

// TODO(dpeach): remove this endpoint when a Kayenta endpoint for
// retrieving a single metric set pair exists.
@ApiOperation(value = 'Retrieve a metric set pair list')
@RequestMapping(value = '/metricSetPairList/{metricSetPairListId}', method = RequestMethod.GET)
List getMetricSetPairList(@PathVariable String metricSetPairListId,
@RequestParam(value='storageAccountName', required = false) String storageAccountName) {
v2CanaryService.getMetricSetPairList(metricSetPairListId, storageAccountName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package com.netflix.spinnaker.gate.services

interface CanaryConfigService {
List getCanaryConfigs(String application)
Map getCanaryConfig(String id)
Map createCanaryConfig(Map config)
Map updateCanaryConfig(String id, Map config)
void deleteCanaryConfig(String id)
List getCanaryConfigs(String application, String configurationAccountName)
Map getCanaryConfig(String id, String configurationAccountName)
Map createCanaryConfig(Map config, String configurationAccountName)
Map updateCanaryConfig(String id, Map config, String configurationAccountName)
void deleteCanaryConfig(String id, String configurationAccountName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,70 @@ import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
import org.springframework.stereotype.Component
import retrofit.RetrofitError
import retrofit.client.Response
import retrofit.mime.TypedByteArray

import static com.netflix.spinnaker.gate.retrofit.UpstreamBadRequest.classifyError

@CompileStatic
@Component
@Slf4j
@ConditionalOnExpression('${services.kayenta.enabled:false} and ${services.kayenta.canaryConfigStore:false}')
class KayentaCanaryConfigService implements CanaryConfigService {
private static final String GROUP = "canaryConfigs"

private static final String HYSTRIX_GROUP = "v2-canaryConfigs"

@Autowired
KayentaService kayentaService

List getCanaryConfigs(String application) {
HystrixFactory.newListCommand(GROUP, "getCanaryConfigs") {
kayentaService.getCanaryConfigs(application)
} execute()
List getCanaryConfigs(String application, String configurationAccountName) {
return HystrixFactory.newListCommand(HYSTRIX_GROUP, "getCanaryConfigs", {
try {
return kayentaService.getCanaryConfigs(application, configurationAccountName)
} catch (RetrofitError e) {
throw classifyError(e)
}
}).execute() as List
}

Map getCanaryConfig(String id) {
HystrixFactory.newMapCommand(GROUP, "getCanaryConfig") {
kayentaService.getCanaryConfig(id)
} execute()
Map getCanaryConfig(String id, String configurationAccountName) {
return HystrixFactory.newMapCommand(HYSTRIX_GROUP, "getCanaryConfig", {
try {
return kayentaService.getCanaryConfig(id, configurationAccountName)
} catch (RetrofitError e) {
throw classifyError(e)
}
}).execute() as Map
}

Map createCanaryConfig(Map config) {
HystrixFactory.newMapCommand(GROUP, "createCanaryConfig") {
kayentaService.createCanaryConfig(config)
} execute()
Map createCanaryConfig(Map config, String configurationAccountName) {
return HystrixFactory.newMapCommand(HYSTRIX_GROUP, "createCanaryConfig", {
try {
return kayentaService.createCanaryConfig(config, configurationAccountName)
} catch (RetrofitError e) {
throw classifyError(e)
}
}).execute() as Map
}

Map updateCanaryConfig(String id, Map config) {
HystrixFactory.newMapCommand(GROUP, "updateCanaryConfig") {
kayentaService.updateCanaryConfig(id, config)
} execute()
Map updateCanaryConfig(String id, Map config, String configurationAccountName) {
return HystrixFactory.newMapCommand(HYSTRIX_GROUP, "updateCanaryConfig", {
try {
return kayentaService.updateCanaryConfig(id, config, configurationAccountName)
} catch (RetrofitError e) {
throw classifyError(e)
}
}).execute() as Map
}

void deleteCanaryConfig(String id) {
HystrixFactory.newMapCommand(GROUP, "deleteCanaryConfig") {
kayentaService.deleteCanaryConfig(id)
} execute()
void deleteCanaryConfig(String id, String configurationAccountName) {
HystrixFactory.newVoidCommand(HYSTRIX_GROUP, "deleteCanaryConfig", {
try {
kayentaService.deleteCanaryConfig(id, configurationAccountName)
} catch (RetrofitError e) {
throw classifyError(e)
}
}).execute()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2017 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.netflix.spinnaker.gate.services

import static com.netflix.spinnaker.gate.retrofit.UpstreamBadRequest.classifyError

import com.netflix.spinnaker.gate.services.commands.HystrixFactory
import com.netflix.spinnaker.gate.services.internal.KayentaService
import groovy.transform.CompileStatic
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
import org.springframework.stereotype.Component
import retrofit.RetrofitError

@Component
@CompileStatic
@ConditionalOnExpression('${services.kayenta.enabled:false}')
class V2CanaryService {

private static final String HYSTRIX_GROUP = "v2-canaries"

@Autowired
KayentaService kayentaService

List getCredentials() {
return HystrixFactory.newListCommand(HYSTRIX_GROUP, "getCanaryCredentials", {
try {
return kayentaService.getCredentials()
} catch (RetrofitError error) {
throw classifyError(error)
}
}).execute() as List
}

List listJudges() {
return HystrixFactory.newListCommand(HYSTRIX_GROUP, "listCanaryJudges", {
try {
return kayentaService.listJudges()
} catch (RetrofitError error) {
throw classifyError(error)
}
}).execute() as List
}

Map getCanaryResults(String canaryConfigId, String canaryExecutionId, String storageAccountName) {
return HystrixFactory.newMapCommand(HYSTRIX_GROUP, "getCanaryResults", {
try {
return kayentaService.getCanaryResult(canaryConfigId, canaryExecutionId, storageAccountName)
} catch (RetrofitError error) {
throw classifyError(error)
}
}).execute() as Map
}

List getMetricSetPairList(String metricSetPairListId, String storageAccountName) {
return HystrixFactory.newListCommand(HYSTRIX_GROUP, "getMetricSetPairList", {
try {
return kayentaService.getMetricSetPairList(metricSetPairListId, storageAccountName)
} catch (RetrofitError error) {
throw classifyError(error)
}
}).execute() as List
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,35 @@ interface KayentaService {
List getCredentials()

@GET("/canaryConfig")
List getCanaryConfigs(@Query("application") String application)
List getCanaryConfigs(@Query("application") String application,
@Query("configurationAccountName") String configurationAccountName)

@GET("/canaryConfig/{id}")
Map getCanaryConfig(@Path("id") String id)
Map getCanaryConfig(@Path("id") String id,
@Query("configurationAccountName") String configurationAccountName)

@POST("/canaryConfig")
Map createCanaryConfig(@Body Map config)
Map createCanaryConfig(@Body Map config,
@Query("configurationAccountName") String configurationAccountName)

@PUT("/canaryConfig/{id}")
Map updateCanaryConfig(@Path("id") String id, @Body Map config)
Map updateCanaryConfig(@Path("id") String id,
@Body Map config,
@Query("configurationAccountName") String configurationAccountName)

@DELETE("/canaryConfig/{id}")
Response deleteCanaryConfig(@Path("id") String id)
Response deleteCanaryConfig(@Path("id") String id,
@Query("configurationAccountName") String configurationAccountName)

@GET("/judges")
List listJudges()

@GET("/canaryJudgeResult")
List listResults()
@GET("/canary/{canaryConfigId}/{canaryExecutionId}")
Map getCanaryResult(@Path("canaryConfigId") String canaryConfigId,
@Path("canaryExecutionId") String canaryExecutionId,
@Query("storageAccountName") String storageAccountName)

@GET("/canaryJudgeResult/{id}")
Map getResult(@Path("id") String id)
@GET("/metricSetPairList/{metricSetPairListId}")
List getMetricSetPairList(@Path("metricSetPairListId") metricSetPairListId,
@Query("accountName") String storageAccountName)
}

0 comments on commit 4e98950

Please sign in to comment.