-
Notifications
You must be signed in to change notification settings - Fork 633
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kayenta): Prepare automated integration tests for kayenta (#594)
* feat(kayenta): Prepare automated integration tests for kayenta, simple successfull and failure cases added based on prometheus and s3 integrations * chore: add graphite into integration tests module * chore: optionally enable integration tests * chore: enable integration tests in travis and fix merge conflict * fix(standalone-canary-analysis): Fixed bad Intellij refactor that changed the conditional prop for the module preventing it from being loaded
- Loading branch information
Showing
30 changed files
with
1,214 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
kayenta-integration-tests/kayenta-integration-tests.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
dependencies { | ||
|
||
testCompile project(":kayenta-web") | ||
testCompile 'io.rest-assured:rest-assured:3.1.1' | ||
testCompile 'org.awaitility:awaitility:3.1.6' | ||
testCompile 'io.micrometer:micrometer-registry-prometheus' | ||
testCompile 'io.micrometer:micrometer-registry-graphite' | ||
testCompile 'org.springframework.cloud:spring-cloud-starter:2.1.2.RELEASE'// needed for bootstrap phase when all embedded containers are setup | ||
testCompile 'com.playtika.testcontainers:embedded-redis:1.25' | ||
testCompile 'com.playtika.testcontainers:embedded-minio:1.25' | ||
} | ||
|
||
test.testLogging { | ||
showStandardStreams = true | ||
} | ||
|
||
gradle.taskGraph.whenReady { | ||
tasks.test.enabled = ( | ||
properties.getOrDefault('ENABLE_INTEGRATION_TESTS', 'false') == 'true' | ||
|| System.getProperty('ENABLE_INTEGRATION_TESTS', 'false') == 'true' | ||
|| System.getenv().getOrDefault('ENABLE_INTEGRATION_TESTS', 'false') == 'true' | ||
) | ||
} |
75 changes: 75 additions & 0 deletions
75
...c/test/java/com/netflix/kayenta/configuration/EmbeddedGraphiteBootstrapConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2019 Playtika | ||
* | ||
* 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.kayenta.configuration; | ||
|
||
import static com.playtika.test.common.utils.ContainerUtils.containerLogsConsumer; | ||
|
||
import com.netflix.kayenta.utils.EnvironmentUtils; | ||
import java.time.Duration; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.env.ConfigurableEnvironment; | ||
import org.testcontainers.containers.BindMode; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy; | ||
import org.testcontainers.containers.wait.strategy.WaitStrategy; | ||
|
||
@Slf4j | ||
@Configuration | ||
public class EmbeddedGraphiteBootstrapConfiguration { | ||
private static final int PICKLE_RECEIVER_PORT = 2004; | ||
private static final int HTTP_PORT = 80; | ||
|
||
@Bean(name = "graphiteWaitStrategy") | ||
public WaitStrategy graphiteWaitStrategy() { | ||
return new HostPortWaitStrategy(); | ||
} | ||
|
||
@Bean(name = "graphite", destroyMethod = "stop") | ||
public GenericContainer graphite( | ||
ConfigurableEnvironment environment, WaitStrategy graphiteWaitStrategy) { | ||
|
||
GenericContainer container = | ||
new GenericContainer("graphiteapp/graphite-statsd:1.1.5-12") | ||
.withLogConsumer(containerLogsConsumer(log)) | ||
.withExposedPorts(PICKLE_RECEIVER_PORT) | ||
.waitingFor(graphiteWaitStrategy) | ||
.withClasspathResourceMapping( | ||
"/external/graphite/storage-schemas.conf", | ||
"/opt/graphite/conf/storage-schemas.conf", | ||
BindMode.READ_ONLY) | ||
.withStartupTimeout(Duration.ofSeconds(30)); | ||
container.start(); | ||
|
||
Map<String, Object> map = registerEnvironment(environment, container); | ||
log.info("Started Graphite server. Connection details: {}", map); | ||
return container; | ||
} | ||
|
||
@NotNull | ||
private Map<String, Object> registerEnvironment( | ||
ConfigurableEnvironment environment, GenericContainer container) { | ||
Map<String, Object> map = new LinkedHashMap<>(); | ||
map.put("embedded.graphite.picklePort", container.getMappedPort(PICKLE_RECEIVER_PORT)); | ||
map.put("embedded.graphite.httpPort", container.getMappedPort(HTTP_PORT)); | ||
EnvironmentUtils.registerPropertySource("embeddedGraphiteInfo", environment, map); | ||
return map; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...test/java/com/netflix/kayenta/configuration/EmbeddedPrometheusBootstrapConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2019 Playtika | ||
* | ||
* 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.kayenta.configuration; | ||
|
||
import static com.playtika.test.common.utils.ContainerUtils.containerLogsConsumer; | ||
|
||
import com.netflix.kayenta.utils.EnvironmentUtils; | ||
import java.time.Duration; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.env.ConfigurableEnvironment; | ||
import org.testcontainers.Testcontainers; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy; | ||
import org.testcontainers.containers.wait.strategy.WaitStrategy; | ||
import org.testcontainers.utility.MountableFile; | ||
|
||
@Slf4j | ||
@Configuration | ||
public class EmbeddedPrometheusBootstrapConfiguration { | ||
|
||
// Exposes host machine port to be used by prometheus container for scraping metrics from | ||
// /prometehus endpoint | ||
// See for more details: | ||
// https://www.testcontainers.org/features/networking/#exposing-host-ports-to-the-container | ||
static { | ||
Testcontainers.exposeHostPorts(8081); | ||
} | ||
|
||
private static final int PORT = 9090; | ||
|
||
@Bean(name = "prometheusWaitStrategy") | ||
public WaitStrategy prometheusWaitStrategy() { | ||
return new HttpWaitStrategy().forPath("/status").forPort(PORT).forStatusCode(200); | ||
} | ||
|
||
@Bean(name = "prometheus", destroyMethod = "stop") | ||
public GenericContainer prometheus( | ||
ConfigurableEnvironment environment, WaitStrategy prometheusWaitStrategy) { | ||
|
||
GenericContainer container = | ||
new GenericContainer("prom/prometheus:v2.10.0") | ||
.withLogConsumer(containerLogsConsumer(log)) | ||
.withExposedPorts(PORT) | ||
.withCopyFileToContainer( | ||
MountableFile.forClasspathResource("/external/prometheus/prometheus.yml"), | ||
"/etc/prometheus/prometheus.yml") | ||
.waitingFor(prometheusWaitStrategy) | ||
.withStartupTimeout(Duration.ofSeconds(30)); | ||
container.start(); | ||
Map<String, Object> env = registerEnvironment(environment, container.getMappedPort(PORT)); | ||
log.info("Started Prometheus server. Connection details: {}", env); | ||
return container; | ||
} | ||
|
||
static Map<String, Object> registerEnvironment(ConfigurableEnvironment environment, int port) { | ||
Map<String, Object> map = new LinkedHashMap<>(); | ||
map.put("embedded.prometheus.port", port); | ||
EnvironmentUtils.registerPropertySource("embeddedPrometheusInfo", environment, map); | ||
return map; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...-tests/src/test/java/com/netflix/kayenta/configuration/MetricsReportingConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2019 Playtika | ||
* | ||
* 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.kayenta.configuration; | ||
|
||
import com.netflix.kayenta.metrics.CanaryAnalysisCasesConfigurationProperties; | ||
import com.netflix.kayenta.metrics.MetricsGenerator; | ||
import com.netflix.kayenta.metrics.PercentilePrecisionMeterConfigurationFilter; | ||
import com.netflix.kayenta.metrics.RandomProvider; | ||
import com.netflix.kayenta.steps.StandaloneCanaryAnalysisSteps; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.config.MeterFilter; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@EnableConfigurationProperties(CanaryAnalysisCasesConfigurationProperties.class) | ||
@Configuration | ||
public class MetricsReportingConfiguration { | ||
|
||
@Bean | ||
public RandomProvider randomProvider() { | ||
return new RandomProvider(); | ||
} | ||
|
||
@Bean | ||
public MetricsGenerator metricsGenerator( | ||
MeterRegistry registry, | ||
RandomProvider randomProvider, | ||
CanaryAnalysisCasesConfigurationProperties configuration) { | ||
return new MetricsGenerator(registry, randomProvider, configuration); | ||
} | ||
|
||
@Bean | ||
public StandaloneCanaryAnalysisSteps canaryAnalysisSteps( | ||
@Value("${server.port}") int serverPort, | ||
CanaryAnalysisCasesConfigurationProperties configuration) { | ||
return new StandaloneCanaryAnalysisSteps(serverPort, configuration); | ||
} | ||
|
||
@Bean | ||
public MeterFilter percentilePrecisionConfigurationFilter() { | ||
return new PercentilePrecisionMeterConfigurationFilter(); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...src/test/java/com/netflix/kayenta/metrics/CanaryAnalysisCasesConfigurationProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright 2019 Playtika | ||
* | ||
* 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.kayenta.metrics; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotEmpty; | ||
import javax.validation.constraints.NotNull; | ||
import lombok.Data; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
@Data | ||
@Validated | ||
@ConfigurationProperties("canary-analysis") | ||
public class CanaryAnalysisCasesConfigurationProperties { | ||
|
||
@Valid private Map<String, AnalysisConfiguration> cases; | ||
|
||
public AnalysisConfiguration get(String caseName) { | ||
AnalysisConfiguration config = cases.get(caseName); | ||
if (config == null) { | ||
throw new IllegalStateException("Case " + caseName + " not configured"); | ||
} | ||
return config; | ||
} | ||
|
||
@Data | ||
public static class AnalysisConfiguration { | ||
|
||
@NotNull private Long lifetimeDurationMinutes; | ||
@NotNull private Long analysisIntervalMinutes; | ||
@NotNull private String namespace; | ||
@NotNull private ScopeMetricsConfiguration control; | ||
@NotNull private ScopeMetricsConfiguration experiment; | ||
} | ||
|
||
@Data | ||
public static class ScopeMetricsConfiguration { | ||
|
||
@NotNull private String scope; | ||
@Valid @NotNull private List<MetricConfiguration> metrics; | ||
} | ||
|
||
@Data | ||
public static class MetricConfiguration { | ||
|
||
@NotEmpty private String name; | ||
@NotNull private Integer lowerBound; | ||
@NotNull private Integer upperBound; | ||
@NotNull private String type; | ||
} | ||
} |
Oops, something went wrong.