Commit b11d4793 authored by 刘新元 Liu XinYuan's avatar 刘新元 Liu XinYuan Committed by 吴晟
Browse files

Add service and instance reset function (#1790)



* Manually trigger agent registration and write registration status to file

* Delete unused variables

* Code optimization, encapsulating some methods

* add clear DataCarrier function

* revert SkyWalkingAgent

* Optimize code and logic, including updating applicatin_id in unRegisterOperationNames

* Server end metadata loss notification

* Server end metadata loss notification

* fix file stream close and other problem

* revert to old

* fix some bug

Signed-off-by: default avatarLiu-XinYuan <879928098@qq.com>

* fix some bugs in agent reset

* add close inputStream and fileChannel and fix some bug

* fixed some bugs
parent 072ee397
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -152,4 +152,10 @@ public class DataCarrier<T> {
            consumerPool.close();
        }
    }

    public void clear() {
        for (int i = 0; i < channels.getChannelSize(); i++) {
            channels.getBuffer(i).clear();
        }
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -91,4 +91,10 @@ public class Buffer<T> {
        return result;
    }

    public void clear() {
        for (Object obj : buffer) {
            obj = null;
        }
    }

}
+16 −2
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
 *
 */


package org.apache.skywalking.apm.agent.core.conf;

import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment;
@@ -70,6 +69,21 @@ public class Config {
         * Skywalking team may ask for these files in order to resolve compatible problem.
         */
        public static boolean IS_OPEN_DEBUGGING_CLASS = false;

        /**
         * Specify register.status dir ,This is an option, the default is AGENT_HOME/option/reset.status.
         */
        public static String REGISTER_STATUS_DIR = "skywalking-agent/option";

        /**
         * Specify instance_uuid to ensure that the whole show is unique, for example: applicationName_ip_12
         */
        public static String INSTANCE_UUID = "";
        /**
         * enabled means that the reset function is enabled, and disabled means that the reset function is not enabled. A reset can be triggered by modifying the configuration file only if the reset feature is enabled.
         */
        public static String RESETER_LISTENER = "disabled";

    }

    public static class Collector {
@@ -80,7 +94,7 @@ public class Config {
        /**
         * application and service registry check interval
         */
        public static long APP_AND_SERVICE_REGISTER_CHECK_INTERVAL = 3;
        public static long SERVICE_AND_ENDPOINT_REGISTER_CHECK_INTERVAL = 3;
        /**
         * Collector skywalking trace receiver service addresses.
         */
+11 −12
Original line number Diff line number Diff line
@@ -41,24 +41,23 @@ import org.apache.skywalking.apm.util.StringUtil;
 */
public class SnifferConfigInitializer {
    private static final ILog logger = LogManager.getLogger(SnifferConfigInitializer.class);
    private static String SPECIFIED_CONFIG_PATH = "skywalking_config";
    private static String DEFAULT_CONFIG_FILE_NAME = "/config/agent.config";
    private static String ENV_KEY_PREFIX = "skywalking.";
    private static final String SPECIFIED_CONFIG_PATH = "skywalking_config";
    private static final String DEFAULT_CONFIG_FILE_NAME = "/config/agent.config";
    private static final String ENV_KEY_PREFIX = "skywalking.";
    private static final String INSTANCE_UUID_NAME = "agent.instance_uuid";
    private static final String REGISTER_STATUS_DIR = "agent.register_status_dir";
    private static boolean IS_INIT_COMPLETED = false;

    /**
     * If the specified agent config path is set, the agent will try to locate the specified agent config.
     * If the specified agent config path is not set , the agent will try to locate `agent.config`, which should be in the /config dictionary of agent package.
     * <p>
     * Also try to override the config by system.env and system.properties. All the keys in these two places should
     * start with {@link #ENV_KEY_PREFIX}. e.g. in env `skywalking.agent.application_code=yourAppName` to override
     * `agent.application_code` in config file.
     * <p>
     * At the end, `agent.application_code` and `collector.servers` must be not blank.
     * If the specified agent config path is set, the agent will try to locate the specified agent config. If the
     * specified agent config path is not set , the agent will try to locate `agent.config`, which should be in the
     * /config dictionary of agent package. <p> Also try to override the config by system.env and system.properties. All
     * the keys in these two places should start with {@link #ENV_KEY_PREFIX}. e.g. in env
     * `skywalking.agent.application_code=yourAppName` to override `agent.application_code` in config file. <p> At the
     * end, `agent.application_code` and `collector.servers` must be not blank.
     */
    public static void initialize() throws ConfigNotFoundException, AgentPackageNotFoundException {
        InputStreamReader configFileStream;

        try {
            configFileStream = loadConfig();
            Properties properties = new Properties();
+6 −1
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
 *
 */


package org.apache.skywalking.apm.agent.core.dictionary;

import io.netty.util.internal.ConcurrentSet;
@@ -49,6 +48,12 @@ public enum NetworkAddressDictionary {
        }
    }

    public void clearApplicationDictionary() {
        unRegisterApplications.clear();
        applicationDictionary.clear();

    }

    public void syncRemoteDictionary(
        NetworkAddressRegisterServiceGrpc.NetworkAddressRegisterServiceBlockingStub networkAddressRegisterServiceBlockingStub) {
        if (unRegisterApplications.size() > 0) {
Loading