Skip to content

Commit ef01dc9

Browse files
committed
Address comments on system tests
Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
1 parent d481c9c commit ef01dc9

2 files changed

Lines changed: 70 additions & 52 deletions

File tree

systemtest/src/main/java/io/strimzi/systemtest/templates/crd/KafkaTemplates.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,6 @@ public static KafkaBuilder kafka(String namespaceName, String kafkaClusterName,
183183

184184
return kb;
185185
}
186-
187-
public static KafkaBuilder kafkaWithoutEntityOperator(String namespaceName, String kafkaClusterName, int kafkaReplicas) {
188-
KafkaBuilder kb = kafka(namespaceName, kafkaClusterName, kafkaReplicas)
189-
.editSpec()
190-
.editEntityOperator()
191-
.withTopicOperator(null)
192-
.withUserOperator(null)
193-
.endEntityOperator()
194-
.endSpec();
195-
196-
return kb;
197-
}
198186

199187
// -------------------------------------------------------------------------------------------
200188
// Application of defaults to the builders

systemtest/src/test/java/io/strimzi/systemtest/metrics/StrimziMetricsReporterST.java

Lines changed: 70 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.skodjob.annotations.SuiteDoc;
1111
import io.skodjob.annotations.TestDoc;
1212
import io.skodjob.testframe.resources.KubeResourceManager;
13+
import io.strimzi.operator.common.Annotations;
1314
import io.strimzi.systemtest.AbstractST;
1415
import io.strimzi.systemtest.Environment;
1516
import io.strimzi.systemtest.TestConstants;
@@ -40,9 +41,7 @@
4041
import static io.strimzi.systemtest.TestTags.MIRROR_MAKER2;
4142
import static io.strimzi.systemtest.TestTags.REGRESSION;
4243
import static io.strimzi.systemtest.TestTags.SANITY;
43-
import static io.strimzi.systemtest.utils.specific.MetricsUtils.assertMetricCountHigherThan;
4444
import static io.strimzi.systemtest.utils.specific.MetricsUtils.assertMetricValue;
45-
import static io.strimzi.systemtest.utils.specific.MetricsUtils.assertMetricValueCount;
4645
import static io.strimzi.systemtest.utils.specific.MetricsUtils.assertMetricValueHigherThanOrEqualTo;
4746
import static org.junit.jupiter.api.Assumptions.assumeFalse;
4847

