You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2023/01/06 10:16:37 UTC

[GitHub] [skywalking-java] kezhenxu94 commented on a diff in pull request #437: Put `Agent-Version` property reading in premain stage to avoid deadlock when use `jarsigner`.

kezhenxu94 commented on code in PR #437:
URL: https://github.com/apache/skywalking-java/pull/437#discussion_r1063304964


##########
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java:
##########
@@ -202,6 +210,35 @@ private static void overrideConfigBySystemProp() {
         }
     }
 
+    /**
+     * Set agent version(Described in MANIFEST.MF)
+     */
+    private static void setAgentVersion() {
+        //set default value
+        Config.Agent.VERSION = "UNKNOWN";
+        try {
+            Enumeration<URL> resources = SnifferConfigInitializer.class.getClassLoader().getResources(JarFile.MANIFEST_NAME);
+            while (resources.hasMoreElements()) {
+                URL url = resources.nextElement();
+                LOGGER.info("SnifferConfigInitializer url:{}", url.toString());
+                try (InputStream is = url.openStream()) {
+                    if (is != null) {
+                        Manifest manifest = new Manifest(is);
+                        Attributes mainAttribs = manifest.getMainAttributes();
+                        String projectName = mainAttribs.getValue("Implementation-Vendor-Id");
+                        if (projectName != null) {
+                            if ("org.apache.skywalking".equals(projectName)) {
+                                Config.Agent.VERSION = mainAttribs.getValue("Implementation-Version");

Review Comment:
   Consider adding a `break` here as soon as you find the version needed. 



##########
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java:
##########
@@ -178,6 +178,11 @@ public static class Agent {
          * Private key file. If ssl_cert_chain and ssl_key exist, will enable mTLS for gRPC channel.
          */
         public static String SSL_KEY_PATH;
+
+        /**
+         * Agent version. This is set by the agent kernel through reading MANIFEST.MF file in the skywalking-agent.jar.
+         */
+        public static String VERSION = "";

Review Comment:
   The default value `UNKNOWN` can be moved here. 



##########
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java:
##########
@@ -98,6 +103,9 @@ public static void initializeCoreConfig(String agentOptions) {
         configureLogger();
         LOGGER = LogManager.getLogger(SnifferConfigInitializer.class);
 
+        //set agent version

Review Comment:
   ```suggestion
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org