Skip to content

Commit

Permalink
adding metrics system tests (kroxylicious#1055)
Browse files Browse the repository at this point in the history
* adding metrics system tests

* make all timeouts of type Duration

* suggested changes

* added suggested changes

* remove TestUtils waitFor method

* reduce code smells

* remove code smells

* fix format

* fix format

* Update kroxylicious-systemtests/src/main/java/io/kroxylicious/systemtests/executor/Exec.java

Co-authored-by: Keith Wall <[email protected]>
Signed-off-by: Francisco Vila <[email protected]>

* reduce code smells

* remove code smells

* fix imports

* Update kroxylicious-systemtests/src/test/java/io/kroxylicious/systemtests/MetricsST.java

Co-authored-by: Keith Wall <[email protected]>
Signed-off-by: Francisco Vila <[email protected]>

* Update kroxylicious-systemtests/src/test/java/io/kroxylicious/systemtests/MetricsST.java

Co-authored-by: Keith Wall <[email protected]>
Signed-off-by: Francisco Vila <[email protected]>

* Update kroxylicious-systemtests/src/test/java/io/kroxylicious/systemtests/MetricsST.java

Co-authored-by: Keith Wall <[email protected]>
Signed-off-by: Francisco Vila <[email protected]>

* Update kroxylicious-systemtests/src/test/java/io/kroxylicious/systemtests/MetricsST.java

Co-authored-by: Keith Wall <[email protected]>
Signed-off-by: Francisco Vila <[email protected]>

* remove memory config for scraper

* remove scraper image variable

---------

Signed-off-by: Francisco Vila <[email protected]>
Co-authored-by: Keith Wall <[email protected]>
  • Loading branch information
franvila and k-wall authored Mar 7, 2024
1 parent a2219bb commit 470fb42
Show file tree
Hide file tree
Showing 22 changed files with 779 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,24 @@ public interface Constants {
/**
* Polls and timeouts constants
*/
long POLL_INTERVAL_FOR_RESOURCE_READINESS_MILLIS = Duration.ofSeconds(5).toMillis();
Duration POLL_INTERVAL_FOR_RESOURCE_READINESS = Duration.ofSeconds(2);
/**
* Poll interval for resource deletion in milliseconds
* Poll interval for resource deletion
*/
long POLL_INTERVAL_FOR_RESOURCE_DELETION_MILLIS = Duration.ofSeconds(1).toMillis();
Duration POLL_INTERVAL_FOR_RESOURCE_DELETION = Duration.ofSeconds(1);

/**
* Global timeout in milliseconds
* Global timeout
*/
long GLOBAL_TIMEOUT_MILLIS = Duration.ofMinutes(5).toMillis();
Duration GLOBAL_TIMEOUT = Duration.ofMinutes(5);
/**
* Global Poll interval in milliseconds
* Global Poll interval
*/
long GLOBAL_POLL_INTERVAL_MILLIS = Duration.ofSeconds(1).toMillis();
Duration GLOBAL_POLL_INTERVAL = Duration.ofSeconds(1);
Duration RECONCILIATION_INTERVAL = Duration.ofSeconds(30);
Duration GLOBAL_POLL_INTERVAL_MEDIUM = Duration.ofSeconds(10);
Duration GLOBAL_STATUS_TIMEOUT = Duration.ofMinutes(3);
Duration GLOBAL_TIMEOUT_SHORT = Duration.ofMinutes(2);

/**
* Kubernetes related constants
Expand Down Expand Up @@ -156,4 +160,12 @@ public interface Constants {
String DONT_USE_KRAFT_MODE = "-UseKRaft";
String USE_KAFKA_NODE_POOLS = "+KafkaNodePools";
String DONT_USE_KAFKA_NODE_POOLS = "-KafkaNodePools";

/**
* Scraper pod labels
*/
String SCRAPER_LABEL_KEY = "user-test-app";
String SCRAPER_LABEL_VALUE = "scraper";
String SCRAPER_NAME = "Scraper";
String DEPLOYMENT_TYPE_LABEL_KEY = "deployment-type";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Kroxylicious Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/

package io.kroxylicious.systemtests.enums;

public enum ComponentType {
KROXYLICIOUS
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -58,7 +59,7 @@ public class Exec {
/**
* Instantiates a new Exec.
*/
public Exec() {
private Exec() {
}

/**
Expand Down Expand Up @@ -142,7 +143,7 @@ public static long execWithoutWait(String... command) {
* @return execution results
*/
public static ExecResult exec(List<String> command, File dir) {
return exec(null, command, 0, false, dir);
return exec(null, command, Duration.ZERO, false, dir);
}

/**
Expand All @@ -152,7 +153,7 @@ public static ExecResult exec(List<String> command, File dir) {
* @return the exec result
*/
public static ExecResult exec(List<String> command) {
return exec(null, command, 0, false);
return exec(null, command, Duration.ZERO, false);
}

/**
Expand All @@ -163,7 +164,7 @@ public static ExecResult exec(List<String> command) {
* @return execution results
*/
public static ExecResult exec(String input, List<String> command) {
return exec(input, command, 0, false);
return exec(input, command, Duration.ZERO, false);
}

/**
Expand All @@ -175,7 +176,7 @@ public static ExecResult exec(String input, List<String> command) {
* @param dir the dir
* @return execution results
*/
public static ExecResult exec(String input, List<String> command, int timeout, boolean logToOutput, File dir) {
public static ExecResult exec(String input, List<String> command, Duration timeout, boolean logToOutput, File dir) {
return exec(input, command, timeout, logToOutput, true, dir);
}

Expand All @@ -199,7 +200,7 @@ public static long execWithoutWait(List<String> command) {
* @param logToOutput the log to output
* @return the exec result
*/
public static ExecResult exec(String input, List<String> command, int timeout, boolean logToOutput) {
public static ExecResult exec(String input, List<String> command, Duration timeout, boolean logToOutput) {
return exec(input, command, timeout, logToOutput, true, null);
}

Expand All @@ -213,7 +214,7 @@ public static ExecResult exec(String input, List<String> command, int timeout, b
* @param dir the dir
* @return execution results
*/
public static ExecResult exec(String input, List<String> command, int timeout, boolean logToOutput, boolean throwErrors, File dir) {
public static ExecResult exec(String input, List<String> command, Duration timeout, boolean logToOutput, boolean throwErrors, File dir) {
int ret;
ExecResult execResult;
try {
Expand Down Expand Up @@ -293,14 +294,14 @@ private static void logExecutor(int ret, String input, List<String> command, Str
*
* @param input the input
* @param commands arguments for command
* @param timeoutMs timeout in ms for kill
* @param timeout timeout allowed for the process's execution. If the timeout is exceed the process will be killed.
* @param dir the dir
* @return returns ecode of execution
* @throws IOException the io exception
* @throws InterruptedException the interrupted exception
* @throws ExecutionException the execution exception
*/
public int execute(String input, List<String> commands, long timeoutMs, File dir) throws IOException, InterruptedException, ExecutionException {
public int execute(String input, List<String> commands, Duration timeout, File dir) throws IOException, InterruptedException, ExecutionException {
LOGGER.debug("Running command - {}", String.join(" ", commands.toArray(new String[0])));
ProcessBuilder builder = new ProcessBuilder();
builder.command(commands);
Expand All @@ -319,8 +320,8 @@ public int execute(String input, List<String> commands, long timeoutMs, File dir
Future<String> error = readStdError();

int retCode = 1;
if (timeoutMs > 0) {
if (process.waitFor(timeoutMs, TimeUnit.MILLISECONDS)) {
if (timeout.toMillis() > 0) {
if (process.waitFor(timeout.toMillis(), TimeUnit.MILLISECONDS)) {
retCode = process.exitValue();
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package io.kroxylicious.systemtests.k8s;

import java.nio.file.Path;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -93,7 +94,7 @@ public HelmClient install(String chartName, String releaseName, Optional<String>
overrideFile.map(Path::toString).ifPresent(v -> cmd.addAll(List.of("--values", v)));
overrideMap.filter(not(Map::isEmpty)).ifPresent(m -> cmd.addAll(List.of("--set", mapToValuesParameterArgument(m))));

Exec.exec(null, wait(cmd), 0, true);
Exec.exec(null, wait(cmd), Duration.ZERO, true);
return this;
}

Expand All @@ -108,7 +109,7 @@ public HelmClient addRepository(String repoName, String repoUrl) {
LOGGER.info("Adding repo {}", repoName);
Exec.exec(null, command("repo", "add",
repoName,
repoUrl), 0, true);
repoUrl), Duration.ZERO, true);
return this;
}

Expand All @@ -130,7 +131,7 @@ public HelmClient delete(String releaseName) {
*/
public HelmClient delete(String namespace, String releaseName) {
LOGGER.info("Deleting helm-chart:{} in namespace:{}", releaseName, namespace);
Exec.exec(null, wait(command("uninstall", releaseName, "--namespace", namespace)), 0, true);
Exec.exec(null, wait(command("uninstall", releaseName, "--namespace", namespace)), Duration.ZERO, true);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.stream.Collectors;

import io.fabric8.kubernetes.api.model.DeletionPropagation;
import io.fabric8.kubernetes.api.model.LabelSelector;
import io.fabric8.kubernetes.api.model.Namespace;
import io.fabric8.kubernetes.api.model.NamespaceBuilder;
import io.fabric8.kubernetes.api.model.Pod;
Expand Down Expand Up @@ -135,6 +136,10 @@ public List<Pod> listPods(String namespaceName) {
return client.pods().inNamespace(namespaceName).list().getItems();
}

public List<Pod> listPods(String namespaceName, LabelSelector selector) {
return client.pods().inNamespace(namespaceName).withLabelSelector(selector).list().getItems();
}

/**
* Returns list of pods by prefix in pod name
* @param namespaceName Namespace name
Expand Down Expand Up @@ -191,6 +196,16 @@ public Deployment getDeployment(String namespaceName, String deploymentName) {
return client.apps().deployments().inNamespace(namespaceName).withName(deploymentName).get();
}

/**
* Gets deployment selectors
* @param namespaceName the namespace name
* @param deploymentName the deployment name
* @return the deployment selectors
*/
public LabelSelector getPodSelectorFromDeployment(String namespaceName, String deploymentName) {
return client.apps().deployments().inNamespace(namespaceName).withName(deploymentName).get().getSpec().getSelector();
}

/**
* Gets if the deployment is ready
* @param namespaceName the namespace name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ public String getNamespace() {
return namespace;
}

/**
* Sets the namespace value for Kubernetes clients
* @param futureNamespace Namespace which should be used in Kubernetes clients
* @return Previous namespace which was used in Kubernetes clients
*/
public String setNamespace(String futureNamespace) {
String previousNamespace = namespace;
LOGGER.info("Previous namespace used: {}", previousNamespace);
LOGGER.info("Client use Namespace: {}", futureNamespace);
namespace = futureNamespace;
return previousNamespace;
}

/**
* Provides appropriate CMD client for running cluster
* @return CMD client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.File;
import java.nio.file.NoSuchFileException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
Expand Down Expand Up @@ -95,7 +96,7 @@ private Map<File, ExecResult> execRecursive(String subcommand, File[] files, Com
for (File f : files) {
if (f.isFile()) {
if (f.getName().endsWith(".yaml")) {
execResults.put(f, Exec.exec(null, namespacedCommand(subcommand, "-f", f.getAbsolutePath()), 0, false, false, null));
execResults.put(f, Exec.exec(null, namespacedCommand(subcommand, "-f", f.getAbsolutePath()), Duration.ZERO, false, false, null));
}
}
else if (f.isDirectory()) {
Expand All @@ -121,6 +122,6 @@ public String toString() {
public ExecResult execInPod(String pod, boolean throwErrors, String... command) {
List<String> cmd = namespacedCommand("exec", pod, "--");
cmd.addAll(asList(command));
return Exec.exec(null, cmd, 0, throwErrors);
return Exec.exec(null, cmd, Duration.ZERO, true, throwErrors, null);
}
}
Loading

0 comments on commit 470fb42

Please sign in to comment.