@@ -69,6 +68,12 @@
6968
public class StrimziMetricsReporterST extends AbstractST {
7069
private static final Logger LOGGER = LogManager.getLogger(StrimziMetricsReporterST.class);
7170

71+
private static final int BROKER_REPLICAS = 3;
72+
private static final int TARGET_BROKER_REPLICAS = 3;
73+
private static final String CONNECT_CLUSTER_NAME = "my-connect";
74+
private static final String MM2_CLUSTER_NAME = "my-mm2";
75+
76+
private TestStorage testStorage;
7277
private BaseMetricsCollector kafkaCollector;
7378

7479
@ParallelTest
@@ -86,8 +91,8 @@ public class StrimziMetricsReporterST extends AbstractST {
8691
void testKafkaMetrics() {
8792
kafkaCollector.collectMetricsFromPods(TestConstants.METRICS_COLLECT_TIMEOUT);
8893

89-
assertMetricValueCount(kafkaCollector, "kafka_server_replicamanager_leadercount", 3.0);
90-
assertMetricCountHigherThan(kafkaCollector, "kafka_server_replicamanager_partitioncount", 2);
94+
assertMetricValueHigherThanOrEqualTo(kafkaCollector, "kafka_server_replicamanager_leadercount", 1.0);
95+
assertMetricValueHigherThanOrEqualTo(kafkaCollector, "kafka_server_replicamanager_partitioncount", 1.0);
9196
assertMetricValue(kafkaCollector, "kafka_server_replicamanager_underreplicatedpartitions", 0.0);
9297
}
9398

@@ -110,8 +115,27 @@ void testKafkaMetrics() {
110115
}
111116
)
112117
void testKafkaConnectAndConnectorMetrics() {
118+
KubeResourceManager.get().createResourceWithWait(
119+
KafkaConnectTemplates.kafkaConnectWithFilePlugin(testStorage.getNamespaceName(), CONNECT_CLUSTER_NAME,
120+
testStorage.getClusterName(), 1)
121+
.editMetadata()
122+
.addToAnnotations(Annotations.STRIMZI_IO_USE_CONNECTOR_RESOURCES, "true")
123+
.endMetadata()
124+
.editOrNewSpec()
125+
.withNewStrimziMetricsReporterConfig()
126+
.withNewValues()
127+
.withAllowList("kafka_connect.*")
128+
.endValues()
129+
.endStrimziMetricsReporterConfig()
130+
.endSpec().build()
131+
);
132+
133+
KubeResourceManager.get().createResourceWithWait(
134+
KafkaConnectorTemplates.kafkaConnector(testStorage.getNamespaceName(), CONNECT_CLUSTER_NAME).build()
135+
);
136+
113137
BaseMetricsCollector kafkaConnectCollector = kafkaCollector.toBuilder()
114-
.withComponent(KafkaConnectMetricsComponent.create("my-connect"))
138+
.withComponent(KafkaConnectMetricsComponent.create(CONNECT_CLUSTER_NAME))
115139
.build();
116140

117141
kafkaConnectCollector.collectMetricsFromPods(TestConstants.METRICS_COLLECT_TIMEOUT);
@@ -139,8 +163,35 @@ void testKafkaConnectAndConnectorMetrics() {
139163
}
140164
)
141165
void testMirrorMaker2Metrics() {
166+
KubeResourceManager.get().createResourceWithWait(
167+
KafkaNodePoolTemplates.mixedPool(testStorage.getNamespaceName(), testStorage.getTargetBrokerPoolName(),
168+
testStorage.getTargetClusterName(), TARGET_BROKER_REPLICAS).build()
169+
);
170+
171+
KubeResourceManager.get().createResourceWithWait(
172+
KafkaTemplates.kafka(testStorage.getNamespaceName(), testStorage.getTargetClusterName(), TARGET_BROKER_REPLICAS)
173+
.editSpec()
174+
.editEntityOperator()
175+
.withTopicOperator(null)
176+
.withUserOperator(null)
177+
.endEntityOperator()
178+
.endSpec().build()
179+
);
180+
181+
KubeResourceManager.get().createResourceWithWait(
182+
KafkaMirrorMaker2Templates.kafkaMirrorMaker2(testStorage.getNamespaceName(), MM2_CLUSTER_NAME,
183+
testStorage.getClusterName(), testStorage.getTargetClusterName(), 1, false)
184+
.editOrNewSpec()
185+
.withNewStrimziMetricsReporterConfig()
186+
.withNewValues()
187+
.withAllowList("kafka_connect.*")
188+
.endValues()
189+
.endStrimziMetricsReporterConfig()
190+
.endSpec().build()
191+
);
192+
142193
BaseMetricsCollector kmm2Collector = kafkaCollector.toBuilder()
143-
.withComponent(KafkaMirrorMaker2MetricsComponent.create("my-mm2"))
194+
.withComponent(KafkaMirrorMaker2MetricsComponent.create(MM2_CLUSTER_NAME))
144195
.build();
145196

146197
kmm2Collector.collectMetricsFromPods(TestConstants.METRICS_COLLECT_TIMEOUT);
@@ -151,7 +202,7 @@ void testMirrorMaker2Metrics() {
151202

152203
@BeforeAll
153204
void setupEnvironment() {
154-
final TestStorage testStorage = new TestStorage(KubeResourceManager.get().getTestContext());
205+
testStorage = new TestStorage(KubeResourceManager.get().getTestContext());
155206

156207
// metrics tests are not designed to run with namespace RBAC scope
157208
assumeFalse(Environment.isNamespaceRbacScope());
@@ -164,13 +215,14 @@ void setupEnvironment() {
164215
cluster.setNamespace(testStorage.getNamespaceName());
165216

166217
KubeResourceManager.get().createResourceWithWait(
167-
KafkaNodePoolTemplates.brokerPool(testStorage.getNamespaceName(), testStorage.getBrokerPoolName(), testStorage.getClusterName(), 3).build(),
168-
KafkaNodePoolTemplates.controllerPool(testStorage.getNamespaceName(), testStorage.getControllerPoolName(), testStorage.getClusterName(), 3).build(),
169-
KafkaNodePoolTemplates.mixedPool(testStorage.getNamespaceName(), testStorage.getBrokerPoolName() + "-tgt", testStorage.getClusterName() + "-tgt", 1).build()
218+
KafkaNodePoolTemplates.brokerPool(testStorage.getNamespaceName(), testStorage.getBrokerPoolName(),
219+
testStorage.getClusterName(), BROKER_REPLICAS).build(),
220+
KafkaNodePoolTemplates.controllerPool(testStorage.getNamespaceName(), testStorage.getControllerPoolName(),
221+
testStorage.getClusterName(), 1).build()
170222
);
171223

172224
KubeResourceManager.get().createResourceWithWait(
173-
KafkaTemplates.kafka(testStorage.getNamespaceName(), testStorage.getClusterName(), 3)
225+
KafkaTemplates.kafka(testStorage.getNamespaceName(), testStorage.getClusterName(), BROKER_REPLICAS)
174226
.editSpec()
175227
.editKafka()
176228
.withNewStrimziMetricsReporterConfig()
@@ -179,35 +231,13 @@ void setupEnvironment() {
179231
.endValues()
180232
.endStrimziMetricsReporterConfig()
181233
.endKafka()
182-
.endSpec().build(),
183-
KafkaTemplates.kafkaWithoutEntityOperator(testStorage.getNamespaceName(), testStorage.getClusterName() + "-tgt", 1).build()
184-
);
185-
186-
KubeResourceManager.get().createResourceWithWait(
187-
KafkaConnectTemplates.kafkaConnectWithFilePlugin(testStorage.getNamespaceName(), "my-connect",
188-
testStorage.getClusterName(), 1)
189-
.editOrNewSpec()
190-
.withNewStrimziMetricsReporterConfig()
191-
.withNewValues()
192-
.withAllowList("kafka_connect.*")
193-
.endValues()
194-
.endStrimziMetricsReporterConfig()
195-
.endSpec().build(),
196-
KafkaMirrorMaker2Templates.kafkaMirrorMaker2(testStorage.getNamespaceName(), "my-mm2",
197-
testStorage.getClusterName(), testStorage.getClusterName() + "-tgt", 1, false)
198-
.editOrNewSpec()
199-
.withNewStrimziMetricsReporterConfig()
200-
.withNewValues()
201-
.withAllowList("kafka_connect.*")
202-
.endValues()
203-
.endStrimziMetricsReporterConfig()
204234
.endSpec().build()
205235
);
206236

207237
KubeResourceManager.get().createResourceWithoutWait(
208238
ScraperTemplates.scraperPod(testStorage.getNamespaceName(), testStorage.getScraperName()).build(),
209-
KafkaTopicTemplates.topic(testStorage.getNamespaceName(), testStorage.getTopicName(), testStorage.getClusterName(), 5, 2).build(),
210-
KafkaConnectorTemplates.kafkaConnector(testStorage.getNamespaceName(), "my-connect").build()
239+
KafkaTopicTemplates.topic(testStorage.getNamespaceName(), testStorage.getTopicName(),
240+
testStorage.getClusterName(), 5, BROKER_REPLICAS).build()
211241
);
212242

213243
// wait some time for metrics to be stable, at least reconciliation interval + 10s
@@ -216,10 +246,10 @@ void setupEnvironment() {
216246
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(TestConstants.SAFETY_RECONCILIATION_INTERVAL));
217247

218248
kafkaCollector = new BaseMetricsCollector.Builder()
219-
.withScraperPodName(KubeResourceManager.get().kubeClient()
220-
.listPodsByPrefixInName(testStorage.getNamespaceName(), testStorage.getScraperName()).get(0).getMetadata().getName())
221-
.withNamespaceName(testStorage.getNamespaceName())
222-
.withComponent(KafkaMetricsComponent.create(testStorage.getClusterName()))
223-
.build();
249+
.withScraperPodName(KubeResourceManager.get().kubeClient()
250+
.listPodsByPrefixInName(testStorage.getNamespaceName(), testStorage.getScraperName()).get(0).getMetadata().getName())
251+
.withNamespaceName(testStorage.getNamespaceName())
252+
.withComponent(KafkaMetricsComponent.create(testStorage.getClusterName()))
253+
.build();
224254
}
225255
}

0 commit comments

Comments
 (0)