You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2021/10/26 07:05:46 UTC
[skywalking] branch master updated: Add a GraphQL query to get OAP
version, display OAP version in startup message and error logs (#8004)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new a5685cb Add a GraphQL query to get OAP version, display OAP version in startup message and error logs (#8004)
a5685cb is described below
commit a5685cb149d8f3f5187238bc828c95e2d9fd400e
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Tue Oct 26 15:05:37 2021 +0800
Add a GraphQL query to get OAP version, display OAP version in startup message and error logs (#8004)
---
.gitignore | 4 ++
.licenserc.yaml | 1 +
CHANGES.md | 1 +
apm-protocol/apm-network/src/main/proto | 2 +-
docker/oap/log4j2.xml | 6 ++-
.../oap/server/core/version/Version.java | 57 ++++++++++++++++++++++
.../server/core/version/VersionLogConverter.java | 42 ++++++++++++++++
.../oap/query/graphql/resolver/Query.java | 4 +-
oap-server/server-starter/pom.xml | 50 ++++++++++++++++++-
.../oap/server/starter/OAPServerBootstrap.java | 3 ++
.../server-starter/src/main/resources/log4j2.xml | 6 ++-
tools/releasing/create_source_release.sh | 5 ++
12 files changed, 176 insertions(+), 5 deletions(-)
diff --git a/.gitignore b/.gitignore
index c583d0b..492dd61 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,3 +18,7 @@ OALLexer.tokens
.checkstyle
.externalToolBuilders
oap-server/oal-grammar/**/gen/
+
+# This serves as a template but will ONLY be updated when building a source release tar,
+# so we don't track future updates of this file.
+oap-server/server-starter/src/main/resources/version.properties
diff --git a/.licenserc.yaml b/.licenserc.yaml
index f94085e..7b1bc66 100644
--- a/.licenserc.yaml
+++ b/.licenserc.yaml
@@ -61,5 +61,6 @@ header:
- '**/src/main/proto/protoc-gen-swagger/**'
- '**/src/main/proto/validate/validate.proto'
- '**/src/main/proto/opencensus/**'
+ - 'oap-server/server-starter/src/main/resources/version.properties'
comment: on-failure
diff --git a/CHANGES.md b/CHANGES.md
index 9bc7390..60bd3e7 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -52,6 +52,7 @@ Release Notes.
* Add `getProfileTaskLogs` to profile query protocol.
* Set `SW_KAFKA_FETCHER_ENABLE_NATIVE_PROTO_LOG`, `SW_KAFKA_FETCHER_ENABLE_NATIVE_JSON_LOG` default `true`.
* Fix unexpected deleting due to TTL mechanism bug for H2, MySQL, TiDB and PostgreSQL.
+* Add a GraphQL query to get OAP version, display OAP version in startup message and error logs.
#### UI
diff --git a/apm-protocol/apm-network/src/main/proto b/apm-protocol/apm-network/src/main/proto
index e6742be..21492e4 160000
--- a/apm-protocol/apm-network/src/main/proto
+++ b/apm-protocol/apm-network/src/main/proto
@@ -1 +1 @@
-Subproject commit e6742be211302cf7eb93db83bdf1da2a8e600d17
+Subproject commit 21492e496b797567d0e127f4510509baf73e10fd
diff --git a/docker/oap/log4j2.xml b/docker/oap/log4j2.xml
index eab9c37..6152fc7 100644
--- a/docker/oap/log4j2.xml
+++ b/docker/oap/log4j2.xml
@@ -20,7 +20,11 @@
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
- <PatternLayout charset="UTF-8" pattern="%d %c %L [%t] %-5p %x - %m%n"/>
+ <PatternLayout>
+ <LevelPatternSelector defaultPattern="%d %c %L [%t] %-5p %x - %m%n">
+ <PatternMatch key="ERROR" pattern="%d %c %L [%t] %-5p %x - [%swversion] %m%n" />
+ </LevelPatternSelector>
+ </PatternLayout>
</Console>
</Appenders>
<Loggers>
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/version/Version.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/version/Version.java
new file mode 100644
index 0000000..0acb44e
--- /dev/null
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/version/Version.java
@@ -0,0 +1,57 @@
+/*
+ * 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.skywalking.oap.server.core.version;
+
+import java.io.IOException;
+import java.util.Properties;
+import lombok.Getter;
+import org.apache.logging.log4j.util.Strings;
+
+@Getter
+public enum Version {
+ CURRENT;
+
+ private final String buildVersion;
+ private final String buildTime;
+ private final String commitId;
+
+ private final Properties properties = new Properties();
+
+ Version() {
+ try {
+ properties.load(Version.class.getClassLoader()
+ .getResourceAsStream("version.properties"));
+ buildVersion = properties.getProperty("git.build.version");
+ buildTime = properties.getProperty("git.build.time");
+ commitId = properties.getProperty("git.commit.id");
+ } catch (IOException e) {
+ throw new ExceptionInInitializerError(e);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return String.format(
+ "%s-%s (%s)",
+ buildVersion,
+ Strings.left(commitId, 7),
+ buildTime
+ );
+ }
+}
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/version/VersionLogConverter.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/version/VersionLogConverter.java
new file mode 100644
index 0000000..d2872f8
--- /dev/null
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/version/VersionLogConverter.java
@@ -0,0 +1,42 @@
+/*
+ * 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.skywalking.oap.server.core.version;
+
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.pattern.ConverterKeys;
+import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
+import org.apache.logging.log4j.core.pattern.PatternConverter;
+
+@Plugin(name = "VersionLogConverter", category = PatternConverter.CATEGORY)
+@ConverterKeys({"swversion"})
+public class VersionLogConverter extends LogEventPatternConverter {
+ protected VersionLogConverter(String name) {
+ super(name, null);
+ }
+
+ public static VersionLogConverter newInstance(String[] options) {
+ return new VersionLogConverter("swversion");
+ }
+
+ @Override
+ public void format(LogEvent event, StringBuilder toAppendTo) {
+ toAppendTo.append(Version.CURRENT);
+ }
+}
diff --git a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/Query.java b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/Query.java
index 947e303..737d164 100644
--- a/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/Query.java
+++ b/oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/Query.java
@@ -19,10 +19,12 @@
package org.apache.skywalking.oap.query.graphql.resolver;
import com.coxautodev.graphql.tools.GraphQLQueryResolver;
+import org.apache.skywalking.oap.server.core.version.Version;
/**
* Root Query Resolver.
*/
public class Query implements GraphQLQueryResolver {
- private String version = "8.0";
+ @SuppressWarnings("unused") // Used in GraphQL query
+ private final String version = Version.CURRENT.toString();
}
diff --git a/oap-server/server-starter/pom.xml b/oap-server/server-starter/pom.xml
index 00300a8..3468f83 100644
--- a/oap-server/server-starter/pom.xml
+++ b/oap-server/server-starter/pom.xml
@@ -17,7 +17,8 @@
~
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>oap-server</artifactId>
<groupId>org.apache.skywalking</groupId>
@@ -27,6 +28,10 @@
<artifactId>server-starter</artifactId>
+ <properties>
+ <generateGitPropertiesFilename>${project.build.outputDirectory}/version.properties</generateGitPropertiesFilename>
+ </properties>
+
<dependencies>
<dependency>
<groupId>org.apache.skywalking</groupId>
@@ -260,6 +265,22 @@
<build>
<finalName>skywalking-oap</finalName>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>version.properties</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>false</filtering>
+ <excludes>
+ <exclude>version.properties</exclude>
+ </excludes>
+ </resource>
+ </resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
@@ -320,6 +341,33 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>pl.project13.maven</groupId>
+ <artifactId>git-commit-id-plugin</artifactId>
+ <version>4.9.10</version>
+ <executions>
+ <execution>
+ <id>get-the-git-information</id>
+ <goals>
+ <goal>revision</goal>
+ </goals>
+ <phase>initialize</phase>
+ </execution>
+ </executions>
+ <configuration>
+ <verbose>false</verbose>
+ <generateGitPropertiesFile>true</generateGitPropertiesFile>
+ <generateGitPropertiesFilename>${generateGitPropertiesFilename}</generateGitPropertiesFilename>
+ <dateFormatTimeZone>UTC</dateFormatTimeZone>
+ <dateFormat>yyyyMMddHHmmss</dateFormat>
+ <failOnNoGitDirectory>false</failOnNoGitDirectory>
+ <includeOnlyProperties>
+ <includeOnlyProperty>^git.build.version$</includeOnlyProperty>
+ <includeOnlyProperty>^git.commit.id$</includeOnlyProperty>
+ <includeOnlyProperty>^git.build.time$</includeOnlyProperty>
+ </includeOnlyProperties>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
diff --git a/oap-server/server-starter/src/main/java/org/apache/skywalking/oap/server/starter/OAPServerBootstrap.java b/oap-server/server-starter/src/main/java/org/apache/skywalking/oap/server/starter/OAPServerBootstrap.java
index 3e893e4..2b8f4b8 100644
--- a/oap-server/server-starter/src/main/java/org/apache/skywalking/oap/server/starter/OAPServerBootstrap.java
+++ b/oap-server/server-starter/src/main/java/org/apache/skywalking/oap/server/starter/OAPServerBootstrap.java
@@ -20,6 +20,7 @@ package org.apache.skywalking.oap.server.starter;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.oap.server.core.RunningMode;
+import org.apache.skywalking.oap.server.core.version.Version;
import org.apache.skywalking.oap.server.library.module.ApplicationConfiguration;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.starter.config.ApplicationConfigLoader;
@@ -49,6 +50,8 @@ public class OAPServerBootstrap {
// Set uptime to second
.setValue(System.currentTimeMillis() / 1000d);
+ log.info("Version of OAP: {}", Version.CURRENT);
+
if (RunningMode.isInitMode()) {
log.info("OAP starts up in init mode successfully, exit now...");
System.exit(0);
diff --git a/oap-server/server-starter/src/main/resources/log4j2.xml b/oap-server/server-starter/src/main/resources/log4j2.xml
index a420c6e..99f5604 100644
--- a/oap-server/server-starter/src/main/resources/log4j2.xml
+++ b/oap-server/server-starter/src/main/resources/log4j2.xml
@@ -20,7 +20,11 @@
<Configuration status="DEBUG">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
- <PatternLayout charset="UTF-8" pattern="%d %c %L [%t] %-5p %x - %m%n"/>
+ <PatternLayout>
+ <LevelPatternSelector defaultPattern="%d %c %L [%t] %-5p %x - %m%n">
+ <PatternMatch key="ERROR" pattern="%d %c %L [%t] %-5p %x - [%swversion] %m%n" />
+ </LevelPatternSelector>
+ </PatternLayout>
</Console>
</Appenders>
<Loggers>
diff --git a/tools/releasing/create_source_release.sh b/tools/releasing/create_source_release.sh
index 16d1bb3..b5918a9 100755
--- a/tools/releasing/create_source_release.sh
+++ b/tools/releasing/create_source_release.sh
@@ -58,6 +58,11 @@ git checkout ${TAG_NAME}
git submodule init
git submodule update
+# Generate a static version.properties and override the template when releasing source tar
+# because after that there is no Git information anymore.
+./mvnw -q -pl oap-server/server-starter initialize \
+ -DgenerateGitPropertiesFilename="$(pwd)/oap-server/server-starter/src/main/resources/version.properties"
+
cd ..
tar czf ${PRODUCT_NAME}-src.tgz \