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

ISSUE-9231 Makes Kafka Exporter offset.show-all configurable #9494

Merged
merged 9 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 0.40.0

* Fix NullPointerException from missing listenerConfig when using custom auth
* Added support for Kafka Exporter `offset.show-all` parameter

### Changes, deprecations and removals

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"image", "groupRegex", "topicRegex",
"groupExcludeRegex", "topicExcludeRegex",
"resources", "logging",
"enableSaramaLogging", "template"})
"enableSaramaLogging", "showAllOffsets", "template"})
@EqualsAndHashCode
public class KafkaExporterSpec implements HasLivenessProbe, HasReadinessProbe, UnknownPropertyPreserving, Serializable {
private static final long serialVersionUID = 1L;
Expand All @@ -45,6 +45,7 @@ public class KafkaExporterSpec implements HasLivenessProbe, HasReadinessProbe, U
private Probe readinessProbe;
private String logging = "info";
private boolean enableSaramaLogging;
private boolean showAllOffsets = true;
private KafkaExporterTemplate template;
private Map<String, Object> additionalProperties = new HashMap<>(0);

Expand Down Expand Up @@ -112,6 +113,16 @@ public void setEnableSaramaLogging(boolean enableSaramaLogging) {
this.enableSaramaLogging = enableSaramaLogging;
}

@Description("Enable/disable offset show all option.")
ilkerkocatepe marked this conversation as resolved.
Show resolved Hide resolved
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public boolean getShowAllOffsets() {
return showAllOffsets;
}

public void setShowAllOffsets(boolean showAllOffsets) {
this.showAllOffsets = showAllOffsets;
}

@Description("Only log messages with the given severity or above. " +
"Valid levels: [`info`, `debug`, `trace`]. " +
"Default log level is `info`.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class KafkaExporter extends AbstractModel {
protected static final String ENV_VAR_KAFKA_EXPORTER_TOPIC_EXCLUDE_REGEX = "KAFKA_EXPORTER_TOPIC_EXCLUDE_REGEX";
protected static final String ENV_VAR_KAFKA_EXPORTER_KAFKA_SERVER = "KAFKA_EXPORTER_KAFKA_SERVER";
protected static final String ENV_VAR_KAFKA_EXPORTER_ENABLE_SARAMA = "KAFKA_EXPORTER_ENABLE_SARAMA";
protected static final String ENV_VAR_KAFKA_EXPORTER_OFFSET_SHOW_ALL = "KAFKA_EXPORTER_OFFSET_SHOW_ALL";

protected static final String CO_ENV_VAR_CUSTOM_KAFKA_EXPORTER_POD_LABELS = "STRIMZI_CUSTOM_KAFKA_EXPORTER_LABELS";

Expand All @@ -72,6 +73,7 @@ public class KafkaExporter extends AbstractModel {
protected String groupExcludeRegex;
protected String topicExcludeRegex;
protected boolean saramaLoggingEnabled;
protected boolean showAllOffsets;
/* test */ String exporterLogging;
protected String version;

Expand All @@ -96,6 +98,7 @@ protected KafkaExporter(Reconciliation reconciliation, HasMetadata resource, Sha
super(reconciliation, resource, KafkaExporterResources.deploymentName(resource.getMetadata().getName()), COMPONENT_TYPE, sharedEnvironmentProvider);

this.saramaLoggingEnabled = false;
this.showAllOffsets = true;
}

/**
Expand Down Expand Up @@ -132,6 +135,7 @@ public static KafkaExporter fromCrd(Reconciliation reconciliation, Kafka kafkaAs

result.exporterLogging = spec.getLogging();
result.saramaLoggingEnabled = spec.getEnableSaramaLogging();
result.showAllOffsets = spec.getShowAllOffsets();

if (spec.getTemplate() != null) {
KafkaExporterTemplate template = spec.getTemplate();
Expand Down Expand Up @@ -224,6 +228,7 @@ protected List<EnvVar> getEnvVars() {
}
varList.add(ContainerUtils.createEnvVar(ENV_VAR_KAFKA_EXPORTER_KAFKA_SERVER, KafkaResources.bootstrapServiceName(cluster) + ":" + KafkaCluster.REPLICATION_PORT));
varList.add(ContainerUtils.createEnvVar(ENV_VAR_KAFKA_EXPORTER_ENABLE_SARAMA, String.valueOf(saramaLoggingEnabled)));
varList.add(ContainerUtils.createEnvVar(ENV_VAR_KAFKA_EXPORTER_OFFSET_SHOW_ALL, String.valueOf(showAllOffsets)));

// Add shared environment variables used for all containers
varList.addAll(sharedEnvironmentProvider.variables());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public class KafkaExporterTest {
private final String topicRegex = "my-topic-.*";
private final String groupExcludeRegex = "my-group-exclude-.*";
private final String topicExcludeRegex = "my-topic-exclude-.*";
private final boolean showAllOffsets = false;

private final KafkaExporterSpec exporterOperator = new KafkaExporterSpecBuilder()
.withLogging(exporterOperatorLogging)
Expand All @@ -102,6 +103,7 @@ public class KafkaExporterTest {
.withTopicExcludeRegex(topicExcludeRegex)
.withImage(keImage)
.withEnableSaramaLogging(true)
.withShowAllOffsets(showAllOffsets)
.withNewTemplate()
.withNewPod()
.withTmpDirSizeLimit("100Mi")
Expand Down Expand Up @@ -135,6 +137,7 @@ private List<EnvVar> getExpectedEnvVars() {
expected.add(new EnvVarBuilder().withName(KafkaExporter.ENV_VAR_KAFKA_EXPORTER_TOPIC_EXCLUDE_REGEX).withValue(topicExcludeRegex).build());
expected.add(new EnvVarBuilder().withName(KafkaExporter.ENV_VAR_KAFKA_EXPORTER_KAFKA_SERVER).withValue("foo-kafka-bootstrap:" + KafkaCluster.REPLICATION_PORT).build());
expected.add(new EnvVarBuilder().withName(KafkaExporter.ENV_VAR_KAFKA_EXPORTER_ENABLE_SARAMA).withValue("true").build());
expected.add(new EnvVarBuilder().withName(KafkaExporter.ENV_VAR_KAFKA_EXPORTER_OFFSET_SHOW_ALL).withValue(String.valueOf(showAllOffsets)).build());
return expected;
}

Expand All @@ -152,6 +155,7 @@ public void testFromConfigMapDefaultConfig() {
assertNull(ke.groupExcludeRegex);
assertNull(ke.topicExcludeRegex);
assertThat(ke.saramaLoggingEnabled, is(false));
assertThat(ke.showAllOffsets, is(true));
}

@ParallelTest
Expand All @@ -165,6 +169,7 @@ public void testFromConfigMap() {
assertThat(ke.groupExcludeRegex, is("my-group-exclude-.*"));
assertThat(ke.topicExcludeRegex, is("my-topic-exclude-.*"));
assertThat(ke.saramaLoggingEnabled, is(true));
assertThat(ke.showAllOffsets, is(false));
}

@ParallelTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ if [ "$KAFKA_EXPORTER_ENABLE_SARAMA" = "true" ]; then
saramaenable="--log.enable-sarama"
fi

if [ "$KAFKA_EXPORTER_OFFSET_SHOW_ALL" = "true" ]; then
allgroups="--offset.show-all"
fi

if [ -n "$KAFKA_EXPORTER_LOGGING" ]; then
loglevel="--verbosity=${KAFKA_EXPORTER_LOGGING}"
fi
Expand All @@ -48,8 +52,6 @@ kafkaserver="--kafka.server="$KAFKA_EXPORTER_KAFKA_SERVER

listenaddress="--web.listen-address=:9404"

allgroups="--offset.show-all"

tls="--tls.enabled --tls.ca-file=$CA_CERTS --tls.cert-file=/etc/kafka-exporter/kafka-exporter-certs/kafka-exporter.crt --tls.key-file=/etc/kafka-exporter/kafka-exporter-certs/kafka-exporter.key"

# starting Kafka Exporter with final configuration
Expand Down
2 changes: 2 additions & 0 deletions documentation/modules/appendix_crds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,8 @@ Used in: xref:type-KafkaSpec-{context}[`KafkaSpec`]
|string
|enableSaramaLogging 1.2+<.<a|Enable Sarama logging, a Go client library used by the Kafka Exporter.
|boolean
|showAllOffsets 1.2+<.<a|Enable/disable offset show all option.
|boolean
|template 1.2+<.<a|Customization of deployment templates and pods.
|xref:type-KafkaExporterTemplate-{context}[`KafkaExporterTemplate`]
|livenessProbe 1.2+<.<a|Pod liveness check.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5599,6 +5599,9 @@ spec:
enableSaramaLogging:
type: boolean
description: "Enable Sarama logging, a Go client library used by the Kafka Exporter."
showAllOffsets:
type: boolean
description: Enable/disable offset show all option.
template:
type: object
properties:
Expand Down
3 changes: 3 additions & 0 deletions packaging/install/cluster-operator/040-Crd-kafka.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5598,6 +5598,9 @@ spec:
enableSaramaLogging:
type: boolean
description: "Enable Sarama logging, a Go client library used by the Kafka Exporter."
showAllOffsets:
type: boolean
description: Enable/disable offset show all option.
template:
type: object
properties:
Expand Down
Loading