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
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", "offsetShowAll", "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 offsetShowAll = true;
ilkerkocatepe marked this conversation as resolved.
Show resolved Hide resolved
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 getOffsetShowAll() {
return offsetShowAll;
}

public void setOffsetShowAll(boolean offsetShowAll) {
this.offsetShowAll = offsetShowAll;
}

@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 offsetShowAll;
/* 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.offsetShowAll = 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.offsetShowAll = spec.getOffsetShowAll();

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(offsetShowAll)));

// 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 offsetShowAll = false;

private final KafkaExporterSpec exporterOperator = new KafkaExporterSpecBuilder()
.withLogging(exporterOperatorLogging)
Expand All @@ -102,6 +103,7 @@ public class KafkaExporterTest {
.withTopicExcludeRegex(topicExcludeRegex)
.withImage(keImage)
.withEnableSaramaLogging(true)
.withOffsetShowAll(offsetShowAll)
.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(offsetShowAll)).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.offsetShowAll, is(true));
}

@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" != "false" ]; then
allgroups="--offset.show-all"
fi
ilkerkocatepe marked this conversation as resolved.
Show resolved Hide resolved

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