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 @@ UTF-8 + ${project.build.outputDirectory}/skywalking-agent-version.properties 30.1.1-jre 2.6.0 2.0.7.Final 1.4.1.Final + 4.9.10 com.google ${shade.package}.${shade.com.google.source} io.grpc @@ -171,6 +173,30 @@ + + pl.project13.maven + git-commit-id-plugin + ${git-commit-id-plugin.version} + + + get-the-git-infos + + revision + + initialize + + + + false + true + ${generateGitPropertiesFilename} + full + + git.build.version + ^git.commit.id.(abbrev|full)$ + + + maven-shade-plugin 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.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 static List parseProperties() { 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 @@ **/.asf.yaml, - **/.github/** + **/.github/**, + **/skywalking-agent-version.properties **/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 \