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

chore(upgrade): Migrate to openapi swagger spec #1046

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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 @@ -23,7 +23,7 @@
import com.netflix.kayenta.metrics.SynchronousQueryProcessor;
import com.netflix.kayenta.security.AccountCredentials;
import com.netflix.kayenta.security.AccountCredentialsRepository;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.Parameter;
import java.io.IOException;
import java.time.Instant;
import java.util.Collections;
Expand Down Expand Up @@ -55,14 +55,14 @@ public AtlasFetchController(
public Map queryMetrics(
@RequestParam(required = false) final String metricsAccountName,
@RequestParam(required = false) final String storageAccountName,
@ApiParam(defaultValue = "name,CpuRawUser,:eq,:sum") @RequestParam String q,
@ApiParam(defaultValue = "cpu") @RequestParam String metricSetName,
@ApiParam(defaultValue = "cluster") @RequestParam String type,
@Parameter(example = "name,CpuRawUser,:eq,:sum") @RequestParam String q,
@Parameter(example = "cpu") @RequestParam String metricSetName,
@Parameter(example = "cluster") @RequestParam String type,
@RequestParam String scope,
@ApiParam(defaultValue = "us-east-1") @RequestParam String location,
@ApiParam(defaultValue = "2000-01-01T00:00:00Z") @RequestParam Instant start,
@ApiParam(defaultValue = "2000-01-01T04:00:00Z") @RequestParam Instant end,
@ApiParam(defaultValue = "300") @RequestParam Long step)
@Parameter(example = "us-east-1") @RequestParam String location,
@Parameter(example = "2000-01-01T00:00:00Z") @RequestParam Instant start,
@Parameter(example = "2000-01-01T04:00:00Z") @RequestParam Instant end,
@Parameter(example = "300") @RequestParam Long step)
throws IOException {
String resolvedMetricsAccountName =
accountCredentialsRepository
Expand Down
3 changes: 1 addition & 2 deletions kayenta-core/kayenta-core.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ dependencies {
api "io.spinnaker.kork:kork-retrofit"
api "com.netflix.spectator:spectator-api"

api "io.swagger:swagger-annotations"

api "io.spinnaker.orca:orca-core"
api "io.spinnaker.orca:orca-retrofit"

Expand All @@ -16,6 +14,7 @@ dependencies {
api "net.logstash.logback:logstash-logback-encoder"

api "javax.validation:validation-api"
api "io.swagger.core.v3:swagger-annotations"

testImplementation "io.spinnaker.kork:kork-jedis-test"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
package com.netflix.kayenta.canary;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Map;
import javax.validation.constraints.NotNull;
import lombok.*;
Expand All @@ -28,19 +27,19 @@
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModel(description = "The classification configuration, such as group weights.")
@Schema(description = "The classification configuration, such as group weights.")
public class CanaryClassifierConfig {

@ApiModelProperty(
value =
@Schema(
description =
"List of each metrics group along with its corresponding weight. Weights must total 100.",
example = "{\"pod-group\": 70, \"app-group\": 30}")
@NotNull
@Singular
@Getter
private Map<String, Double> groupWeights;

@ApiModelProperty(hidden = true)
@Schema(hidden = true)
@Getter
private CanaryClassifierThresholdsConfig scoreThresholds;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
package com.netflix.kayenta.canary;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.NotNull;
import lombok.*;

Expand All @@ -27,18 +26,19 @@
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModel(description = "Sets thresholds for canary score.")
@Schema(description = "Sets thresholds for canary score.")
public class CanaryClassifierThresholdsConfig {

@ApiModelProperty(
value = "If canary score is higher than this value -- canary is considered successful.",
@Schema(
description = "If canary score is higher than this value -- canary is considered successful.",
example = "75.0")
@NotNull
@Getter
private Double pass;

@ApiModelProperty(
value = "If canary score is lower than this value -- canary is considered marginal (failed).",
@Schema(
description =
"If canary score is lower than this value -- canary is considered marginal (failed).",
example = "50.0")
@NotNull
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
package com.netflix.kayenta.canary;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Map;
import javax.validation.constraints.NotNull;
import lombok.*;
Expand All @@ -28,19 +27,19 @@
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModel(description = "Judge configuration.")
@Schema(description = "Judge configuration.")
public class CanaryJudgeConfig {

@ApiModelProperty(
value = "Judge to use, as of right now there is only `NetflixACAJudge-v1.0`.",
@Schema(
description = "Judge to use, as of right now there is only `NetflixACAJudge-v1.0`.",
example = "NetflixACAJudge-v1.0",
required = true)
@NotNull
@Getter
private String name;

@ApiModelProperty(
value =
@Schema(
description =
"Additional judgement configuration. As of right now, this should always be an empty object.",
example = "{}",
required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import com.netflix.kayenta.metrics.SynchronousQueryProcessor;
import com.netflix.kayenta.security.AccountCredentials;
import com.netflix.kayenta.security.AccountCredentialsRepository;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import java.io.IOException;
import java.time.Instant;
import java.util.Map;
Expand Down Expand Up @@ -61,18 +62,21 @@ public DatadogFetchController(
public Map queryMetrics(
@RequestParam(required = false) final String metricsAccountName,
@RequestParam(required = false) final String storageAccountName,
@ApiParam(defaultValue = "cpu") @RequestParam String metricSetName,
@ApiParam(defaultValue = "avg:system.cpu.user") @RequestParam String metricName,
@ApiParam(value = "The scope of the Datadog query. e.g. autoscaling_group:myapp-prod-v002")
@Parameter(example = "cpu") @RequestParam String metricSetName,
@Parameter(example = "avg:system.cpu.user") @RequestParam String metricName,
@Parameter(
description =
"The scope of the Datadog query. e.g. autoscaling_group:myapp-prod-v002")
@RequestParam(required = false)
String scope,
@ApiParam(value = "An ISO format timestamp, e.g.: 2018-03-15T01:23:45Z")
@Parameter(description = "An ISO format timestamp, e.g.: 2018-03-15T01:23:45Z")
@RequestParam(required = false)
String start,
@ApiParam(value = "An ISO format timestamp, e.g.: 2018-03-15T01:23:45Z")
@Parameter(description = "An ISO format timestamp, e.g.: 2018-03-15T01:23:45Z")
@RequestParam(required = false)
String end,
@ApiParam(defaultValue = "false") @RequestParam(required = false) final boolean dryRun)
@Parameter(schema = @Schema(defaultValue = "false")) @RequestParam(required = false)
final boolean dryRun)
throws IOException {
// Apply defaults.
scope =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.netflix.kayenta.metrics.SynchronousQueryProcessor;
import com.netflix.kayenta.security.AccountCredentials;
import com.netflix.kayenta.security.AccountCredentialsRepository;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.Parameter;
import java.io.IOException;
import java.time.Instant;
import java.util.Collections;
Expand Down Expand Up @@ -63,25 +63,25 @@ public GraphiteFetchController(
public Map queryMetrics(
@RequestParam(required = false) final String metricsAccountName,
@RequestParam(required = false) final String storageAccountName,
@ApiParam(defaultValue = "cpu") @RequestParam String metricSetName,
@ApiParam(defaultValue = "system.$location.$scope") @RequestParam String metricName,
@ApiParam(
value =
@Parameter(example = "cpu") @RequestParam String metricSetName,
@Parameter(example = "system.$location.$scope") @RequestParam String metricName,
@Parameter(
description =
"The name of the resource to use when scoping the query. "
+ "This parameter will replace $scope in metricName")
@RequestParam(required = false)
String scope,
@ApiParam(
value =
@Parameter(
description =
"The name of the resource to use when locating the query. "
+ "This parameter will replace $location in metricName")
@RequestParam(required = false)
String location,
@ApiParam(value = "An ISO format timestamp, e.g.: 2018-03-15T01:23:45Z") @RequestParam
@Parameter(description = "An ISO format timestamp, e.g.: 2018-03-15T01:23:45Z") @RequestParam
String start,
@ApiParam(value = "An ISO format timestamp, e.g.: 2018-03-15T01:23:45Z") @RequestParam
@Parameter(description = "An ISO format timestamp, e.g.: 2018-03-15T01:23:45Z") @RequestParam
String end,
@ApiParam(defaultValue = "false") @RequestParam(required = false) final boolean dryRun)
@Parameter(example = "false") @RequestParam(required = false) final boolean dryRun)
throws IOException {

start =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.netflix.kayenta.metrics.SynchronousQueryProcessor;
import com.netflix.kayenta.security.AccountCredentials;
import com.netflix.kayenta.security.AccountCredentialsRepository;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.Parameter;
import java.io.IOException;
import java.time.Instant;
import java.util.Collections;
Expand Down Expand Up @@ -64,21 +64,23 @@ public InfluxDbFetchController(
public Map<String, String> queryMetrics(
@RequestParam(required = false) final String metricsAccountName,
@RequestParam(required = false) final String storageAccountName,
@ApiParam(defaultValue = "cpu") @RequestParam String metricSetName,
@ApiParam(defaultValue = "temperature") @RequestParam String metricName,
@ApiParam(value = "Fields that are being queried. e.g. internal, external")
@Parameter(example = "cpu") @RequestParam String metricSetName,
@Parameter(example = "temperature") @RequestParam String metricName,
@Parameter(description = "Fields that are being queried. e.g. internal, external")
@RequestParam(required = false)
List<String> fields,
@ApiParam(value = "The scope of the Influxdb query. e.g. autoscaling_group:myapp-prod-v002")
@Parameter(
description =
"The scope of the Influxdb query. e.g. autoscaling_group:myapp-prod-v002")
@RequestParam(required = false)
String scope,
@ApiParam(value = "An ISO format timestamp, e.g.: 2018-03-15T01:23:45Z")
@Parameter(description = "An ISO format timestamp, e.g.: 2018-03-15T01:23:45Z")
@RequestParam(required = false)
String start,
@ApiParam(value = "An ISO format timestamp, e.g.: 2018-03-15T01:23:45Z")
@Parameter(description = "An ISO format timestamp, e.g.: 2018-03-15T01:23:45Z")
@RequestParam(required = false)
String end,
@ApiParam(defaultValue = "60", value = "seconds") @RequestParam Long step)
@Parameter(example = "60", description = "seconds") @RequestParam Long step)
throws IOException {
// Apply defaults.
scope =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import com.netflix.kayenta.newrelic.config.NewRelicConfigurationTestControllerDefaultProperties;
import com.netflix.kayenta.security.AccountCredentials;
import com.netflix.kayenta.security.AccountCredentialsRepository;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import java.io.IOException;
import java.time.Instant;
import java.util.Map;
Expand Down Expand Up @@ -62,22 +63,25 @@ public NewRelicFetchController(
public Map queryMetrics(
@RequestParam(required = false) final String metricsAccountName,
@RequestParam(required = false) final String storageAccountName,
@ApiParam(required = true) @Valid @RequestBody NewRelicFetchRequest newRelicFetchRequest,
@ApiParam(value = "The scope of the NewRelic query. e.g. autoscaling_group:myapp-prod-v002")
@Parameter(required = true) @Valid @RequestBody NewRelicFetchRequest newRelicFetchRequest,
@Parameter(
description =
"The scope of the NewRelic query. e.g. autoscaling_group:myapp-prod-v002")
@RequestParam(required = false)
String scope,
@ApiParam(value = "The location of the NewRelic query. e.g. us-west-2")
@Parameter(description = "The location of the NewRelic query. e.g. us-west-2")
@RequestParam(required = false)
String location,
@ApiParam(value = "An ISO format timestamp, e.g.: 2018-03-15T01:23:45Z") @RequestParam
@Parameter(description = "An ISO format timestamp, e.g.: 2018-03-15T01:23:45Z") @RequestParam
String start,
@ApiParam(value = "An ISO format timestamp, e.g.: 2018-03-15T01:23:45Z") @RequestParam
@Parameter(description = "An ISO format timestamp, e.g.: 2018-03-15T01:23:45Z") @RequestParam
String end,
@ApiParam(defaultValue = "60", value = "seconds") @RequestParam Long step,
@ApiParam(defaultValue = "0", value = "canary config metrics index")
@Parameter(example = "60", description = "seconds") @RequestParam Long step,
@Parameter(schema = @Schema(defaultValue = "0"), description = "canary config metrics index")
@RequestParam(required = false)
Integer metricIndex,
@ApiParam(defaultValue = "false") @RequestParam(required = false) final boolean dryRun)
@Parameter(schema = @Schema(defaultValue = "false")) @RequestParam(required = false)
final boolean dryRun)
throws IOException {

// Apply defaults.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

import com.netflix.kayenta.canary.CanaryConfig;
import com.netflix.kayenta.canary.CanaryMetricConfig;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
Expand All @@ -31,10 +30,10 @@
@ToString
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "Request body for using the New Relic Fetch controller")
@Schema(description = "Request body for using the New Relic Fetch controller")
class NewRelicFetchRequest {
@NotNull
@ApiModelProperty(value = "The metric config to query New Relic insights for")
@Schema(description = "The metric config to query New Relic insights for")
CanaryMetricConfig canaryMetricConfig;

@NotNull @Builder.Default Map<String, String> extendedScopeParams = new HashMap<>();
Expand Down
1 change: 1 addition & 0 deletions kayenta-orca/kayenta-orca.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dependencies {
api "io.spinnaker.orca:orca-redis"
api "org.springframework.boot:spring-boot-starter-actuator"
api "org.springframework.cloud:spring-cloud-commons"
api "io.swagger.core.v3:swagger-annotations"

// TODO(duftler): Move these to spinnaker-dependencies.
testImplementation "io.spinnaker.orca:orca-test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.netflix.spinnaker.orca.api.pipeline.models.PipelineExecution;
import com.netflix.spinnaker.orca.pipeline.ExecutionLauncher;
import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionRepository;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -97,19 +97,19 @@ void startOrcaQueueProcessing() {
}
}

@ApiOperation(value = "Initiate a pipeline execution")
@Operation(summary = "Initiate a pipeline execution")
@RequestMapping(value = "/start", method = RequestMethod.POST)
String start(@RequestBody Map map) throws Exception {
return startPipeline(map);
}

@ApiOperation(value = "Retrieve a pipeline execution")
@Operation(summary = "Retrieve a pipeline execution")
@RequestMapping(value = "/{executionId}", method = RequestMethod.GET)
PipelineExecution getPipeline(@PathVariable String executionId) {
return executionRepository.retrieve(PIPELINE, executionId);
}

@ApiOperation(value = "Cancel a pipeline execution")
@Operation(summary = "Cancel a pipeline execution")
@RequestMapping(value = "/{executionId}/cancel", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.ACCEPTED)
void cancel(@PathVariable String executionId) {
Expand All @@ -126,7 +126,7 @@ void cancel(@PathVariable String executionId) {
executionRepository.updateStatus(PIPELINE, executionId, ExecutionStatus.CANCELED);
}

@ApiOperation(value = "Delete a pipeline execution")
@Operation(summary = "Delete a pipeline execution")
@RequestMapping(value = "/{executionId}", method = RequestMethod.DELETE)
ResponseEntity delete(@PathVariable String executionId) {
log.info("Deleting pipeline execution {}...", executionId);
Expand All @@ -139,7 +139,7 @@ ResponseEntity delete(@PathVariable String executionId) {
return new ResponseEntity(HttpStatus.OK);
}

@ApiOperation(value = "List all pipeline IDs")
@Operation(summary = "List all pipeline IDs")
@RequestMapping(method = RequestMethod.GET)
List<String> list() {
return executionRepository.retrieveAllExecutionIds(PIPELINE);
Expand Down
Loading
Loading