This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/main by this push:
new ecea586a3 feat(operator): remove maven structured logging
ecea586a3 is described below
commit ecea586a3e92543116a6b0a5357e35b5ba071ecc
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Wed Jan 22 18:28:36 2025 +0100
feat(operator): remove maven structured logging
We just need to capture the log trace, no need to make it more complicated
than that.
---
.gitignore | 2 -
build/Dockerfile | 12 +--
e2e/support/test_support.go | 1 -
java/.mvn/wrapper/maven-wrapper.jar | Bin 59925 -> 0 bytes
java/.mvn/wrapper/maven-wrapper.properties | 18 ----
java/maven-logging/pom.xml | 116 ----------------------
java/maven-logging/src/main/resources/logback.xml | 67 -------------
pkg/util/maven/maven_log.go | 75 ++++++--------
pkg/util/maven/maven_log_test.go | 21 +++-
script/Makefile | 10 +-
script/maven_overlay.sh | 35 -------
11 files changed, 54 insertions(+), 303 deletions(-)
diff --git a/.gitignore b/.gitignore
index 7e62d4fbd..f9274f44a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -44,9 +44,7 @@ build/_offline
build/camel-k-runtime-*-maven-offline.tar.gz
build/_test
build/_maven_output
-build/_maven_overlay
build/_kamelets
-build/_maven_overlay/
build/maven/target/
build/maven
build/m2
diff --git a/build/Dockerfile b/build/Dockerfile
index f1523076c..183fcc34a 100644
--- a/build/Dockerfile
+++ b/build/Dockerfile
@@ -22,15 +22,12 @@ ARG MAVEN_HOME="/usr/share/maven"
ARG
MAVEN_DIST_URL="https://archive.apache.org/dist/maven/maven-3/${MAVEN_DEFAULT_VERSION}/binaries/apache-maven-${MAVEN_DEFAULT_VERSION}-bin.zip"
ARG MVNW_DIR="/usr/share/maven/mvnw/"
ARG MVN_REPO="/etc/maven/m2"
-ARG MAVEN_OPTS=""
USER 0
# Maven configuration
RUN mkdir -p ${MAVEN_HOME}
RUN mkdir -p ${MVN_REPO}
-COPY build/_maven_overlay/ /usr/share/maven/lib/
-ADD build/_maven_overlay/logback.xml /usr/share/maven/conf/
# Prepare the maven wrapper required in the build Pod strategy
COPY build/mvnw/mvnw.tar ${MVNW_DIR}
@@ -39,13 +36,8 @@ RUN tar -xC ${MVNW_DIR} -f ${MVNW_DIR}mvnw.tar \
&& sed -i "s;distributionUrl=.*;distributionUrl=${MAVEN_DIST_URL};"
${MVNW_DIR}.mvn/wrapper/maven-wrapper.properties
# Used by mvnw to download maven dist into it
ENV MAVEN_USER_HOME="${MAVEN_HOME}"
-# Install a default mvnw distribution at build time and prepare the config for
formatting log
-RUN ${MVNW_DIR}/mvnw --version | grep "Maven home:" | sed 's/Maven home: //'
>> ${MVNW_DIR}default \
- && cp -r /usr/share/maven/lib/. $(cat ${MVNW_DIR}default)/lib \
- && rm $(cat ${MVNW_DIR}default)/lib/maven-slf4j-provider* \
- && rm $(cat ${MVNW_DIR}default)/lib/slf4j-api-1.*
-
-ENV MAVEN_OPTS="${MAVEN_OPTS}
-Dlogback.configurationFile=${MAVEN_HOME}/conf/logback.xml"
+# Install a default mvnw distribution at build time
+RUN ${MVNW_DIR}/mvnw --version
ADD build/_maven_output ${MVN_REPO}
# Fix https://github.com/moby/moby/issues/37965
diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go
index e314b378d..8df8f8f68 100644
--- a/e2e/support/test_support.go
+++ b/e2e/support/test_support.go
@@ -496,7 +496,6 @@ func Logs(t *testing.T, ctx context.Context, ns, podName
string, options corev1.
}
func StructuredLogs(t *testing.T, ctx context.Context, ns, podName string,
options *corev1.PodLogOptions, ignoreParseErrors bool) ([]util.LogEntry, error)
{
-
stream, err := TestClient(t).CoreV1().Pods(ns).GetLogs(podName,
options).Stream(ctx)
if err != nil {
msg := "Error while reading container logs"
diff --git a/java/.mvn/wrapper/maven-wrapper.jar
b/java/.mvn/wrapper/maven-wrapper.jar
deleted file mode 100644
index bf82ff01c..000000000
Binary files a/java/.mvn/wrapper/maven-wrapper.jar and /dev/null differ
diff --git a/java/.mvn/wrapper/maven-wrapper.properties
b/java/.mvn/wrapper/maven-wrapper.properties
deleted file mode 100644
index 84b111fb2..000000000
--- a/java/.mvn/wrapper/maven-wrapper.properties
+++ /dev/null
@@ -1,18 +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
-#
-# https://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.
-distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
-wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
diff --git a/java/maven-logging/pom.xml b/java/maven-logging/pom.xml
deleted file mode 100644
index 2b0a3a2d9..000000000
--- a/java/maven-logging/pom.xml
+++ /dev/null
@@ -1,116 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- 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.
-
--->
-<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.apache.camel.k</groupId>
- <artifactId>camel-k-maven-logging</artifactId>
- <version>2.6.0-SNAPSHOT</version>
- <description>Set of dependencies used for structural logging of Maven
output</description>
- <packaging>pom</packaging>
-
- <properties>
- <logstash-logback-encoder.version>7.4</logstash-logback-encoder.version>
- <maven-dependency-plugin-version>3.5.0</maven-dependency-plugin-version>
- <slf4j.version>2.0.7</slf4j.version>
- <logback.version>1.5.13</logback.version>
- <jackson.version>2.15.2</jackson.version>
- </properties>
-
- <build>
- <defaultGoal>generate-resources</defaultGoal>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <version>${maven-dependency-plugin-version}</version>
- <executions>
- <execution>
- <id>default-cli</id>
- <phase>generate-resources</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <configuration>
- <excludeTransitive>true</excludeTransitive>
-
<outputDirectory>${project.build.directory}/maven-overlay</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <!-- structural logging: we only need this dependencies to be part of
the overlay package, reason why are marked as provided -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>${slf4j.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-core</artifactId>
- <version>${logback.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <version>${logback.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>net.logstash.logback</groupId>
- <artifactId>logstash-logback-encoder</artifactId>
- <version>${logstash-logback-encoder.version}</version>
- <scope>provided</scope>
- <exclusions>
- <exclusion>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-annotations</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-core</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-annotations</artifactId>
- <version>${jackson.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-core</artifactId>
- <version>${jackson.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>${jackson.version}</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-</project>
diff --git a/java/maven-logging/src/main/resources/logback.xml
b/java/maven-logging/src/main/resources/logback.xml
deleted file mode 100644
index f752b5011..000000000
--- a/java/maven-logging/src/main/resources/logback.xml
+++ /dev/null
@@ -1,67 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- 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.
-
--->
-<configuration>
- <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
- <!--
- This configuration tries to output the Maven build log in a way that
is as close as possible the native k8s
- log output format.
- -->
- <encoder
class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
- <providers>
- <logLevel>
- <fieldName>level</fieldName>
- </logLevel>
- <timestamp>
- <fieldName>ts</fieldName>
- <timeZone>UTC</timeZone>
- </timestamp>
- <loggerName>
- <fieldName>logger</fieldName>
- </loggerName>
- <message>
- <fieldName>msg</fieldName>
- </message>
- <callerData>
- <classFieldName>class</classFieldName>
- </callerData>
- <threadName>
- <fieldName>thread</fieldName>
- </threadName>
- <mdc/>
- <arguments>
-
<includeNonStructuredArguments>false</includeNonStructuredArguments>
- </arguments>
- <logstashMarkers/>
- <stackTrace>
- <fieldName>stack</fieldName>
- <throwableConverter
class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
- <maxLength>4096</maxLength>
- <rootCauseFirst>false</rootCauseFirst>
- </throwableConverter>
- </stackTrace>
- </providers>
- </encoder>
- </appender>
-
- <root level="INFO">
- <appender-ref ref="CONSOLE"/>
- </root>
-
-</configuration>
diff --git a/pkg/util/maven/maven_log.go b/pkg/util/maven/maven_log.go
index a9d58d2fc..8204c247a 100644
--- a/pkg/util/maven/maven_log.go
+++ b/pkg/util/maven/maven_log.go
@@ -18,81 +18,68 @@ limitations under the License.
package maven
import (
- "encoding/json"
- "strings"
+ "regexp"
"github.com/apache/camel-k/v2/pkg/util/log"
)
type mavenLog struct {
- Level string `json:"level"`
- TS string `json:"ts"`
- Logger string `json:"logger"`
- Msg string `json:"msg"`
- Class string `json:"class"`
- CallerMethodName string `json:"caller_method_name"`
- CallerFileName string `json:"caller_file_name"`
- CallerLineNumber int `json:"caller_line_number"`
- Thread string `json:"thread"`
+ Level string `json:"level"`
+ Msg string `json:"msg"`
}
const (
- TRACE = "TRACE"
- DEBUG = "DEBUG"
- INFO = "INFO"
- WARN = "WARN"
- ERROR = "ERROR"
- FATAL = "FATAL"
+ TRACE = "TRACE"
+ DEBUG = "DEBUG"
+ INFO = "INFO"
+ WARNING = "WARNING"
+ ERROR = "ERROR"
+ FATAL = "FATAL"
)
var mavenLogger = log.WithName("maven.build")
+var mavenLoggingFormat =
regexp.MustCompile(`^\[(TRACE|DEBUG|INFO|WARNING|ERROR|FATAL)\] (.*)$`)
+// LogHandler is in charge to log the text passed and, if the trace is an
error, to return the message to the caller.
func LogHandler(s string) string {
- l, parseError := parseLog(s)
- if parseError == nil {
- normalizeLog(l)
- } else {
- // Why we are ignoring the parsing errors here: there are a few
scenarios where this would likely occur.
- // For example, if something outside of Maven outputs something
(i.e.: the JDK, a misbehaved plugin,
- // etc). The build may still have succeeded, though.
- nonNormalizedLog(s)
- }
+ l := parseLog(s)
+ normalizeLog(l)
- // Return the error message according to maven log
- if strings.HasPrefix(s, "[ERROR]") {
- return s
+ if l.Level == ERROR {
+ return l.Msg
}
return ""
}
-func parseLog(line string) (mavenLog, error) {
+func parseLog(line string) mavenLog {
var l mavenLog
- err := json.Unmarshal([]byte(line), &l)
- if err != nil {
- return l, err
+ matches := mavenLoggingFormat.FindAllStringSubmatch(line, -1)
+ if len(matches) == 0 || len(matches[0]) != 3 {
+ // If this is happening, then, we have a problem with parsing
the maven output
+ // however we are printing the output in its plain format
+ l = mavenLog{
+ Level: INFO,
+ Msg: line,
+ }
+ } else {
+ l = mavenLog{
+ Level: matches[0][1],
+ Msg: matches[0][2],
+ }
}
- return l, nil
+ return l
}
func normalizeLog(mavenLog mavenLog) {
switch mavenLog.Level {
case DEBUG, TRACE:
mavenLogger.Debug(mavenLog.Msg)
- case INFO, WARN:
+ case INFO, WARNING:
mavenLogger.Info(mavenLog.Msg)
case ERROR, FATAL:
mavenLogger.Error(nil, mavenLog.Msg)
}
}
-
-func nonNormalizedLog(rawLog string) {
- // Distinguish an error message from the rest
- if strings.HasPrefix(rawLog, "[ERROR]") {
- mavenLogger.Error(nil, rawLog)
- } else {
- mavenLogger.Info(rawLog)
- }
-}
diff --git a/pkg/util/maven/maven_log_test.go b/pkg/util/maven/maven_log_test.go
index 46fadfdb0..dbd3307d7 100644
--- a/pkg/util/maven/maven_log_test.go
+++ b/pkg/util/maven/maven_log_test.go
@@ -24,6 +24,7 @@ import (
"testing"
"github.com/apache/camel-k/v2/pkg/util"
+ "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -37,5 +38,23 @@ func TestRunAndLogErrorMvn(t *testing.T) {
err := util.RunAndLog(context.Background(), cmd, LogHandler, LogHandler)
require.Error(t, err)
- require.ErrorContains(t, err, "[ERROR] The goal you specified requires
a project to execute but there is no POM in this directory")
+ require.ErrorContains(t, err, "The goal you specified requires a
project to execute but there is no POM in this directory")
+}
+
+func TestParseLog(t *testing.T) {
+ mavenLogLine := parseLog("[INFO] this is an info log trace")
+ assert.Equal(t, INFO, mavenLogLine.Level)
+ assert.Equal(t, "this is an info log trace", mavenLogLine.Msg)
+}
+
+func TestParseErrorLog(t *testing.T) {
+ mavenLogLine := parseLog("[ERROR] this is an error log trace")
+ assert.Equal(t, ERROR, mavenLogLine.Level)
+ assert.Equal(t, "this is an error log trace", mavenLogLine.Msg)
+}
+
+func TestParseLogCannotTrace(t *testing.T) {
+ mavenLogLine := parseLog("[FAILING] this is a failing log trace")
+ assert.Equal(t, INFO, mavenLogLine.Level)
+ assert.Equal(t, "[FAILING] this is a failing log trace",
mavenLogLine.Msg)
}
diff --git a/script/Makefile b/script/Makefile
index 7c1cc637f..83b44c734 100644
--- a/script/Makefile
+++ b/script/Makefile
@@ -377,7 +377,6 @@ clean:
rm -f *.test
rm -rf $(LOCALBIN)
rm -rf build/_maven_output
- rm -rf build/_maven_overlay
rm -rf build/_output
rm -rf camel-k-client-*.tar.gz
rm -rf camel-k-examples-*.tar.gz
@@ -430,13 +429,6 @@ dir-licenses:
check-licenses:
./script/check_licenses.sh
-# The below are dependencies needed for maven structured logs. We must bundle
into the final container image.
-maven-overlay:
- @echo "####### Preparing maven dependencies bundle..."
- rm -rf build/_maven_overlay
- mkdir -p build/_maven_overlay
- ./script/maven_overlay.sh build/_maven_overlay
-
TARGET_STAGE := base
ifeq ($(DEBUG_MODE),true)
TARGET_STAGE := debug
@@ -445,7 +437,7 @@ endif
DOCKER_TAG := $(CUSTOM_IMAGE):$(CUSTOM_VERSION)-$(IMAGE_ARCH)
-images: build maven-overlay image-build build-kamel-platform
+images: build image-build build-kamel-platform
image-build:
ifneq (,$(findstring SNAPSHOT,$(DEFAULT_RUNTIME_VERSION)))
diff --git a/script/maven_overlay.sh b/script/maven_overlay.sh
deleted file mode 100755
index 3c02bcbac..000000000
--- a/script/maven_overlay.sh
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/bin/bash
-
-# 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.
-
-location=$(dirname $0)
-rootdir=$(realpath ${location}/../)
-
-if [ "$#" -lt 1 ]; then
- echo "usage: $0 <output directory>"
- exit 1
-fi
-
-options=""
-if [ "$CI" = "true" ]; then
- options="--batch-mode"
-fi
-
-output_dir=$1
-
-mvn -q $options -f java/maven-logging/pom.xml clean package
-cp java/maven-logging/target/maven-overlay/*.jar ${output_dir}
-cp java/maven-logging/src/main/resources/logback.xml ${output_dir}