From dfc719041fce2c2a73aa8b3eeab4743e9a33f6c7 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Mon, 25 Mar 2024 13:17:07 +0100 Subject: [PATCH] Remove `log4j-kubernetes` in version 3.x Due to differences in the lifecycle of Log4j Core and Kubernetes Client, we remove `log4j-kubernetes` from the 3.x release and redirect users to Fabric8's own `kubernetes-log4j` artifact introduced in fabric8io/kubernetes-client#5718. The `log4j-kubernetes` lookup depends on: * the very stable `StrLookup` interface from Log4j Core, * the evolving set of Kubernetes metadata provided by Kubernetes Client. Therefore it makes more sense to distribute the lookup together with Kubernetes Client. --- log4j-kubernetes/pom.xml | 85 ----- .../log4j/kubernetes/ContainerUtil.java | 92 ------ .../kubernetes/KubernetesClientBuilder.java | 74 ----- .../KubernetesClientProperties.java | 190 ----------- .../log4j/kubernetes/KubernetesLookup.java | 298 ------------------ .../log4j/kubernetes/package-info.java | 24 -- .../kubernetes/KubernetesLookupTest.java | 98 ------ .../src/test/resources/clusterPod.json | 177 ----------- .../src/test/resources/localPod.json | 141 --------- log4j-parent/pom.xml | 9 - pom.xml | 7 - src/site/asciidoc/log4j-kubernetes.adoc | 201 ------------ src/site/asciidoc/manual/cloud.adoc | 2 +- src/site/asciidoc/manual/lookups.adoc | 28 +- 14 files changed, 2 insertions(+), 1424 deletions(-) delete mode 100644 log4j-kubernetes/pom.xml delete mode 100644 log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/ContainerUtil.java delete mode 100644 log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/KubernetesClientBuilder.java delete mode 100644 log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/KubernetesClientProperties.java delete mode 100644 log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/KubernetesLookup.java delete mode 100644 log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/package-info.java delete mode 100644 log4j-kubernetes/src/test/java/org/apache/logging/log4j/kubernetes/KubernetesLookupTest.java delete mode 100644 log4j-kubernetes/src/test/resources/clusterPod.json delete mode 100644 log4j-kubernetes/src/test/resources/localPod.json delete mode 100644 src/site/asciidoc/log4j-kubernetes.adoc diff --git a/log4j-kubernetes/pom.xml b/log4j-kubernetes/pom.xml deleted file mode 100644 index 9162c079fd26..000000000000 --- a/log4j-kubernetes/pom.xml +++ /dev/null @@ -1,85 +0,0 @@ - - - - 4.0.0 - - org.apache.logging.log4j - log4j - ${revision} - ../log4j-parent - - log4j-kubernetes - jar - Apache Log4j Kubernetes Library - Apache Log4j Kubernetes Support - - - - - - kubernetes.client;substitute="kubernetes-client";transitive=false;static=true, - kubernetes.model.core;substitute="kubernetes-model-core";transitive=false;static=true - - org.apache.logging.log4j.core - - - - org.apache.logging.log4j - log4j-api - - - org.apache.logging.log4j - log4j-core - - - - io.fabric8 - kubernetes-client - - - org.junit.jupiter - junit-jupiter-engine - test - - - org.junit.vintage - junit-vintage-engine - test - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - org.apache.logging.log4j - log4j-plugin-processor - ${project.version} - - - - - - - diff --git a/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/ContainerUtil.java b/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/ContainerUtil.java deleted file mode 100644 index 814b2c11cf44..000000000000 --- a/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/ContainerUtil.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.logging.log4j.kubernetes; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Objects; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.status.StatusLogger; - -/** - * Locate the current docker container. - */ -public class ContainerUtil { - private static final Logger LOGGER = StatusLogger.getLogger(); - private static final int MAXLENGTH = 65; - - /** - * Returns the container id when running in a Docker container. - * - * This inspects /proc/self/cgroup looking for a Kubernetes Control Group. Once it finds one it attempts - * to isolate just the docker container id. There doesn't appear to be a standard way to do this, but - * it seems to be the only way to determine what the current container is in a multi-container pod. It would have - * been much nicer if Kubernetes would just put the container id in a standard environment variable. - * - * @see Stackoverflow for a discussion on retrieving the containerId. - * @see ControlGroup - * for the original version of this. Not much is actually left but it provided good inspiration. - * @return The container id. - */ - public static String getContainerId() { - try { - final File file = new File("/proc/self/cgroup"); - if (file.exists()) { - final Path path = file.toPath(); - final String id = Files.lines(path) - .map(ContainerUtil::getContainerId) - .filter(Objects::nonNull) - .findFirst() - .orElse(null); - LOGGER.debug("Found container id {}", id); - return id; - } - LOGGER.warn("Unable to access container information"); - } catch (IOException ioe) { - LOGGER.warn("Error obtaining container id: {}", ioe.getMessage()); - } - return null; - } - - private static String getContainerId(String line) { - // Every control group in Kubernetes will use - if (line.contains("/kubepods")) { - // Strip off everything up to the last slash. - int i = line.lastIndexOf('/'); - if (i < 0) { - return null; - } - // If the remainder has a period then take everything up to it. - line = line.substring(i + 1); - i = line.lastIndexOf('.'); - if (i > 0) { - line = line.substring(0, i); - } - // Everything ending with a '/' has already been stripped but the remainder might start with "docker-" - if (line.contains("docker-")) { - // 8:cpuset:/kubepods.slice/kubepods-pod9c26dfb6_b9c9_11e7_bfb9_02c6c1fc4861.slice/docker-3dd988081e7149463c043b5d9c57d7309e079c5e9290f91feba1cc45a04d6a5b.scope - i = line.lastIndexOf("docker-"); - line = line.substring(i + 7); - } - return line.length() <= MAXLENGTH ? line : line.substring(0, MAXLENGTH); - } - - return null; - } -} diff --git a/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/KubernetesClientBuilder.java b/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/KubernetesClientBuilder.java deleted file mode 100644 index 3847c74a6b01..000000000000 --- a/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/KubernetesClientBuilder.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.logging.log4j.kubernetes; - -import io.fabric8.kubernetes.client.Config; -import io.fabric8.kubernetes.client.ConfigBuilder; -import io.fabric8.kubernetes.client.DefaultKubernetesClient; -import io.fabric8.kubernetes.client.KubernetesClient; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.status.StatusLogger; - -/** - * Builds a Kubernetes Client. - */ -public class KubernetesClientBuilder { - - private static final Logger LOGGER = StatusLogger.getLogger(); - - public KubernetesClient createClient() { - final Config config = kubernetesClientConfig(); - return config != null ? new DefaultKubernetesClient(config) : null; - } - - private Config kubernetesClientConfig() { - Config base = null; - try { - base = Config.autoConfigure(null); - } catch (Exception ex) { - if (ex instanceof NullPointerException) { - return null; - } - } - final KubernetesClientProperties props = new KubernetesClientProperties(base); - final Config properties = new ConfigBuilder(base) - .withApiVersion(props.getApiVersion()) - .withCaCertData(props.getCaCertData()) - .withCaCertFile(props.getCaCertFile()) - .withClientCertData(props.getClientCertData()) - .withClientCertFile(props.getClientCertFile()) - .withClientKeyAlgo(props.getClientKeyAlgo()) - .withClientKeyData(props.getClientKeyData()) - .withClientKeyFile(props.getClientKeyFile()) - .withClientKeyPassphrase(props.getClientKeyPassphrase()) - .withConnectionTimeout(props.getConnectionTimeout()) - .withHttpProxy(props.getHttpProxy()) - .withHttpsProxy(props.getHttpsProxy()) - .withMasterUrl(props.getMasterUrl()) - .withNamespace(props.getNamespace()) - .withNoProxy(props.getNoProxy()) - .withPassword(props.getPassword()) - .withProxyPassword(props.getProxyPassword()) - .withProxyUsername(props.getProxyUsername()) - .withRequestTimeout(props.getRequestTimeout()) - .withRollingTimeout(props.getRollingTimeout()) - .withTrustCerts(props.isTrustCerts()) - .withUsername(props.getUsername()) - .build(); - return properties; - } -} diff --git a/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/KubernetesClientProperties.java b/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/KubernetesClientProperties.java deleted file mode 100644 index ca461802c773..000000000000 --- a/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/KubernetesClientProperties.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.logging.log4j.kubernetes; - -import io.fabric8.kubernetes.client.Config; -import java.time.Duration; -import org.apache.logging.log4j.util.PropertiesUtil; -import org.apache.logging.log4j.util.PropertyEnvironment; - -/** - * Obtains properties used to configure the Kubernetes client. - */ -public class KubernetesClientProperties { - - private static final String[] PREFIXES = {"log4j2.kubernetes.client.", "spring.cloud.kubernetes.client."}; - private static final String API_VERSION = "apiVersion"; - private static final String CA_CERT_FILE = "caCertFile"; - private static final String CA_CERT_DATA = "caCertData"; - private static final String CLIENT_CERT_FILE = "clientCertFile"; - private static final String CLIENT_CERT_DATA = "clientCertData"; - private static final String CLIENT_KEY_FILE = "clientKeyFile"; - private static final String CLIENT_KEY_DATA = "clientKeyData"; - private static final String CLIENT_KEY_ALGO = "clientKeyAlgo"; - private static final String CLIENT_KEY_PASSPHRASE = "clientKeyPassphrase"; - private static final String CONNECTION_TIMEOUT = "connectionTimeout"; - private static final String HTTP_PROXY = "httpProxy"; - private static final String HTTPS_PROXY = "httpsProxy"; - private static final String LOGGING_INTERVAL = "loggingInterval"; - private static final String MASTER_URL = "masterUrl"; - private static final String NAMESPACE = "namespace"; - private static final String NO_PROXY = "noProxy"; - private static final String PASSWORD = "password"; - private static final String PROXY_USERNAME = "proxyUsername"; - private static final String PROXY_PASSWORD = "proxyPassword"; - private static final String REQUEST_TIMEOUT = "requestTimeout"; - private static final String ROLLING_TIMEOUT = "rollingTimeout"; - private static final String TRUST_CERTS = "trustCerts"; - private static final String USERNAME = "username"; - private static final String WATCH_RECONNECT_INTERVAL = "watchReconnectInterval"; - private static final String WATCH_RECONNECT_LIMIT = "watchReconnectLimit"; - - private final PropertyEnvironment props = PropertiesUtil.getProperties(); - private final Config base; - - public KubernetesClientProperties(final Config base) { - this.base = base; - } - - public String getApiVersion() { - return props.getStringProperty(PREFIXES, API_VERSION, base::getApiVersion); - } - - public String getCaCertFile() { - return props.getStringProperty(PREFIXES, CA_CERT_FILE, base::getCaCertFile); - } - - public String getCaCertData() { - return props.getStringProperty(PREFIXES, CA_CERT_DATA, base::getCaCertData); - } - - public String getClientCertFile() { - return props.getStringProperty(PREFIXES, CLIENT_CERT_FILE, base::getClientCertFile); - } - - public String getClientCertData() { - return props.getStringProperty(PREFIXES, CLIENT_CERT_DATA, base::getClientCertData); - } - - public String getClientKeyFile() { - return props.getStringProperty(PREFIXES, CLIENT_KEY_FILE, base::getClientKeyFile); - } - - public String getClientKeyData() { - return props.getStringProperty(PREFIXES, CLIENT_KEY_DATA, base::getClientKeyData); - } - - public String getClientKeyAlgo() { - return props.getStringProperty(PREFIXES, CLIENT_KEY_ALGO, base::getClientKeyAlgo); - } - - public String getClientKeyPassphrase() { - return props.getStringProperty(PREFIXES, CLIENT_KEY_PASSPHRASE, base::getClientKeyPassphrase); - } - - public int getConnectionTimeout() { - final Duration timeout = props.getDurationProperty(PREFIXES, CONNECTION_TIMEOUT, null); - if (timeout != null) { - return (int) timeout.toMillis(); - } - return base.getConnectionTimeout(); - } - - public String getHttpProxy() { - return props.getStringProperty(PREFIXES, HTTP_PROXY, base::getHttpProxy); - } - - public String getHttpsProxy() { - return props.getStringProperty(PREFIXES, HTTPS_PROXY, base::getHttpsProxy); - } - - public int getLoggingInterval() { - final Duration interval = props.getDurationProperty(PREFIXES, LOGGING_INTERVAL, null); - if (interval != null) { - return (int) interval.toMillis(); - } - return base.getLoggingInterval(); - } - - public String getMasterUrl() { - return props.getStringProperty(PREFIXES, MASTER_URL, base::getMasterUrl); - } - - public String getNamespace() { - return props.getStringProperty(PREFIXES, NAMESPACE, base::getNamespace); - } - - public String[] getNoProxy() { - final String result = props.getStringProperty(PREFIXES, NO_PROXY, null); - if (result != null) { - return result.replace("\\s", "").split(","); - } - return base.getNoProxy(); - } - - public String getPassword() { - return props.getStringProperty(PREFIXES, PASSWORD, base::getPassword); - } - - public String getProxyUsername() { - return props.getStringProperty(PREFIXES, PROXY_USERNAME, base::getProxyUsername); - } - - public String getProxyPassword() { - return props.getStringProperty(PREFIXES, PROXY_PASSWORD, base::getProxyPassword); - } - - public int getRequestTimeout() { - final Duration interval = props.getDurationProperty(PREFIXES, REQUEST_TIMEOUT, null); - if (interval != null) { - return (int) interval.toMillis(); - } - return base.getRequestTimeout(); - } - - public long getRollingTimeout() { - final Duration interval = props.getDurationProperty(PREFIXES, ROLLING_TIMEOUT, null); - if (interval != null) { - return interval.toMillis(); - } - return base.getRollingTimeout(); - } - - public Boolean isTrustCerts() { - return props.getBooleanProperty(PREFIXES, TRUST_CERTS, base::isTrustCerts); - } - - public String getUsername() { - return props.getStringProperty(PREFIXES, USERNAME, base::getUsername); - } - - public int getWatchReconnectInterval() { - final Duration interval = props.getDurationProperty(PREFIXES, WATCH_RECONNECT_INTERVAL, null); - if (interval != null) { - return (int) interval.toMillis(); - } - return base.getWatchReconnectInterval(); - } - - public int getWatchReconnectLimit() { - final Duration interval = props.getDurationProperty(PREFIXES, WATCH_RECONNECT_LIMIT, null); - if (interval != null) { - return (int) interval.toMillis(); - } - return base.getWatchReconnectLimit(); - } -} diff --git a/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/KubernetesLookup.java b/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/KubernetesLookup.java deleted file mode 100644 index 9b2cd85c406a..000000000000 --- a/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/KubernetesLookup.java +++ /dev/null @@ -1,298 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.logging.log4j.kubernetes; - -import io.fabric8.kubernetes.api.model.Container; -import io.fabric8.kubernetes.api.model.ContainerStatus; -import io.fabric8.kubernetes.api.model.Namespace; -import io.fabric8.kubernetes.api.model.Pod; -import io.fabric8.kubernetes.client.Config; -import io.fabric8.kubernetes.client.KubernetesClient; -import java.net.URL; -import java.nio.file.Paths; -import java.util.List; -import java.util.Map; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.lookup.AbstractLookup; -import org.apache.logging.log4j.core.lookup.Lookup; -import org.apache.logging.log4j.plugins.Plugin; -import org.apache.logging.log4j.status.StatusLogger; -import org.apache.logging.log4j.util.LoaderUtil; -import org.apache.logging.log4j.util.Strings; - -/** - * Retrieve various Kubernetes attributes. Supported keys are: - * accountName, containerId, containerName, clusterName, host, hostIp, labels, labels.app, - * labels.podTemplateHash, masterUrl, namespaceId, namespaceName, podId, podIp, podName, - * imageId, imageName. - */ -@Lookup -@Plugin("k8s") -public class KubernetesLookup extends AbstractLookup { - - private static final Logger LOGGER = StatusLogger.getLogger(); - private static final String HOSTNAME = "HOSTNAME"; - private static final String SPRING_ENVIRONMENT_KEY = "SpringEnvironment"; - - private static volatile KubernetesInfo kubernetesInfo; - private static final Lock initLock = new ReentrantLock(); - private static final boolean isSpringIncluded = - LoaderUtil.isClassAvailable("org.apache.logging.log4j.spring.cloud.config.client.SpringEnvironmentHolder") - || LoaderUtil.isClassAvailable("org.apache.logging.log4j.spring.boot.SpringEnvironmentHolder"); - private Pod pod; - private Namespace namespace; - private URL masterUrl; - - public KubernetesLookup() { - this.pod = null; - this.namespace = null; - this.masterUrl = null; - initialize(); - } - - KubernetesLookup(Pod pod, Namespace namespace, URL masterUrl) { - this.pod = pod; - this.namespace = namespace; - this.masterUrl = masterUrl; - initialize(); - } - - private boolean initialize() { - if (kubernetesInfo == null || (isSpringIncluded && !kubernetesInfo.isSpringActive)) { - initLock.lock(); - try { - final boolean isSpringActive = isSpringActive(); - if (kubernetesInfo == null || (!kubernetesInfo.isSpringActive && isSpringActive)) { - final KubernetesInfo info = new KubernetesInfo(); - KubernetesClient client = null; - info.isSpringActive = isSpringActive; - if (pod == null) { - client = new KubernetesClientBuilder().createClient(); - if (client != null) { - pod = getCurrentPod(System.getenv(HOSTNAME), client); - info.masterUrl = client.getMasterUrl(); - if (pod != null) { - info.namespace = pod.getMetadata().getNamespace(); - namespace = client.namespaces() - .withName(info.namespace) - .get(); - } - } else { - LOGGER.warn("Kubernetes is not available for access"); - } - } else { - info.masterUrl = masterUrl; - } - if (pod != null) { - if (namespace != null) { - info.namespaceId = namespace.getMetadata().getUid(); - info.namespaceAnnotations = namespace.getMetadata().getAnnotations(); - info.namespaceLabels = namespace.getMetadata().getLabels(); - } - info.app = pod.getMetadata().getLabels().get("app"); - info.hostName = pod.getSpec().getNodeName(); - info.annotations = pod.getMetadata().getAnnotations(); - final String app = info.app != null ? info.app : ""; - info.podTemplateHash = pod.getMetadata().getLabels().get("pod-template-hash"); - info.accountName = pod.getSpec().getServiceAccountName(); - info.clusterName = pod.getMetadata().getClusterName(); - info.hostIp = pod.getStatus().getHostIP(); - info.labels = pod.getMetadata().getLabels(); - info.podId = pod.getMetadata().getUid(); - info.podIp = pod.getStatus().getPodIP(); - info.podName = pod.getMetadata().getName(); - ContainerStatus containerStatus = null; - final List statuses = pod.getStatus().getContainerStatuses(); - if (statuses.size() == 1) { - containerStatus = statuses.get(0); - } else if (statuses.size() > 1) { - final String containerId = ContainerUtil.getContainerId(); - if (containerId != null) { - containerStatus = statuses.stream() - .filter(cs -> cs.getContainerID().contains(containerId)) - .findFirst() - .orElse(null); - } - } - final String containerName; - if (containerStatus != null) { - info.containerId = containerStatus.getContainerID(); - info.imageId = containerStatus.getImageID(); - containerName = containerStatus.getName(); - } else { - containerName = null; - } - Container container = null; - final List containers = pod.getSpec().getContainers(); - if (containers.size() == 1) { - container = containers.get(0); - } else if (containers.size() > 1 && containerName != null) { - container = containers.stream() - .filter(c -> c.getName().equals(containerName)) - .findFirst() - .orElse(null); - } - if (container != null) { - info.containerName = container.getName(); - info.imageName = container.getImage(); - } - - kubernetesInfo = info; - } - } - } finally { - initLock.unlock(); - } - } - return kubernetesInfo != null; - } - - @Override - public String lookup(final LogEvent event, final String key) { - if (kubernetesInfo == null) { - return null; - } - switch (key) { - case "accountName": { - return kubernetesInfo.accountName; - } - case "annotations": { - return kubernetesInfo.annotations.toString(); - } - case "containerId": { - return kubernetesInfo.containerId; - } - case "containerName": { - return kubernetesInfo.containerName; - } - case "clusterName": { - return kubernetesInfo.clusterName; - } - case "host": { - return kubernetesInfo.hostName; - } - case "hostIp": { - return kubernetesInfo.hostIp; - } - case "labels": { - return kubernetesInfo.labels.toString(); - } - case "labels.app": { - return kubernetesInfo.app; - } - case "labels.podTemplateHash": { - return kubernetesInfo.podTemplateHash; - } - case "masterUrl": { - return kubernetesInfo.masterUrl.toString(); - } - case "namespaceAnnotations": { - return kubernetesInfo.namespaceAnnotations.toString(); - } - case "namespaceId": { - return kubernetesInfo.namespaceId; - } - case "namespaceLabels": { - return kubernetesInfo.namespaceLabels.toString(); - } - case "namespaceName": { - return kubernetesInfo.namespace; - } - case "podId": { - return kubernetesInfo.podId; - } - case "podIp": { - return kubernetesInfo.podIp; - } - case "podName": { - return kubernetesInfo.podName; - } - case "imageId": { - return kubernetesInfo.imageId; - } - case "imageName": { - return kubernetesInfo.imageName; - } - default: - return null; - } - } - - /** - * For unit testing only. - */ - void clearInfo() { - kubernetesInfo = null; - } - - private String getHostname() { - return System.getenv(HOSTNAME); - } - - private Pod getCurrentPod(final String hostName, final KubernetesClient kubernetesClient) { - try { - if (isServiceAccount() && Strings.isNotBlank(hostName)) { - return kubernetesClient.pods().withName(hostName).get(); - } - } catch (Throwable t) { - LOGGER.debug("Unable to locate pod with name {}.", hostName); - } - return null; - } - - private boolean isServiceAccount() { - return Paths.get(Config.KUBERNETES_SERVICE_ACCOUNT_TOKEN_PATH).toFile().exists() - && Paths.get(Config.KUBERNETES_SERVICE_ACCOUNT_CA_CRT_PATH) - .toFile() - .exists(); - } - - private boolean isSpringActive() { - return isSpringIncluded - && LogManager.getFactory() != null - && LogManager.getFactory().hasContext(KubernetesLookup.class.getName(), null, false) - && LogManager.getContext(false).getObject(SPRING_ENVIRONMENT_KEY) != null; - } - - private static class KubernetesInfo { - boolean isSpringActive; - String accountName; - Map annotations; - String app; - String clusterName; - String containerId; - String containerName; - String hostName; - String hostIp; - String imageId; - String imageName; - Map labels; - URL masterUrl; - String namespace; - Map namespaceAnnotations; - String namespaceId; - Map namespaceLabels; - String podId; - String podIp; - String podName; - String podTemplateHash; - } -} diff --git a/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/package-info.java b/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/package-info.java deleted file mode 100644 index 5eeaf75555dc..000000000000 --- a/log4j-kubernetes/src/main/java/org/apache/logging/log4j/kubernetes/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -@Export -@Open("org.apache.logging.log4j.core") -@Version("2.20.1") -package org.apache.logging.log4j.kubernetes; - -import aQute.bnd.annotation.jpms.Open; -import org.osgi.annotation.bundle.Export; -import org.osgi.annotation.versioning.Version; diff --git a/log4j-kubernetes/src/test/java/org/apache/logging/log4j/kubernetes/KubernetesLookupTest.java b/log4j-kubernetes/src/test/java/org/apache/logging/log4j/kubernetes/KubernetesLookupTest.java deleted file mode 100644 index e01a1051d55f..000000000000 --- a/log4j-kubernetes/src/test/java/org/apache/logging/log4j/kubernetes/KubernetesLookupTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.logging.log4j.kubernetes; - -import static org.junit.Assert.assertEquals; - -import com.fasterxml.jackson.databind.ObjectMapper; -import io.fabric8.kubernetes.api.model.Namespace; -import io.fabric8.kubernetes.api.model.ObjectMeta; -import io.fabric8.kubernetes.api.model.Pod; -import java.io.File; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * Validate the Kubernetes Lookup. - */ -public class KubernetesLookupTest { - - private static final String localJson = "target/test-classes/localPod.json"; - private static final String clusterJson = "target/test-classes/clusterPod.json"; - private static final ObjectMapper objectMapper = new ObjectMapper(); - public static URL masterUrl; - - @BeforeClass - public static void beforeClass() throws Exception { - masterUrl = new URL("http://localhost:443/"); - } - - @Test - public void testLocal() throws Exception { - final Pod pod = objectMapper.readValue(new File(localJson), Pod.class); - final Namespace namespace = createNamespace(); - final KubernetesLookup lookup = new KubernetesLookup(pod, namespace, masterUrl); - try { - assertEquals("Incorrect container name", "sampleapp", lookup.lookup("containerName")); - assertEquals( - "Incorrect container id", - "docker://818b0098946c67e6ac56cb7c0934b7c2a9f50feb7244b422b2a7f566f7e5d0df", - lookup.lookup("containerId")); - assertEquals("Incorrect host name", "docker-desktop", lookup.lookup("host")); - assertEquals("Incorrect pod name", "sampleapp-584f99476d-mnrp4", lookup.lookup("podName")); - } finally { - lookup.clearInfo(); - } - } - - @Test - public void testCluster() throws Exception { - final Pod pod = objectMapper.readValue(new File(clusterJson), Pod.class); - final Namespace namespace = createNamespace(); - final KubernetesLookup lookup = new KubernetesLookup(pod, namespace, masterUrl); - try { - assertEquals("Incorrect container name", "platform-forms-service", lookup.lookup("containerName")); - assertEquals( - "Incorrect container id", - "docker://2b7c2a93dfb48334aa549e29fdd38039ddd256eec43ba64c145fa4b75a1542f0", - lookup.lookup("containerId")); - assertEquals("Incorrect host name", "k8s-tmpcrm-worker-s03-04", lookup.lookup("host")); - assertEquals( - "Incorrect pod name", "platform-forms-service-primary-5ddfc4f9b8-kfpzv", lookup.lookup("podName")); - } finally { - lookup.clearInfo(); - } - } - - private Namespace createNamespace() { - final Namespace namespace = new Namespace(); - final ObjectMeta meta = new ObjectMeta(); - final Map annotations = new HashMap<>(); - annotations.put("test", "name"); - meta.setAnnotations(annotations); - final Map labels = new HashMap<>(); - labels.put("ns", "my-namespace"); - meta.setLabels(labels); - meta.setUid(UUID.randomUUID().toString()); - namespace.setMetadata(meta); - return namespace; - } -} diff --git a/log4j-kubernetes/src/test/resources/clusterPod.json b/log4j-kubernetes/src/test/resources/clusterPod.json deleted file mode 100644 index 7bae9c35ebe5..000000000000 --- a/log4j-kubernetes/src/test/resources/clusterPod.json +++ /dev/null @@ -1,177 +0,0 @@ -{ - "apiVersion": "v1", - "kind": "Pod", - "metadata": { - "annotations": { - "cni.projectcalico.org/podIP": "172.16.55.101/32", - "cni.projectcalico.org/podIPs": "172.16.55.101/32", - "flagger-id": "94d53b7b-cc06-41b3-bbac-a2d14a16d95d", - "prometheus.io/port": "9797", - "prometheus.io/scrape": "true" - }, - "creationTimestamp": "2020-06-15T15:44:16Z", - "generateName": "platform-forms-service-primary-5ddfc4f9b8-", - "labels": { - "app": "platform-forms-service-primary", - "pod-template-hash": "5ddfc4f9b8" - }, - "name": "platform-forms-service-primary-5ddfc4f9b8-kfpzv", - "namespace": "default", - "ownerReferences": [ - { - "apiVersion": "apps/v1", - "kind": "ReplicaSet", - "blockOwnerDeletion": true, - "controller": true, - "name": "platform-forms-service-primary-5ddfc4f9b8", - "uid": "d2e89c56-7623-439e-a9ee-4a67e2f3a81a" - }], - "resourceVersion": "37382150", - "selfLink": "/api/v1/namespaces/default/pods/platform-forms-service-primary-5ddfc4f9b8-kfpzv", - "uid": "df8cbac1-129c-4cd3-b5bc-65d72d8ba5f0" - }, - "spec": { - "containers": [ - { - "env": [ - { - "name": "APACHE_ENV", - "value": "tmpcrm" - }, - { - "name": "SPRING_PROFILES_ACTIVE", - "value": "tmpcrm" - }, - { - "name": "JAVA_OPTS", - "value": "-Dlogging.label=crm" - }], - "image": "docker.apache.xyz/platform-forms-service:0.15.0", - "imagePullPolicy": "Always", - "livenessProbe": { - "failureThreshold": 3, - "httpGet": { - "path": "/info", - "port": "http", - "scheme": "HTTP" - }, - "periodSeconds": 10, - "successThreshold": 1, - "timeoutSeconds": 1 - }, - "name": "platform-forms-service", - "ports": [ - { - "containerPort": 8080, - "name": "http", - "protocol": "TCP" - }], - "readinessProbe": { - "failureThreshold": 3, - "httpGet": { - "path": "/health", - "port": "http", - "scheme": "HTTP" - }, - "periodSeconds": 10, - "successThreshold": 1, - "timeoutSeconds": 1 - }, - "resources": { - }, - "securityContext": { - }, - "terminationMessagePath": "/dev/termination-log", - "terminationMessagePolicy": "File", - "volumeMounts": [ - { - "mountPath": "/var/run/secrets/kubernetes.io/serviceaccount", - "name": "default-token-2nqlw", - "readOnly": true - }] - }], - "dnsPolicy": "ClusterFirst", - "enableServiceLinks": true, - "nodeName": "k8s-tmpcrm-worker-s03-04", - "priority": 0, - "restartPolicy": "Always", - "schedulerName": "default-scheduler", - "securityContext": { - }, - "serviceAccount": "default", - "serviceAccountName": "default", - "terminationGracePeriodSeconds": 30, - "tolerations": [ - { - "effect": "NoExecute", - "key": "node.kubernetes.io/not-ready", - "operator": "Exists", - "tolerationSeconds": 300 - }, - { - "effect": "NoExecute", - "key": "node.kubernetes.io/unreachable", - "operator": "Exists", - "tolerationSeconds": 300 - }], - "volumes": [ - { - "name": "default-token-2nqlw", - "secret": { - "defaultMode": 420, - "secretName": "default-token-2nqlw" - } - }] - }, - "status": { - "conditions": [ - { - "lastTransitionTime": "2020-06-15T15:44:16Z", - "status": "True", - "type": "Initialized" - }, - { - "lastTransitionTime": "2020-06-15T15:44:46Z", - "status": "True", - "type": "Ready" - }, - { - "lastTransitionTime": "2020-06-15T15:44:46Z", - "status": "True", - "type": "ContainersReady" - }, - { - "lastTransitionTime": "2020-06-15T15:44:16Z", - "status": "True", - "type": "PodScheduled" - }], - "containerStatuses": [ - { - "containerID": "docker://2b7c2a93dfb48334aa549e29fdd38039ddd256eec43ba64c145fa4b75a1542f0", - "image": "docker.apache.xyz/platform-forms-service:0.15.0", - "imageID": - "docker-pullable://docker.apache.xyz/platform-forms-service@sha256:45fd19ccd99e218a7685c4cee5bc5b16aeae1cdb8e8773f9c066d4cfb22ee195", - "lastState": { - }, - "name": "platform-forms-service", - "ready": true, - "restartCount": 0, - "state": { - "running": { - "startedAt": "2020-06-15T15:44:21Z" - } - }, - "started": true - }], - "hostIP": "10.103.220.170", - "phase": "Running", - "podIP": "172.16.55.101", - "qosClass": "BestEffort", - "startTime": "2020-06-15T15:44:16Z", - "podIPs": [ - { - "ip": "172.16.55.101" - }] - } -} - diff --git a/log4j-kubernetes/src/test/resources/localPod.json b/log4j-kubernetes/src/test/resources/localPod.json deleted file mode 100644 index 3aeef4672496..000000000000 --- a/log4j-kubernetes/src/test/resources/localPod.json +++ /dev/null @@ -1,141 +0,0 @@ -{ - "apiVersion": "v1", - "kind": "Pod", - "metadata": { - "creationTimestamp": "2020-06-14T21:50:09Z", - "generateName": "sampleapp-584f99476d-", - "labels": { - "app": "sampleapp", - "pod-template-hash": "584f99476d" - }, - "name": "sampleapp-584f99476d-mnrp4", - "namespace": "default", - "ownerReferences": [ - { - "apiVersion": "apps/v1", - "kind": "ReplicaSet", - "blockOwnerDeletion": true, - "controller": true, - "name": "sampleapp-584f99476d", - "uid": "d68146d1-17c4-486e-aa8d-07d7d5d38b94" - }], - "resourceVersion": "1200430", - "selfLink": "/api/v1/namespaces/default/pods/sampleapp-584f99476d-mnrp4", - "uid": "9213879a-479c-42ce-856b-7e2666d21829" - }, - "spec": { - "containers": [ - { - "env": [ - { - "name": "JAVA_OPTS", - "value": "-Delastic.search.host=host.docker.internal" - }], - "image": "localhost:5000/sampleapp:latest", - "imagePullPolicy": "Always", - "name": "sampleapp", - "ports": [ - { - "containerPort": 8080, - "protocol": "TCP" - }, - { - "containerPort": 5005, - "protocol": "TCP" - }], - "resources": { - }, - "terminationMessagePath": "/dev/termination-log", - "terminationMessagePolicy": "File", - "volumeMounts": [ - { - "mountPath": "/var/run/secrets/kubernetes.io/serviceaccount", - "name": "default-token-jzq7d", - "readOnly": true - }] - }], - "dnsPolicy": "ClusterFirst", - "nodeName": "docker-desktop", - "priority": 0, - "restartPolicy": "Always", - "schedulerName": "default-scheduler", - "securityContext": { - }, - "serviceAccount": "default", - "serviceAccountName": "default", - "terminationGracePeriodSeconds": 30, - "tolerations": [ - { - "effect": "NoExecute", - "key": "node.kubernetes.io/not-ready", - "operator": "Exists", - "tolerationSeconds": 300 - }, - { - "effect": "NoExecute", - "key": "node.kubernetes.io/unreachable", - "operator": "Exists", - "tolerationSeconds": 300 - }], - "volumes": [ - { - "name": "default-token-jzq7d", - "secret": { - "defaultMode": 420, - "secretName": "default-token-jzq7d" - } - }], - "enableServiceLinks": true - }, - "status": { - "conditions": [ - { - "lastTransitionTime": "2020-06-14T21:50:09Z", - "status": "True", - "type": "Initialized" - }, - { - "lastTransitionTime": "2020-06-14T21:50:10Z", - "status": "True", - "type": "Ready" - }, - { - "lastTransitionTime": "2020-06-14T21:50:10Z", - "status": "True", - "type": "ContainersReady" - }, - { - "lastTransitionTime": "2020-06-14T21:50:09Z", - "status": "True", - "type": "PodScheduled" - }], - "containerStatuses": [ - { - "containerID": "docker://818b0098946c67e6ac56cb7c0934b7c2a9f50feb7244b422b2a7f566f7e5d0df", - "image": "sampleapp:latest", - "imageID": - "docker-pullable://localhost:5000/sampleapp@sha256:3cefb2db514db73c69854fee8abd072f27240519432d08aad177a57ee34b7d39", - "lastState": { - }, - "name": "sampleapp", - "ready": true, - "restartCount": 0, - "state": { - "running": { - "startedAt": "2020-06-14T21:50:10Z" - } - }, - "started": true - }], - "hostIP": "192.168.65.3", - "phase": "Running", - "podIP": "10.1.0.47", - "qosClass": "BestEffort", - "startTime": "2020-06-14T21:50:09Z", - "podIPs": [ - { - "ip": "10.1.0.47" - }] - } -} - diff --git a/log4j-parent/pom.xml b/log4j-parent/pom.xml index 859776257254..5b012bafbafe 100644 --- a/log4j-parent/pom.xml +++ b/log4j-parent/pom.xml @@ -131,7 +131,6 @@ 4.13.2 5.10.2 2.2.0 - 5.12.4 1.2.17 1.1.0 1.6.0 @@ -240,14 +239,6 @@ import - - io.fabric8 - kubernetes-client-bom - ${kubernetes-client.version} - pom - import - - org.mockito mockito-bom diff --git a/pom.xml b/pom.xml index adb5cf93ecd6..5d6290240e0e 100644 --- a/pom.xml +++ b/pom.xml @@ -253,7 +253,6 @@ log4j-jndi-test log4j-jpl log4j-jul - log4j-kubernetes log4j-layout-template-json log4j-layout-template-json-test log4j-mongodb4 @@ -469,12 +468,6 @@ ${project.version} - - org.apache.logging.log4j - log4j-kubernetes - ${project.version} - - org.apache.logging.log4j log4j-layout-template-json diff --git a/src/site/asciidoc/log4j-kubernetes.adoc b/src/site/asciidoc/log4j-kubernetes.adoc deleted file mode 100644 index 46db935b4e3b..000000000000 --- a/src/site/asciidoc/log4j-kubernetes.adoc +++ /dev/null @@ -1,201 +0,0 @@ -// vim: set syn=markdown : - -//// -Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -//// -= Log4j Kubernetes Support - -Log4j supports Kubernetes by providing a Lookup to retrieve container information. - -== Accessing Kubernetes - -The Log4j Kubernetes support requires access to the Docker REST interface. -In many cases the REST service can be accessed automatically. -If needed the Kubernetes client can be configured any of the standard Log4j configuration locations or via the Spring Boot configuration. -Note, however, that since Spring Boot causes logging to initialize 3 times and since the Spring environment is only available during the last Log4j initialization Spring properties will only be available to Log4j in the last initialization. - -== Lookup Attributes - -Log4j Kubernetes provides access to the following container attributes: - -* accountName - The service account name. -* clusterName - The name of the cluster the application is running in. -* containerId - The full id assigned to the container. -* containerName - The name assigned to the container. -* host - The name of the host. -* hostIp - The host's ip address. -* imageId - The id assigned to the image. -* imageName - The name assigned to the image. -* labels - All labels formatted in a list. -* labels.app - The application name. -* labels.podTemplateHash - The pod's template hash value. -* masterUrl - The url needed to access the API server. -* namespaceId - The id of the namespace the various kubernetes components are located within. -* namespaceName - The namespace the various kubernetes components are located within. -* podId - The pod's id number. -* podIp - The pod's ip address. -* podName - The name of the pod. - -Attributes may be accessed by adding - ----- -${k8s:containerId} ----- - -to the configuration. -Note that kubernetes variables are only resolved once during logging initialization so they shouldn't be referenced with more than one '$' character. - -== Configuration - -Much of the configuration needed to access the Kubernetes API server is provided automatically by Kubernetes. -However, it is not uncommon to need to provide the url required to access the Kubernetes API server or the namespace the application is assigned to. -The properties below may either be configured using the Log4j variable names and located by Log4j's normal property resolution mechansim or Log4j will resolve the spring properties when the application is running in Spring Boot and the Spring Environment has been created. -Note that Spring Boot initializes logging 3 times and only the last will have a Spring Environment present. - -[cols=",>,>,>"] -|=== -| Log4j Property Name | Spring Property Name | Default | Description - -| log4j2.kubernetes.client.apiVersion -| spring.cloud.kubernetes.client.apiVersion -| v1 -| Kubernetes API Version - -| log4j2.kubernetes.client.caCertData -| spring.cloud.kubernetes.client.caCertData -| -| Kubernetes API CACertData - -| log4j2.kubernetes.client.caCertFile -| spring.cloud.kubernetes.client.caCertFile -| -| Kubernetes API CACertFile - -| log4j2.kubernetes.client.clientCertData -| spring.cloud.kubernetes.client.clientCertData -| -| Kubernetes API ClientCertData - -| log4j2.kubernetes.client.clientCertFile -| spring.cloud.kubernetes.client.clientCertFile -| -| Kubernetes API ClientCertFile - -| log4j2.kubernetes.client.clientKeyAlgo -| spring.cloud.kubernetes.client.clientKeyAlgo -| RSA -| Kubernetes API ClientKeyAlgo - -| log4j2.kubernetes.client.clientKeyData -| spring.cloud.kubernetes.client.clientKeyData -| -| Kubernetes API ClientKeyData - -| log4j2.kubernetes.client.clientKeyFile -| spring.cloud.kubernetes.client.clientKeyFile -| -| Kubernetes API ClientKeyFile - -| log4j2.kubernetes.client.clientKeyPassPhrase -| spring.cloud.kubernetes.client.clientKeyPassphrase -| changeit -| Kubernetes API ClientKeyPassphrase - -| log4j2.kubernetes.client.connectionTimeout -| spring.cloud.kubernetes.client.connectionTimeout -| 10s -| Connection timeout - -| log4j2.kubernetes.client.httpProxy -| spring.cloud.kubernetes.client.http-proxy -| -| - -| log4j2.kubernetes.client.httpsProxy -| spring.cloud.kubernetes.client.https-proxy -| -| - -| log4j2.kubernetes.client.loggingInberval -| spring.cloud.kubernetes.client.loggingInterval -| 20s -| Logging interval - -| log4j2.kubernetes.client.masterUrl -| spring.cloud.kubernetes.client.masterUrl -| kubernetes.default.svc -| Kubernetes API Master Node URL - -| log4j2.kubernetes.client.namespacce -| spring.cloud.kubernetes.client.namespace -| default -| Kubernetes Namespace - -| log4j2.kubernetes.client.noProxy -| spring.cloud.kubernetes.client.noProxy -| -| - -| log4j2.kubernetes.client.password -| spring.cloud.kubernetes.client.password -| -| Kubernetes API Password - -| log4j2.kubernetes.client.proxyPassword -| spring.cloud.kubernetes.client.proxyPassword -| -| - -| log4j2.kubernetes.client.proxyUsername -| spring.cloud.kubernetes.client.proxyUsername -| -| - -| log4j2.kubernetes.client.requestTimeout -| spring.cloud.kubernetes.client.requestTimeout -| 10s -| Request timeout - -| log4j2.kubernetes.client.rollingTimeout -| spring.cloud.kubernetes.client.rollingTimeout -| 900s -| Rolling timeout - -| log4j2.kubernetes.client.trustCerts -| spring.cloud.kubernetes.client.trustCerts -| false -| Kubernetes API Trust Certificates - -| log4j2.kubernetes.client.username -| spring.cloud.kubernetes.client.username -| -| Kubernetes API Username - -| log4j2.kubernetes.client.watchReconnectInterval -| spring.cloud.kubernetes.client.watchReconnectInterval -| 1s -| Reconnect Interval - -| log4j2.kubernetes.client.watchReconnectLimit -| spring.cloud.kubernetes.client.watchReconnectLimit -| -1 -| Reconnect Interval limit retries -|=== - -== Requirements - -Log4j Kubernetes requires Log4j Core, Log4j API and a minimum of Java 8. -For more information, see link:runtime-dependencies.html[Runtime Dependencies]. diff --git a/src/site/asciidoc/manual/cloud.adoc b/src/site/asciidoc/manual/cloud.adoc index cd4e39fd5e94..a7e1f8a1c203 100644 --- a/src/site/asciidoc/manual/cloud.adoc +++ b/src/site/asciidoc/manual/cloud.adoc @@ -479,7 +479,7 @@ Applications within a Docker container that log using a Docker logging driver ca === Integration with Kubernetes -Applications managed by Kubernetes can bypass the Docker/Kubernetes logging infrastructure and log directly to either a sidecar forwarder or a logging aggragator cluster while still including all the kubernetes attributes by using the Log4j 2 Kubernetes Lookup. More information on Log4j's Kubernetes support may also be found at Log4j-Kubernetes. +Applications managed by Kubernetes can bypass the Docker/Kubernetes logging infrastructure and log directly to either a sidecar forwarder or a logging aggragator cluster while still including all the Kubernetes attributes by using the https://github.com/fabric8io/kubernetes-client/blob/main/doc/KubernetesLog4j.md[Kubernetes Log4j Lookup] maintained by the Fabric8 project. == Appender Performance diff --git a/src/site/asciidoc/manual/lookups.adoc b/src/site/asciidoc/manual/lookups.adoc index c5bbd72d13bb..a10e9aa4b921 100644 --- a/src/site/asciidoc/manual/lookups.adoc +++ b/src/site/asciidoc/manual/lookups.adoc @@ -310,33 +310,7 @@ https://docs.oracle.com/javase/8/docs/api/java/lang/management/RuntimeMXBean.htm [#KubernetesLookup] == Kubernetes Lookup -The KubernetesLookup can be used to lookup attributes from the Kubernetes environment for the container -the application is running in. - -Log4j Kubernetes provides access to the following container attributes: -[cols="1m,4a"] -|=== -|Attribute |Description -|accountName|The service account name -|clusterName|The name of the cluster the application is deployed in -|containerId|>The full id assigned to the container -|containerName|The name assigned to the container -|host|The name assigned to the host operating system -|hostIp|The host's ip address -|imageId|The id assigned to the container image -|imageName|The name assigned to the container image -|labels|All labels formatted in a list -|labels.app|The application name -|labels.podTemplateHash|The pod's template hash value -|masterUrl|The URL used to access the API server -|namespaceId|The id of the namespace the various kubernetes components are located within -|namespaceName|The namespace the various kubernetes components are located within -|podId|The pod's ip number -|podIp|The pod's ip address -|podName|The name of the pod -|=== - -This Lookup is subject to the configuration requirements listed at link:../log4j-kubernetes/index.html[Log4j Kubernetes Support] +For retrieving attributes using Fabric8's Kubernetes Client, see their https://github.com/fabric8io/kubernetes-client/blob/main/doc/KubernetesLog4j.md[Kubernetes Log4j Lookup]. [#Log4jConfigLookup] == Log4j Configuration Location Lookup