Skip to content

Commit 51161ae

Browse files
authored
Report the agent version to OAP (#397)
1 parent 6b33d05 commit 51161ae

7 files changed

Lines changed: 99 additions & 1 deletion

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Release Notes.
1313
* Upgrade agent test tools
1414
* [Breaking Change] Compatible with 3.x and 4.x RabbitMQ Client, rename `rabbitmq-5.x-plugin` to `rabbitmq-plugin`
1515
* Polish JDBC plugins to make DBType accurate
16+
* Report the agent version to OAP as an instance attribute
1617

1718
#### Documentation
1819

apm-sniffer/apm-agent-core/pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333

3434
<properties>
3535
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
36+
<generateGitPropertiesFilename>${project.build.outputDirectory}/skywalking-agent-version.properties</generateGitPropertiesFilename>
3637
<guava.version>30.1.1-jre</guava.version>
3738
<wiremock.version>2.6.0</wiremock.version>
3839
<netty-tcnative-boringssl-static.version>2.0.7.Final</netty-tcnative-boringssl-static.version>
3940
<os-maven-plugin.version>1.4.1.Final</os-maven-plugin.version>
41+
<git-commit-id-plugin.version>4.9.10</git-commit-id-plugin.version>
4042
<shade.com.google.source>com.google</shade.com.google.source>
4143
<shade.com.google.target>${shade.package}.${shade.com.google.source}</shade.com.google.target>
4244
<shade.io.grpc.source>io.grpc</shade.io.grpc.source>
@@ -171,6 +173,30 @@
171173
</execution>
172174
</executions>
173175
</plugin>
176+
<plugin>
177+
<groupId>pl.project13.maven</groupId>
178+
<artifactId>git-commit-id-plugin</artifactId>
179+
<version>${git-commit-id-plugin.version}</version>
180+
<executions>
181+
<execution>
182+
<id>get-the-git-infos</id>
183+
<goals>
184+
<goal>revision</goal>
185+
</goals>
186+
<phase>initialize</phase>
187+
</execution>
188+
</executions>
189+
<configuration>
190+
<failOnNoGitDirectory>false</failOnNoGitDirectory>
191+
<generateGitPropertiesFile>true</generateGitPropertiesFile>
192+
<generateGitPropertiesFilename>${generateGitPropertiesFilename}</generateGitPropertiesFilename>
193+
<commitIdGenerationMode>full</commitIdGenerationMode>
194+
<includeOnlyProperties>
195+
<includeOnlyProperty>git.build.version</includeOnlyProperty>
196+
<includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
197+
</includeOnlyProperties>
198+
</configuration>
199+
</plugin>
174200
<plugin>
175201
<artifactId>maven-shade-plugin</artifactId>
176202
<executions>

apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/util/InstanceJsonPropertiesUtil.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.List;
2525
import java.util.Map;
2626
import org.apache.skywalking.apm.agent.core.conf.Config;
27+
import org.apache.skywalking.apm.agent.core.version.Version;
2728
import org.apache.skywalking.apm.network.common.v3.KeyStringValuePair;
2829
import org.apache.skywalking.apm.util.StringUtil;
2930

@@ -45,6 +46,7 @@ public static List<KeyStringValuePair> parseProperties() {
4546

4647
properties.add(KeyStringValuePair.newBuilder().setKey("namespace").setValue(Config.Agent.NAMESPACE).build());
4748
properties.add(KeyStringValuePair.newBuilder().setKey("cluster").setValue(Config.Agent.CLUSTER).build());
49+
properties.add(KeyStringValuePair.newBuilder().setKey("version").setValue(Version.CURRENT.toString()).build());
4850

4951
return properties;
5052
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.skywalking.apm.agent.core.version;
20+
21+
import lombok.Getter;
22+
import org.apache.skywalking.apm.agent.core.logging.api.ILog;
23+
import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
24+
25+
import java.io.IOException;
26+
import java.io.InputStream;
27+
import java.util.Properties;
28+
29+
@Getter
30+
public enum Version {
31+
CURRENT;
32+
33+
private static final ILog LOGGER = LogManager.getLogger(Version.class);
34+
private static final String VERSION_FILE_NAME = "skywalking-agent-version.properties";
35+
private final String buildVersion;
36+
private final String commitIdAbbrev;
37+
38+
Version() {
39+
try {
40+
InputStream inputStream = Version.class.getClassLoader().getResourceAsStream(VERSION_FILE_NAME);
41+
if (inputStream == null) {
42+
throw new IOException("Can't find " + VERSION_FILE_NAME);
43+
}
44+
Properties properties = new Properties();
45+
properties.load(inputStream);
46+
buildVersion = properties.getProperty("git.build.version");
47+
commitIdAbbrev = properties.getProperty("git.commit.id.abbrev");
48+
} catch (Exception e) {
49+
throw new ExceptionInInitializerError(e);
50+
}
51+
}
52+
53+
static {
54+
LOGGER.info("SkyWalking agent version: {}", CURRENT);
55+
}
56+
57+
@Override
58+
public String toString() {
59+
return String.format("%s-%s", buildVersion, commitIdAbbrev);
60+
}
61+
}

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@
402402
</resourceIncludes>
403403
<resourceExcludes>
404404
**/.asf.yaml,
405-
**/.github/**
405+
**/.github/**,
406+
**/skywalking-agent-version.properties
406407
</resourceExcludes>
407408
<excludes>
408409
**/target/generated-test-sources/**,

test/e2e/case/expected/service-instance.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
value: '{{ notEmpty .value }}'
3737
- name: ipv4s
3838
value: {{ notEmpty .value }}
39+
- name: version
40+
value: {{ notEmpty .value }}
3941
{{- end }}
4042
language: JAVA
4143
instanceuuid: {{ b64enc "e2e-service-provider" }}.1_{{ b64enc "provider1" }}

tools/releasing/create_release.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ git checkout ${TAG_NAME}
5959
git submodule init
6060
git submodule update
6161

62+
# Generate a static skywalking-agent-version.properties and override the template when releasing source tar
63+
# because after that there is no Git information anymore.
64+
./mvnw -q -pl apm-sniffer/apm-agent-core initialize \
65+
-DgenerateGitPropertiesFilename="$(pwd)/apm-sniffer/apm-agent-core/src/main/resources/skywalking-agent-version.properties"
66+
6267
cd ..
6368
# Build source code tar
6469
tar czf ${PRODUCT_NAME}-src.tgz \

0 commit comments

Comments
 (0)