Skip to content

Commit

Permalink
Support markers for log filtering (#4901)
Browse files Browse the repository at this point in the history
* Support markers for log filtering

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* suggestion

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* fix

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* typo

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* typo

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* comments

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* rename

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* reconciliation

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* tests

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* there is more!

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* more

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* custom wrapper

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* even more

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* maybe little less

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* fix

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* fix

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* ca

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* fix

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* rebase

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* rebase

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* abstract model

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* changes

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* rebase

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* fiddling with validation

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* rebase

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* rebase

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* comments refactoring

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* comments

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* STs

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* Addressing Pull Request Review Comments From Tom B.

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* rebase

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* review comments

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* missed one

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* rc

Signed-off-by: Stanislav Knot <sknot@redhat.com>

* ook?

Signed-off-by: Stanislav Knot <sknot@redhat.com>
  • Loading branch information
sknot-rh committed Jun 8, 2021
1 parent c243e5a commit 3b3a419
Show file tree
Hide file tree
Showing 226 changed files with 13,191 additions and 4,415 deletions.
2 changes: 1 addition & 1 deletion .checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<module name="RightCurly"/>
<module name="EmptyStatement"/>
<module name="ConstantName">
<property name="format" value="(^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$)|(^log$)"/>
<property name="format" value="(^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$)"/>
</module>
<module name="LocalVariableName"/>
<module name="LocalFinalVariableName"/>
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Support pausing reconciliation of KafkaTopic CR with annotation `strimzi.io/pause-reconciliation`
* Update cruise control to 2.5.55
* Support for broker load information added to the rebalance optimization proposal. Information on the load difference, before and after a rebalance is stored in a ConfigMap
* Add support for selectively changing the verbosity of logging for individual CRs, using markers.

### Changes, deprecations and removals

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @param <T> The converted type
*/
public interface Conversion<T> {
Logger log = LogManager.getLogger(Conversion.class);
Logger LOGGER = LogManager.getLogger(Conversion.class);

Conversion<Object> NOOP = new Conversion<>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class OpenSslCertManager implements CertManager {
.appendOffsetId().toFormatter();
public static final int MAXIMUM_CN_LENGTH = 64;

private static final Logger log = LogManager.getLogger(OpenSslCertManager.class);
private static final Logger LOGGER = LogManager.getLogger(OpenSslCertManager.class);
public static final ZoneId UTC = ZoneId.of("UTC");

public OpenSslCertManager() {}
Expand All @@ -79,12 +79,12 @@ static void delete(Path fileOrDir) throws IOException {
try {
Files.delete(path);
} catch (IOException e) {
log.debug("File could not be deleted: {}", fileOrDir);
LOGGER.debug("File could not be deleted: {}", fileOrDir);
}
});
} else {
if (!Files.deleteIfExists(fileOrDir)) {
log.debug("File not deleted, because it did not exist: {}", fileOrDir);
LOGGER.debug("File not deleted, because it did not exist: {}", fileOrDir);
}
}
}
Expand Down Expand Up @@ -534,8 +534,8 @@ public OpensslArgs optArg(String opt, File file) throws IOException {
return optArg(opt, file, false);
}
public OpensslArgs optArg(String opt, File file, boolean mayLog) throws IOException {
if (mayLog && log.isTraceEnabled()) {
log.trace("Contents of {} for option {} is:\n{}", file, opt, Files.readString(file.toPath()));
if (mayLog && LOGGER.isTraceEnabled()) {
LOGGER.trace("Contents of {} for option {} is:\n{}", file, opt, Files.readString(file.toPath()));
}
opt(opt);
pb.command().add(file.getAbsolutePath());
Expand Down Expand Up @@ -614,7 +614,7 @@ public void exec(boolean failOnNonZero) throws IOException {
pb.redirectErrorStream(true)
.redirectOutput(out.toFile());

log.debug("Running command {}", pb.command());
LOGGER.debug("Running command {}", pb.command());

Process proc = pb.start();

Expand All @@ -626,18 +626,18 @@ public void exec(boolean failOnNonZero) throws IOException {

if (failOnNonZero && result != 0) {
String output = Files.readString(out, Charset.defaultCharset());
if (!log.isDebugEnabled()) {
if (!LOGGER.isDebugEnabled()) {
// Include the command if we've not logged it already
log.error("Got result {} from command {} with output\n{}", result, pb.command(), output);
LOGGER.error("Got result {} from command {} with output\n{}", result, pb.command(), output);
} else {
log.error("Got result {} with output\n{}", result, output);
LOGGER.error("Got result {} with output\n{}", result, output);
}
throw new RuntimeException("openssl status code " + result);
} else {
if (log.isTraceEnabled()) {
log.trace("Got output\n{}", Files.readString(out, Charset.defaultCharset()));
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Got output\n{}", Files.readString(out, Charset.defaultCharset()));
}
log.debug("Got result {}", result);
LOGGER.debug("Got result {}", result);
}

} catch (InterruptedException ignored) {
Expand Down
4 changes: 2 additions & 2 deletions cluster-operator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<artifactId>log4j-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<artifactId>log4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import io.vertx.core.Handler;
import io.vertx.core.Promise;
import io.vertx.core.http.HttpServer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -34,6 +32,8 @@

import static java.util.Arrays.asList;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
* An "operator" for managing assemblies of various types <em>in a particular namespace</em>.
Expand All @@ -42,7 +42,7 @@
*/
public class ClusterOperator extends AbstractVerticle {

private static final Logger log = LogManager.getLogger(ClusterOperator.class.getName());
private static final Logger LOGGER = LogManager.getLogger(ClusterOperator.class.getName());

public static final String STRIMZI_CLUSTER_OPERATOR_DOMAIN = "cluster.operator.strimzi.io";
private static final String NAME_SUFFIX = "-cluster-operator";
Expand Down Expand Up @@ -78,7 +78,7 @@ public ClusterOperator(String namespace,
KafkaBridgeAssemblyOperator kafkaBridgeAssemblyOperator,
KafkaRebalanceAssemblyOperator kafkaRebalanceAssemblyOperator,
MetricsProvider metricsProvider) {
log.info("Creating ClusterOperator for namespace {}", namespace);
LOGGER.info("Creating ClusterOperator for namespace {}", namespace);
this.namespace = namespace;
this.config = config;
this.client = client;
Expand All @@ -95,7 +95,7 @@ public ClusterOperator(String namespace,

@Override
public void start(Promise<Void> start) {
log.info("Starting ClusterOperator for namespace {}", namespace);
LOGGER.info("Starting ClusterOperator for namespace {}", namespace);

// Configure the executor here, but it is used only in other places
getVertx().createSharedWorkerExecutor("kubernetes-ops-pool", config.getOperationsThreadPoolSize(), TimeUnit.SECONDS.toNanos(120));
Expand All @@ -109,7 +109,7 @@ public void start(Promise<Void> start) {
}
for (AbstractOperator<?, ?, ?, ?> operator : operators) {
watchFutures.add(operator.createWatch(namespace, operator.recreateWatch(namespace)).compose(w -> {
log.info("Opened watch for {} operator", operator.kind());
LOGGER.info("Opened watch for {} operator", operator.kind());
watchByKind.put(operator.kind(), w);
return Future.succeededFuture();
}));
Expand All @@ -120,9 +120,9 @@ public void start(Promise<Void> start) {

CompositeFuture.join(watchFutures)
.compose(f -> {
log.info("Setting up periodic reconciliation for namespace {}", namespace);
LOGGER.info("Setting up periodic reconciliation for namespace {}", namespace);
this.reconcileTimer = vertx.setPeriodic(this.config.getReconciliationIntervalMs(), res2 -> {
log.info("Triggering periodic reconciliation for namespace {}...", namespace);
LOGGER.info("Triggering periodic reconciliation for namespace {}...", namespace);
reconcileAll("timer");
});
return startHealthServer().map((Void) null);
Expand All @@ -133,7 +133,7 @@ public void start(Promise<Void> start) {

@Override
public void stop(Promise<Void> stop) {
log.info("Stopping ClusterOperator for namespace {}", namespace);
LOGGER.info("Stopping ClusterOperator for namespace {}", namespace);
vertx.cancelTimer(reconcileTimer);
for (Watch watch : watchByKind.values()) {
if (watch != null) {
Expand Down Expand Up @@ -182,9 +182,9 @@ private Future<HttpServer> startHealthServer() {
})
.listen(HEALTH_SERVER_PORT, ar -> {
if (ar.succeeded()) {
log.info("ClusterOperator is now ready (health server listening on {})", HEALTH_SERVER_PORT);
LOGGER.info("ClusterOperator is now ready (health server listening on {})", HEALTH_SERVER_PORT);
} else {
log.error("Unable to bind health server on {}", HEALTH_SERVER_PORT, ar.cause());
LOGGER.error("Unable to bind health server on {}", HEALTH_SERVER_PORT, ar.cause());
}
result.handle(ar);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
* Cluster Operator configuration
*/
public class ClusterOperatorConfig {
private static final Logger log = LogManager.getLogger(ClusterOperatorConfig.class.getName());
private static final Logger LOGGER = LogManager.getLogger(ClusterOperatorConfig.class.getName());


public static final String STRIMZI_NAMESPACE = "STRIMZI_NAMESPACE";
public static final String STRIMZI_FULL_RECONCILIATION_INTERVAL_MS = "STRIMZI_FULL_RECONCILIATION_INTERVAL_MS";
Expand Down Expand Up @@ -159,7 +160,7 @@ public static ClusterOperatorConfig fromMap(Map<String, String> map) {
*/
private static void warningsForRemovedEndVars(Map<String, String> map) {
if (map.containsKey(STRIMZI_DEFAULT_TLS_SIDECAR_KAFKA_IMAGE)) {
log.warn("Kafka TLS sidecar container has been removed and the environment variable {} is not used anymore. " +
LOGGER.warn("Kafka TLS sidecar container has been removed and the environment variable {} is not used anymore. " +
"You can remove it from the Strimzi Cluster Operator deployment.", STRIMZI_DEFAULT_TLS_SIDECAR_KAFKA_IMAGE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
import io.strimzi.operator.cluster.operator.assembly.KafkaRebalanceAssemblyOperator;
import io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier;
import io.strimzi.operator.common.PasswordGenerator;
import io.strimzi.operator.common.Reconciliation;
import io.strimzi.operator.common.Util;
import io.strimzi.operator.common.operator.resource.ClusterRoleOperator;
import io.vertx.core.CompositeFuture;
import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.BufferedReader;
import java.io.IOException;
Expand All @@ -43,10 +42,12 @@
import io.vertx.core.VertxOptions;
import io.vertx.micrometer.MicrometerMetricsOptions;
import io.vertx.micrometer.VertxPrometheusOptions;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@SuppressFBWarnings("DM_EXIT")
public class Main {
private static final Logger log = LogManager.getLogger(Main.class.getName());
private static final Logger LOGGER = LogManager.getLogger(Main.class.getName());

static {
try {
Expand All @@ -57,9 +58,9 @@ public class Main {
}

public static void main(String[] args) {
log.info("ClusterOperator {} is starting", Main.class.getPackage().getImplementationVersion());
LOGGER.info("ClusterOperator {} is starting", Main.class.getPackage().getImplementationVersion());
ClusterOperatorConfig config = ClusterOperatorConfig.fromMap(System.getenv());
log.info("Cluster Operator configuration is {}", config);
LOGGER.info("Cluster Operator configuration is {}", config);

String dnsCacheTtl = System.getenv("STRIMZI_DNS_CACHE_TTL") == null ? "30" : System.getenv("STRIMZI_DNS_CACHE_TTL");
Security.setProperty("networkaddress.cache.ttl", dnsCacheTtl);
Expand All @@ -78,21 +79,21 @@ public static void main(String[] args) {
if (crs.succeeded()) {
PlatformFeaturesAvailability.create(vertx, client).onComplete(pfa -> {
if (pfa.succeeded()) {
log.info("Environment facts gathered: {}", pfa.result());
LOGGER.info("Environment facts gathered: {}", pfa.result());

run(vertx, client, pfa.result(), config).onComplete(ar -> {
if (ar.failed()) {
log.error("Unable to start operator for 1 or more namespace", ar.cause());
LOGGER.error("Unable to start operator for 1 or more namespace", ar.cause());
System.exit(1);
}
});
} else {
log.error("Failed to gather environment facts", pfa.cause());
LOGGER.error("Failed to gather environment facts", pfa.cause());
System.exit(1);
}
});
} else {
log.error("Failed to create Cluster Roles", crs.cause());
LOGGER.error("Failed to create Cluster Roles", crs.cause());
System.exit(1);
}
});
Expand All @@ -119,7 +120,7 @@ static CompositeFuture run(Vertx vertx, KubernetesClient client, PlatformFeature
if (pfa.supportsS2I()) {
kafkaConnectS2IClusterOperations = new KafkaConnectS2IAssemblyOperator(vertx, pfa, resourceOperatorSupplier, config);
} else {
log.info("The KafkaConnectS2I custom resource definition can only be used in environment which supports OpenShift build, image and apps APIs. These APIs do not seem to be supported in this environment.");
LOGGER.info("The KafkaConnectS2I custom resource definition can only be used in environment which supports OpenShift build, image and apps APIs. These APIs do not seem to be supported in this environment.");
}

KafkaMirrorMaker2AssemblyOperator kafkaMirrorMaker2AssemblyOperator =
Expand Down Expand Up @@ -152,9 +153,9 @@ static CompositeFuture run(Vertx vertx, KubernetesClient client, PlatformFeature
vertx.deployVerticle(operator,
res -> {
if (res.succeeded()) {
log.info("Cluster Operator verticle started in namespace {} with label selector {}", namespace, config.getCustomResourceSelector());
LOGGER.info("Cluster Operator verticle started in namespace {} with label selector {}", namespace, config.getCustomResourceSelector());
} else {
log.error("Cluster Operator verticle in namespace {} failed to start", namespace, res.cause());
LOGGER.error("Cluster Operator verticle in namespace {} failed to start", namespace, res.cause());
System.exit(1);
}
prom.handle(res);
Expand All @@ -176,17 +177,17 @@ static CompositeFuture run(Vertx vertx, KubernetesClient client, PlatformFeature
clusterRoles.put("strimzi-kafka-client", "033-ClusterRole-strimzi-kafka-client.yaml");

for (Map.Entry<String, String> clusterRole : clusterRoles.entrySet()) {
log.info("Creating cluster role {}", clusterRole.getKey());
LOGGER.info("Creating cluster role {}", clusterRole.getKey());

try (BufferedReader br = new BufferedReader(
new InputStreamReader(Main.class.getResourceAsStream("/cluster-roles/" + clusterRole.getValue()),
StandardCharsets.UTF_8))) {
String yaml = br.lines().collect(Collectors.joining(System.lineSeparator()));
ClusterRole role = ClusterRoleOperator.convertYamlToClusterRole(yaml);
Future fut = cro.reconcile(role.getMetadata().getName(), role);
Future fut = cro.reconcile(new Reconciliation("start-cluster-operator", "Deployment", config.getOperatorNamespace(), "cluster-operator"), role.getMetadata().getName(), role);
futures.add(fut);
} catch (IOException e) {
log.error("Failed to create Cluster Roles.", e);
LOGGER.error("Failed to create Cluster Roles.", e);
throw new RuntimeException(e);
}

Expand Down

0 comments on commit 3b3a419

Please sign in to comment.