Skip to content

Commit

Permalink
MGDSTRM-10557: Expose strimzi oauth metrics prometheus in order to as…
Browse files Browse the repository at this point in the history
…sist investigating a slow authentication issue (#910)

* MGDSTRM-10557: Expose strimzi oauth metrics to assist investigating a sporadic slow authentications

Signed-off-by: kwall <kwall@apache.org>

* allow kafka container environment to be overridden too

---------

Signed-off-by: kwall <kwall@apache.org>
  • Loading branch information
k-wall authored Apr 19, 2023
1 parent e366568 commit d2122a6
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
17 changes: 17 additions & 0 deletions operator/src/main/java/org/bf2/operator/operands/KafkaCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import io.fabric8.openshift.api.model.TLSConfigBuilder;
import io.javaoperatorsdk.operator.api.reconciler.Context;
import io.quarkus.arc.DefaultBean;
import io.strimzi.api.kafka.model.ContainerEnvVar;
import io.strimzi.api.kafka.model.ContainerEnvVarBuilder;
import io.strimzi.api.kafka.model.CruiseControlSpec;
import io.strimzi.api.kafka.model.CruiseControlSpecBuilder;
import io.strimzi.api.kafka.model.ExternalConfigurationReferenceBuilder;
Expand Down Expand Up @@ -98,6 +100,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import static io.fabric8.kubernetes.api.model.Quantity.getAmountInBytes;

Expand Down Expand Up @@ -544,6 +547,11 @@ private KafkaClusterTemplate buildKafkaTemplate(ManagedKafka managedKafka, int r
KafkaClusterTemplateBuilder templateBuilder = new KafkaClusterTemplateBuilder()
.withPod(podTemplateBuilder.build());

var kafkaContainerEnv = buildKafkaContainerEnvVars(managedKafka);
if (!kafkaContainerEnv.isEmpty()) {
templateBuilder.withNewKafkaContainer().withEnv(kafkaContainerEnv).endKafkaContainer();
}

if (replicas > 1 && drainCleanerManager.isDrainCleanerWebhookFound()) {
templateBuilder.withPodDisruptionBudget(
new PodDisruptionBudgetTemplateBuilder()
Expand All @@ -554,6 +562,15 @@ private KafkaClusterTemplate buildKafkaTemplate(ManagedKafka managedKafka, int r
return templateBuilder.build();
}

private List<ContainerEnvVar> buildKafkaContainerEnvVars(ManagedKafka managedKafka) {
var kafkaOverride = this.overrideManager.getKafkaOverride(managedKafka.getSpec().getVersions().getStrimzi());
if (kafkaOverride == null) {
return List.of();
}
var envVars = kafkaOverride.applyEnvironmentTo(List.of());
return envVars.stream().filter(env -> Objects.isNull(env.getValueFrom())).map(env -> new ContainerEnvVarBuilder().withName(env.getName()).withValue(env.getValue()).build()).collect(Collectors.toList());
}

public static Toleration buildKafkaBrokerToleration() {
return new TolerationBuilder()
.withKey("org.bf2.operator/kafka-broker")
Expand Down
61 changes: 61 additions & 0 deletions operator/src/main/resources/kafka-metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,64 @@ data:
pattern: >-
kafka.server<type=KafkaServer, name=BrokerState><>Value: (\d+)
type: GAUGE
# OAuth Metrics - from https://raw.githubusercontent.com/strimzi/strimzi-kafka-oauth/main/testsuite/docker/kafka/config/metrics-config.yml
- pattern: "strimzi.oauth<type=(.+), context=(.+), kind=(.+), host=\"(.+)\", path=\"(.+)\", (.+)=(.+), (.+)=(.+), (.+)=(.+)><>(count|totalTimeMs):"
name: "strimzi_oauth_$1_$12"
type: COUNTER
labels:
context: "$2"
kind: "$3"
host: "$4"
path: "$5"
"$6": "$7"
"$8": "$9"
"$10": "$11"
- pattern: "strimzi.oauth<type=(.+), context=(.+), kind=(.+), host=\"(.+)\", path=\"(.+)\", (.+)=(.+), (.+)=(.+)><>(count|totalTimeMs):"
name: "strimzi_oauth_$1_$10"
type: COUNTER
labels:
context: "$2"
kind: "$3"
host: "$4"
path: "$5"
"$6": "$7"
"$8": "$9"
- pattern: "strimzi.oauth<type=(.+), context=(.+), kind=(.+), host=\"(.+)\", path=\"(.+)\", (.+)=(.+)><>(count|totalTimeMs):"
name: "strimzi_oauth_$1_$8"
type: COUNTER
labels:
context: "$2"
kind: "$3"
host: "$4"
path: "$5"
"$6": "$7"
- pattern: "strimzi.oauth<type=(.+), context=(.+), kind=(.+), host=\"(.+)\", path=\"(.+)\", (.+)=(.+), (.+)=(.+), (.+)=(.+)><>(.+):"
name: "strimzi_oauth_$1_$12"
type: GAUGE
labels:
context: "$2"
kind: "$3"
host: "$4"
path: "$5"
"$6": "$7"
"$8": "$9"
"$10": "$11"
- pattern: "strimzi.oauth<type=(.+), context=(.+), kind=(.+), host=\"(.+)\", path=\"(.+)\", (.+)=(.+), (.+)=(.+)><>(.+):"
name: "strimzi_oauth_$1_$10"
type: GAUGE
labels:
context: "$2"
kind: "$3"
host: "$4"
path: "$5"
"$6": "$7"
"$8": "$9"
- pattern: "strimzi.oauth<type=(.+), context=(.+), kind=(.+), host=\"(.+)\", path=\"(.+)\", (.+)=(.+)><>(.+):"
name: "strimzi_oauth_$1_$8"
type: GAUGE
labels:
context: "$2"
kind: "$3"
host: "$4"
path: "$5"
"$6": "$7"
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.fabric8.kubernetes.api.model.Affinity;
import io.fabric8.kubernetes.api.model.EnvVar;
import io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaim;
import io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder;
Expand Down Expand Up @@ -445,6 +446,7 @@ void testManagedKafkaToKafkaWithCustomConfiguration() throws IOException {

OperandOverrideManager.Kafka kafkaOverride = new OperandOverrideManager.Kafka();
kafkaOverride.setBrokerConfig(brokerConfig);
kafkaOverride.setEnv(List.of(new EnvVar("FOO", "BAR", null)));
kafkaOverride.setListeners(Map.of("external", externalListenerOverride, "oauth", oauthListenerOverride));

when(overrideManager.getKafkaOverride(strimzi)).thenReturn(kafkaOverride);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ spec:
name: "test-mk-kafka-logging"
optional: false
template:
kafkaContainer:
env:
- name: FOO
value: BAR
pod:
tolerations:
- effect: "NoExecute"
Expand Down

0 comments on commit d2122a6

Please sign in to comment.