Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MGDSTRM-10557: Expose strimzi oauth metrics prometheus in order to assist investigating a slow authentication issue #910

Merged
merged 2 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
Copy link
Contributor Author

@k-wall k-wall Apr 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried approaches introducing an env var type parameter to OperandOverride<E>) etc but the resulting code applyEnvironmentTo in less obvious that this list conversion in the method.

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"
Comment on lines +309 to +338
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if these three entries are redundant? The 3 patterns below look like more generalised forms that would also cover these cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, they won't be redundant. They are matching different forms. The number of groups is different in each case.

Copy link
Member

@grdryn grdryn Apr 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had counted the number of groups in each case, and they appeared to be the same is what I meant. 🙂 It seems like the actual difference is that the above 3 entries are counters, while the below 3 are gauges. Here's a diff tool view with the above on the left, and the below on the right. Lines with differences are those in blue, with the actual differences on those lines highlighted in a slightly lighter blue:

image

- 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