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 2022/11/29 01:16:06 UTC
[skywalking-java] branch main updated: Report the agent version to OAP (#397)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-java.git
The following commit(s) were added to refs/heads/main by this push:
new 51161ae6a5 Report the agent version to OAP (#397)
51161ae6a5 is described below
commit 51161ae6a5b8e266eef39162cc4e23440d36ab38
Author: Stephen Ni <ni...@users.noreply.github.com>
AuthorDate: Tue Nov 29 09:16:00 2022 +0800
Report the agent version to OAP (#397)
---
CHANGES.md | 1 +
apm-sniffer/apm-agent-core/pom.xml | 26 +++++++++
.../core/util/InstanceJsonPropertiesUtil.java | 2 +
.../skywalking/apm/agent/core/version/Version.java | 61 ++++++++++++++++++++++
pom.xml | 3 +-
test/e2e/case/expected/service-instance.yml | 2 +
tools/releasing/create_release.sh | 5 ++
7 files changed, 99 insertions(+), 1 deletion(-)
diff --git a/CHANGES.md b/CHANGES.md
index 76127d2d52..2d45e81d0b 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -13,6 +13,7 @@ Release Notes.
* Upgrade agent test tools
* [Breaking Change] Compatible with 3.x and 4.x RabbitMQ Client, rename `rabbitmq-5.x-plugin` to `rabbitmq-plugin`
* Polish JDBC plugins to make DBType accurate
+* Report the agent version to OAP as an instance attribute
#### Documentation
diff --git a/apm-sniffer/apm-agent-core/pom.xml b/apm-sniffer/apm-agent-core/pom.xml
index 65a2689120..07fc67f556 100644
--- a/apm-sniffer/apm-agent-core/pom.xml
+++ b/apm-sniffer/apm-agent-core/pom.xml
@@ -33,10 +33,12 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <generateGitPropertiesFilename>${project.build.outputDirectory}/skywalking-agent-version.properties</generateGitPropertiesFilename>
<guava.version>30.1.1-jre</guava.version>
<wiremock.version>2.6.0</wiremock.version>
<netty-tcnative-boringssl-static.version>2.0.7.Final</netty-tcnative-boringssl-static.version>
<os-maven-plugin.version>1.4.1.Final</os-maven-plugin.version>
+ <git-commit-id-plugin.version>4.9.10</git-commit-id-plugin.version>
<shade.com.google.source>com.google</shade.com.google.source>
<shade.com.google.target>${shade.package}.${shade.com.google.source}</shade.com.google.target>
<shade.io.grpc.source>io.grpc</shade.io.grpc.source>
@@ -171,6 +173,30 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>pl.project13.maven</groupId>
+ <artifactId>git-commit-id-plugin</artifactId>
+ <version>${git-commit-id-plugin.version}</version>
+ <executions>
+ <execution>
+ <id>get-the-git-infos</id>
+ <goals>
+ <goal>revision</goal>
+ </goals>
+ <phase>initialize</phase>
+ </execution>
+ </executions>
+ <configuration>
+ <failOnNoGitDirectory>false</failOnNoGitDirectory>
+ <generateGitPropertiesFile>true</generateGitPropertiesFile>
+ <generateGitPropertiesFilename>${generateGitPropertiesFilename}</generateGitPropertiesFilename>
+ <commitIdGenerationMode>full</commitIdGenerationMode>
+ <includeOnlyProperties>
+ <includeOnlyProperty>git.build.version</includeOnlyProperty>
+ <includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
+ </includeOnlyProperties>
+ </configuration>
+ </plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/util/InstanceJsonPropertiesUtil.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/util/InstanceJsonPropertiesUtil.java
index 8be5a794e4..0960caa596 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/util/InstanceJsonPropertiesUtil.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/util/InstanceJsonPropertiesUtil.java
@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.skywalking.apm.agent.core.conf.Config;
+import org.apache.skywalking.apm.agent.core.version.Version;
import org.apache.skywalking.apm.network.common.v3.KeyStringValuePair;
import org.apache.skywalking.apm.util.StringUtil;
@@ -45,6 +46,7 @@ public class InstanceJsonPropertiesUtil {
properties.add(KeyStringValuePair.newBuilder().setKey("namespace").setValue(Config.Agent.NAMESPACE).build());
properties.add(KeyStringValuePair.newBuilder().setKey("cluster").setValue(Config.Agent.CLUSTER).build());
+ properties.add(KeyStringValuePair.newBuilder().setKey("version").setValue(Version.CURRENT.toString()).build());
return properties;
}
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/version/Version.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/version/Version.java
new file mode 100644
index 0000000000..da2cf00c17
--- /dev/null
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/version/Version.java
@@ -0,0 +1,61 @@
+/*
+ * 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.apm.agent.core.version;
+
+import lombok.Getter;
+import org.apache.skywalking.apm.agent.core.logging.api.ILog;
+import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+@Getter
+public enum Version {
+ CURRENT;
+
+ private static final ILog LOGGER = LogManager.getLogger(Version.class);
+ private static final String VERSION_FILE_NAME = "skywalking-agent-version.properties";
+ private final String buildVersion;
+ private final String commitIdAbbrev;
+
+ Version() {
+ try {
+ InputStream inputStream = Version.class.getClassLoader().getResourceAsStream(VERSION_FILE_NAME);
+ if (inputStream == null) {
+ throw new IOException("Can't find " + VERSION_FILE_NAME);
+ }
+ Properties properties = new Properties();
+ properties.load(inputStream);
+ buildVersion = properties.getProperty("git.build.version");
+ commitIdAbbrev = properties.getProperty("git.commit.id.abbrev");
+ } catch (Exception e) {
+ throw new ExceptionInInitializerError(e);
+ }
+ }
+
+ static {
+ LOGGER.info("SkyWalking agent version: {}", CURRENT);
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s-%s", buildVersion, commitIdAbbrev);
+ }
+}
diff --git a/pom.xml b/pom.xml
index d802424a41..c58790f429 100755
--- a/pom.xml
+++ b/pom.xml
@@ -402,7 +402,8 @@
</resourceIncludes>
<resourceExcludes>
**/.asf.yaml,
- **/.github/**
+ **/.github/**,
+ **/skywalking-agent-version.properties
</resourceExcludes>
<excludes>
**/target/generated-test-sources/**,
diff --git a/test/e2e/case/expected/service-instance.yml b/test/e2e/case/expected/service-instance.yml
index 59b8e014b8..60c02ef761 100644
--- a/test/e2e/case/expected/service-instance.yml
+++ b/test/e2e/case/expected/service-instance.yml
@@ -36,6 +36,8 @@
value: '{{ notEmpty .value }}'
- name: ipv4s
value: {{ notEmpty .value }}
+ - name: version
+ value: {{ notEmpty .value }}
{{- end }}
language: JAVA
instanceuuid: {{ b64enc "e2e-service-provider" }}.1_{{ b64enc "provider1" }}
diff --git a/tools/releasing/create_release.sh b/tools/releasing/create_release.sh
index ee78728de8..98cedccc01 100755
--- a/tools/releasing/create_release.sh
+++ b/tools/releasing/create_release.sh
@@ -59,6 +59,11 @@ git checkout ${TAG_NAME}
git submodule init
git submodule update
+# Generate a static skywalking-agent-version.properties and override the template when releasing source tar
+# because after that there is no Git information anymore.
+./mvnw -q -pl apm-sniffer/apm-agent-core initialize \
+ -DgenerateGitPropertiesFilename="$(pwd)/apm-sniffer/apm-agent-core/src/main/resources/skywalking-agent-version.properties"
+
cd ..
# Build source code tar
tar czf ${PRODUCT_NAME}-src.tgz \