Skip to content

Commit

Permalink
bump test-frame to 0.4.0 and add handling of the metric types
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Kral <lukywill16@gmail.com>

better parsing of metrics, fixups

Signed-off-by: Lukas Kral <lukywill16@gmail.com>

update test and skodjob version to newly released

Signed-off-by: Lukas Kral <lukywill16@gmail.com>

bump to 0.6.1 and fix tests

Signed-off-by: Lukas Kral <lukywill16@gmail.com>
  • Loading branch information
im-konge committed Sep 3, 2024
1 parent e6a9450 commit ff7b80b
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 77 deletions.
10 changes: 7 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
<kroxylicious-testing.version>0.9.0</kroxylicious-testing.version>
<kindcontainer.version>1.4.6</kindcontainer.version>
<junit4.version>4.13.2</junit4.version>
<skodjob.version>0.1.1</skodjob.version>
<skodjob.test-frame.version>0.6.1</skodjob.test-frame.version>

<!-- properties to skip surefire tests during failsafe execution -->
<skipTests>false</skipTests>
Expand Down Expand Up @@ -732,9 +732,13 @@
<dependency>
<groupId>io.skodjob</groupId>
<artifactId>test-frame-metrics-collector</artifactId>
<version>${skodjob.version}</version>
<version>${skodjob.test-frame.version}</version>
</dependency>
<dependency>
<groupId>io.skodjob</groupId>
<artifactId>test-frame-common</artifactId>
<version>${skodjob.test-frame.version}</version>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>io.strimzi</groupId>
Expand Down
5 changes: 5 additions & 0 deletions systemtest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@
<groupId>io.skodjob</groupId>
<artifactId>test-frame-metrics-collector</artifactId>
</dependency>
<dependency>
<groupId>io.skodjob</groupId>
<artifactId>test-frame-common</artifactId>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -256,6 +260,7 @@
<ignoredUnusedDeclaredDependency>org.apache.logging.log4j:log4j-core</ignoredUnusedDeclaredDependency>
<!-- Needed for logging in tests using the Kubernetes Client (uses SLF4J) -->
<ignoredUnusedDeclaredDependency>org.apache.logging.log4j:log4j-slf4j-impl</ignoredUnusedDeclaredDependency>
<ignoredUnusedDeclaredDependency>io.skodjob:test-frame-common</ignoredUnusedDeclaredDependency>
</ignoredUnusedDeclaredDependencies>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@
package io.strimzi.systemtest.performance.gather.collectors;

import io.skodjob.testframe.MetricsCollector;
import io.skodjob.testframe.MetricsComponent;
import io.skodjob.testframe.exceptions.MetricsCollectionException;
import io.skodjob.testframe.metrics.Metric;
import io.strimzi.api.kafka.model.topic.KafkaTopic;
import io.strimzi.systemtest.TestConstants;
import io.strimzi.systemtest.performance.PerformanceConstants;
import io.strimzi.systemtest.utils.specific.MetricsUtils;
import io.strimzi.test.TestUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
Expand All @@ -22,15 +30,15 @@
* Metrics gathered include system CPU count, JVM memory allocation, thread details, and other
* system performance indicators.
*/
public abstract class BaseMetricsCollector extends MetricsCollector {
public class BaseMetricsCollector extends MetricsCollector {

private static final Logger LOGGER = LogManager.getLogger(BaseMetricsCollector.class);

/**
* Constructs a new {@code BaseMetricsCollector} instance configured via the provided builder.
* @param builder The builder used to configure this collector.
*/
protected BaseMetricsCollector(Builder builder) {
public BaseMetricsCollector(MetricsCollector.Builder builder) {
super(builder);
}

Expand Down Expand Up @@ -82,7 +90,7 @@ public List<Double> getSystemCpuUsage() {
* Retrieves the maximum duration of garbage collection pauses in the JVM.
* @return A map with keys representing unique label combinations and their corresponding maximum GC pause times.
*/
public Map<String, Double> getJvmGcPauseSecondsMax() {
public Map<String, Double> getJvmGcPauseSecondsMax() {
return collectMetricWithLabels(PerformanceConstants.JVM_GC_PAUSE_SECONDS_MAX);
}

Expand Down Expand Up @@ -142,4 +150,99 @@ protected List<Double> collectMetricSimpleValues(String metricName) {
return collectSpecificMetric(pattern);
}

protected Map<String, Double> collectMetricWithLabels(String labels) {
Map<String, Double> values = new HashMap<>();

for (Map.Entry<String, List<Metric>> entry : this.collectedData.entrySet()) {
List<Metric> metrics = collectMetricWithLabels(entry.getKey(), labels);
metrics.forEach(metric -> values.put(metric.getName(), MetricsUtils.getDoubleMetricValueBasedOnType(metric)));
}

return values;
}

public List<Double> collectSpecificMetric(Pattern pattern) {
List<Double> metrics = new ArrayList<>();

for (Map.Entry<String, List<Metric>> entry : this.collectedData.entrySet()) {
Metric metric = findMetricWithPatternInMetrics(entry.getValue(), pattern);

if (metric != null) {
Double value = MetricsUtils.getDoubleMetricValueBasedOnType(metric);
if (value != null) {
metrics.add(value);
}
}
}

return metrics;
}

protected Metric findMetricWithPatternInMetrics(List<Metric> metrics, Pattern pattern) {
return metrics.stream().filter(metric -> pattern.matcher(metric.getStringMetric()).find()).findFirst().orElse(null);
}

public final synchronized List<Double> waitForSpecificMetricAndCollect(Pattern pattern) {
List<Double> values = collectSpecificMetric(pattern);

if (values.isEmpty()) {
TestUtils.waitFor(String.format("metrics contain pattern: %s", pattern.toString()),
TestConstants.GLOBAL_POLL_INTERVAL, TestConstants.GLOBAL_TIMEOUT, () -> {
try {
this.collectMetricsFromPods();
} catch (MetricsCollectionException e) {
throw new RuntimeException(e);
}
LOGGER.debug("Collected data: {}", this.collectedData);
List<Double> vals = this.collectSpecificMetric(pattern);

if (!vals.isEmpty()) {
values.addAll(vals);
return true;
}

return false;
});
}

return values;
}

protected BaseMetricsCollector.Builder newBuilder() {
return new BaseMetricsCollector.Builder();
}

protected BaseMetricsCollector.Builder updateBuilder(BaseMetricsCollector.Builder builder) {
return (BaseMetricsCollector.Builder) super.updateBuilder(builder);
}

public BaseMetricsCollector.Builder toBuilder() {
return this.updateBuilder(this.newBuilder());
}

public static class Builder extends MetricsCollector.Builder {
@Override
public BaseMetricsCollector build() {
return new BaseMetricsCollector(this);
}

// Override the builder methods to return the type of this Builder, allowing method chaining
@Override
public BaseMetricsCollector.Builder withNamespaceName(String namespaceName) {
super.withNamespaceName(namespaceName);
return this;
}

@Override
public BaseMetricsCollector.Builder withScraperPodName(String scraperPodName) {
super.withScraperPodName(scraperPodName);
return this;
}

@Override
public BaseMetricsCollector.Builder withComponent(MetricsComponent component) {
super.withComponent(component);
return this;
}
}
}
Loading

0 comments on commit ff7b80b

Please sign in to comment.