void AppConfig::LoadResourceConf()

in core/app_config/AppConfig.cpp [870:1187]


void AppConfig::LoadResourceConf(const Json::Value& confJson) {
    LoadInt32Parameter(
        INT32_FLAG(batch_send_interval), confJson, "batch_send_interval", "ALIYUN_LOGTAIL_BATCH_SEND_INTERVAL");

    LoadInt32Parameter(INT32_FLAG(batch_send_metric_size),
                       confJson,
                       "batch_send_metric_size",
                       "ALIYUN_LOGTAIL_BATCH_SEND_METRIC_SIZE");

    if (confJson.isMember("max_bytes_per_sec") && confJson["max_bytes_per_sec"].isInt())
        mMaxBytePerSec = confJson["max_bytes_per_sec"].asInt();
    else
        mMaxBytePerSec = kDefaultMaxSendBytePerSec;

    if (confJson.isMember("bytes_per_sec") && confJson["bytes_per_sec"].isInt())
        mBytePerSec = confJson["bytes_per_sec"].asInt();
    else
        mBytePerSec = INT32_FLAG(default_send_byte_per_sec);

    if (confJson.isMember("buffer_file_num") && confJson["buffer_file_num"].isInt())
        mNumOfBufferFile = confJson["buffer_file_num"].asInt();
    else
        mNumOfBufferFile = INT32_FLAG(default_buffer_file_num);

    if (confJson.isMember("buffer_file_size") && confJson["buffer_file_size"].isInt())
        mLocalFileSize = confJson["buffer_file_size"].asInt();
    else
        mLocalFileSize = INT32_FLAG(default_local_file_size);

    if (confJson.isMember("buffer_map_size") && confJson["buffer_map_size"].isInt())
        mMaxHoldedDataSize = confJson["buffer_map_size"].asInt();
    else
        mMaxHoldedDataSize = INT32_FLAG(max_holded_data_size);

    if (confJson.isMember("buffer_map_num") && confJson["buffer_map_num"].isInt())
        mMaxBufferNum = confJson["buffer_map_num"].asInt();
    else
        mMaxBufferNum = INT32_FLAG(max_buffer_num);

    if (confJson.isMember("send_request_concurrency") && confJson["send_request_concurrency"].isInt())
        mSendRequestConcurrency = confJson["send_request_concurrency"].asInt();
    else
        mSendRequestConcurrency = INT32_FLAG(send_request_concurrency);

    if (confJson.isMember("process_thread_count") && confJson["process_thread_count"].isInt())
        mProcessThreadCount = confJson["process_thread_count"].asInt();
    else
        mProcessThreadCount = INT32_FLAG(process_thread_count);

    LoadInt32Parameter(INT32_FLAG(logreader_max_rotate_queue_size),
                       confJson,
                       "logreader_max_rotate_queue_size",
                       "ALIYUN_LOGTAIL_LOGREADER_MAX_ROTATE_QUEUE_SIZE");

    LoadInt32Parameter(INT32_FLAG(logreader_filedeleted_remove_interval),
                       confJson,
                       "logreader_filedeleted_remove_interval",
                       "ALIYUN_LOGTAIL_LOGREADER_FILEDELETED_REMOVE_INTERVAL");

    LoadInt32Parameter(INT32_FLAG(check_handler_timeout_interval),
                       confJson,
                       "check_handler_timeout_interval",
                       "ALIYUN_LOGTAIL_CHECK_HANDLER_TIMEOUT_INTERVAL");

    LoadInt32Parameter(INT32_FLAG(reader_close_unused_file_time),
                       confJson,
                       "reader_close_unused_file_time",
                       "ALIYUN_LOGTAIL_READER_CLOSE_UNUSED_FILE_TIME");

    LOG_DEBUG(sLogger,
              ("logreader delete interval", INT32_FLAG(logreader_filedeleted_remove_interval))(
                  "check handler interval", INT32_FLAG(check_handler_timeout_interval))(
                  "reader close interval", INT32_FLAG(reader_close_unused_file_time)));


    if (confJson.isMember("cpu_usage_limit")) {
        if (confJson["cpu_usage_limit"].isDouble())
            mCpuUsageUpLimit = confJson["cpu_usage_limit"].asDouble();
        else if (confJson["cpu_usage_limit"].isIntegral())
            mCpuUsageUpLimit = double(confJson["cpu_usage_limit"].asInt64());
        else
            mCpuUsageUpLimit = DOUBLE_FLAG(cpu_usage_up_limit);
    } else
        mCpuUsageUpLimit = DOUBLE_FLAG(cpu_usage_up_limit);

    if (confJson.isMember("mem_usage_limit") && confJson["mem_usage_limit"].isIntegral())
        mMemUsageUpLimit = confJson["mem_usage_limit"].asInt64();
    else
        mMemUsageUpLimit = INT64_FLAG(memory_usage_up_limit);

    if (confJson.isMember("resource_auto_scale") && confJson["resource_auto_scale"].isBool())
        mResourceAutoScale = confJson["resource_auto_scale"].asBool();
    else
        mResourceAutoScale = BOOL_FLAG(default_resource_auto_scale);

    if (confJson.isMember("input_flow_control") && confJson["input_flow_control"].isBool())
        mInputFlowControl = confJson["input_flow_control"].asBool();
    else
        mInputFlowControl = BOOL_FLAG(default_input_flow_control);

    if (confJson.isMember("machine_cpu_usage_threshold") && confJson["machine_cpu_usage_threshold"].isDouble())
        mMachineCpuUsageThreshold = confJson["machine_cpu_usage_threshold"].asDouble();
    else
        mMachineCpuUsageThreshold = DOUBLE_FLAG(default_machine_cpu_usage_threshold);

    if (confJson.isMember("scaled_cpu_usage_limit")) {
        if (confJson["scaled_cpu_usage_limit"].isDouble())
            mScaledCpuUsageUpLimit = confJson["scaled_cpu_usage_limit"].asDouble();
        else if (confJson["scaled_cpu_usage_limit"].isIntegral())
            mScaledCpuUsageUpLimit = double(confJson["scaled_cpu_usage_limit"].asInt64());
        else
            mScaledCpuUsageUpLimit = DOUBLE_FLAG(cpu_usage_up_limit);
    }

    // first set buffer_file_path, if buffer_file_path is null then set default_buffer_file_path
    if (confJson.isMember("buffer_file_path") && confJson["buffer_file_path"].isString())
        mBufferFilePath = confJson["buffer_file_path"].asString();
    else if (STRING_FLAG(buffer_file_path) != "")
        mBufferFilePath = STRING_FLAG(buffer_file_path);
    else
        mBufferFilePath = STRING_FLAG(default_buffer_file_path);

    if (confJson.isMember("check_point_filename") && confJson["check_point_filename"].isString())
        mCheckPointFilePath = confJson["check_point_filename"].asString();
    else if (confJson.isMember("check_point_file_path") && confJson["check_point_file_path"].isString())
        mCheckPointFilePath = confJson["check_point_file_path"].asString();
    else
        mCheckPointFilePath = GetCheckPointFileName();
    LoadStringParameter(mCheckPointFilePath,
                        confJson,
                        NULL, // Only load from env.
                        "ALIYUN_LOGTAIL_CHECK_POINT_PATH");
    mCheckPointFilePath = AbsolutePath(mCheckPointFilePath, mProcessExecutionDir);
    LOG_INFO(sLogger, ("logtail checkpoint path", mCheckPointFilePath));

    LoadInt32Parameter(INT32_FLAG(truncate_pos_skip_bytes),
                       confJson,
                       "truncate_pos_skip_bytes",
                       "ALIYUN_LOGTAIL_TRUNCATE_POS_SKIP_BYTES");

    if (confJson.isMember("ignore_dir_inode_changed") && confJson["ignore_dir_inode_changed"].isBool()) {
        mIgnoreDirInodeChanged = confJson["ignore_dir_inode_changed"].asBool();
    }

    // LoadStringParameter(mUserConfigPath, confJson, "user_config_file_path", "ALIYUN_LOGTAIL_USER_CONIFG_PATH");

    // LoadStringParameter(
    //     mUserLocalConfigPath, confJson, "user_local_config_filename", "ALIYUN_LOGTAIL_USER_LOCAL_CONFIG_FILENAME");

    LoadBooleanParameter(
        BOOL_FLAG(ilogtail_discard_old_data), confJson, "discard_old_data", "ALIYUN_LOGTAIL_DISCARD_OLD_DATA");

    // if (confJson.isMember("container_mount_path") && confJson["container_mount_path"].isString()) {
    //     mContainerMountConfigPath = confJson["container_mount_path"].asString();
    // } else {
    //     mContainerMountConfigPath = GetProcessExecutionDir() + STRING_FLAG(default_container_mount_path);
    // }

    LoadStringParameter(mConfigIP, confJson, "working_ip", "ALIYUN_LOGTAIL_WORKING_IP");

    // LoadStringParameter(mCustomizedConfigIP, confJson, "customized_config_ip",
    // "ALIYUN_LOGTAIL_CUSTOMIZED_CONFIG_IP");

    LoadStringParameter(mConfigHostName, confJson, "working_hostname", "ALIYUN_LOGTAIL_WORKING_HOSTNAME");

    // // try to get zone env name from conf json
    // if (confJson.isMember("alipay_zone_env_name") && confJson["alipay_zone_env_name"].isString()) {
    //     STRING_FLAG(alipay_zone_env_name) = confJson["alipay_zone_env_name"].asString();
    // }
    // // get zone info from env, for ant
    // do {
    //     if (!STRING_FLAG(alipay_zone_env_name).empty()) {
    //         const char* alipayZone = getenv(STRING_FLAG(alipay_zone_env_name).c_str());
    //         if (alipayZone != NULL) {
    //             mAlipayZone = alipayZone;
    //             break;
    //         }
    //     }
    //     const char* alipayZone = getenv(STRING_FLAG(alipay_app_zone).c_str());
    //     if (alipayZone != NULL) {
    //         mAlipayZone = alipayZone;
    //         break;
    //     }
    //     alipayZone = getenv(STRING_FLAG(alipay_zone).c_str());
    //     if (alipayZone != NULL) {
    //         mAlipayZone = alipayZone;
    //         break;
    //     }
    // } while (false);

    // if (confJson.isMember("alipay_zone") && confJson["alipay_zone"].isString()) {
    //     mAlipayZone = confJson["alipay_zone"].asString();
    // }

    if (confJson.isMember("system_boot_time") && confJson["system_boot_time"].isInt()) {
        mSystemBootTime = confJson["system_boot_time"].asInt();
    }

    LoadStringParameter(
        mDockerFilePathConfig, confJson, "docker_file_cache_path", "ALIYUN_LOGTAIL_DOCKER_FILE_CACHE_PATH");

    LoadInt32Parameter(INT32_FLAG(max_docker_config_update_times),
                       confJson,
                       "max_docker_config_update_times",
                       "ALIYUN_LOGTAIL_MAX_DOCKER_CONFIG_UPDATE_TIMES");

    LoadInt32Parameter(INT32_FLAG(docker_config_update_interval),
                       confJson,
                       "docker_config_update_interval",
                       "ALIYUN_LOGTAIL_DOCKER_CONFIG_UPDATE_INTERVAL");

    if (confJson.isMember("no_inotify") && confJson["no_inotify"].isBool()) {
        mNoInotify = confJson["no_inotify"].asBool();
        LOG_INFO(sLogger, ("set no_inotify flag", mNoInotify));
    }

    if (confJson.isMember("inotify_black_list") && confJson["inotify_black_list"].isArray()) {
        const Json::Value& blackList = confJson["inotify_black_list"];
        for (Json::ArrayIndex i = 0; i < blackList.size(); ++i) {
            const Json::Value& item = blackList[i];
            if (item.isString()) {
                mInotifyBlackList.insert(item.asString());
                LOG_INFO(sLogger, ("add inoitfy black list", item.asString()));
            }
        }
    }

    if (!STRING_FLAG(host_path_blacklist).empty()) {
#ifdef _MSC_VER
        static const std::string delim = ";";
#else
        static const std::string delim = ":";
#endif
        auto blacklist = SplitString(TrimString(STRING_FLAG(host_path_blacklist)), delim);
        for (const auto& s : blacklist) {
            auto s1 = TrimString(s);
            if (!s1.empty()) {
                mHostPathBlacklist.emplace_back(std::move(s1));
            }
        }
    }

    if (!LoadInt32Parameter(mSendDataPort, confJson, "data_server_port", "ALIYUN_LOGTAIL_DATA_SERVER_PORT")) {
        mSendDataPort = INT32_FLAG(data_server_port);
    }

    if (confJson.isMember("shennong_unix_socket") && confJson["shennong_unix_socket"].isBool()) {
        mShennongSocket = confJson["shennong_unix_socket"].asBool();
    }

    {
        int32_t maxReadBufferSize = 0;
        if (LoadInt32Parameter(
                maxReadBufferSize, confJson, "max_read_buffer_size", "ALIYUN_LOGTAIL_MAX_READ_BUFFER_SIZE")) {
            LogFileReader::SetReadBufferSize(maxReadBufferSize);
        }
    }

    LoadInt32Parameter(
        INT32_FLAG(default_tail_limit_kb), confJson, "default_tail_limit_kb", "ALIYUN_LOGTAIL_DEFAULT_TAIL_LIMIT_KB");

    if (confJson.isMember("read_local_event_interval") && confJson["read_local_event_interval"].isInt()) {
        INT32_FLAG(read_local_event_interval) = confJson["read_local_event_interval"].asInt();
        LOG_INFO(sLogger, ("set read_local_event_interval", INT32_FLAG(read_local_event_interval)));
    }

    LoadInt32Parameter(INT32_FLAG(check_point_dump_interval),
                       confJson,
                       "check_point_dump_interval",
                       "ALIYUN_LOGTAIL_CHECKPOINT_DUMP_INTERVAL");

    // if (confJson.isMember("rapid_retry_update_config") && confJson["rapid_retry_update_config"].isBool()) {
    //     BOOL_FLAG(rapid_retry_update_config) = confJson["rapid_retry_update_config"].asBool();
    //     LOG_INFO(sLogger, ("set rapid_retry_update_config", BOOL_FLAG(rapid_retry_update_config)));
    // }

    if (confJson.isMember("check_profile_region") && confJson["check_profile_region"].isBool()) {
        BOOL_FLAG(check_profile_region) = confJson["check_profile_region"].asBool();
        LOG_INFO(sLogger, ("set check_profile_region", BOOL_FLAG(check_profile_region)));
    }

    // if (confJson.isMember("enable_collection_mark") && confJson["enable_collection_mark"].isBool()) {
    //     BOOL_FLAG(enable_collection_mark) = confJson["enable_collection_mark"].asBool();
    //     LOG_INFO(sLogger, ("set enable_collection_mark", BOOL_FLAG(enable_collection_mark)));
    // }

    // LoadBooleanParameter(BOOL_FLAG(enable_collection_mark),
    //                      confJson,
    //                      "enable_env_ref_in_config",
    //                      "ALIYUN_LOGTAIL_ENABLE_ENV_REF_IN_CONFIG");

    LoadBooleanParameter(
        mEnableHostIPReplace, confJson, "enable_host_ip_replace", "ALIYUN_LOGTAIL_ENABLE_HOST_IP_REPLACE");

    LoadBooleanParameter(mEnableResponseVerification,
                         confJson,
                         "enable_response_verification",
                         "ALIYUN_LOGTAIL_ENABLE_RESPONSE_VERIFICATION");

    LoadEnvResourceLimit();
    CheckAndAdjustParameters();

    if (confJson.isMember("bind_interface") && confJson["bind_interface"].isString()) {
        mBindInterface = TrimString(confJson["bind_interface"].asString());
        if (ToLowerCaseString(mBindInterface) == "default")
            mBindInterface.clear();
        LOG_INFO(sLogger, ("bind_interface", mBindInterface));
    }

    // mSendRequestConcurrency was limited
    if (mSendRequestConcurrency < MIN_SEND_REQUEST_CONCURRENCY) {
        mSendRequestConcurrency = MIN_SEND_REQUEST_CONCURRENCY;
    }
    if (mSendRequestConcurrency > MAX_SEND_REQUEST_CONCURRENCY) {
        mSendRequestConcurrency = MAX_SEND_REQUEST_CONCURRENCY;
    }
    mSendRequestGlobalConcurrency = mSendRequestConcurrency * (1 + GLOBAL_CONCURRENCY_FREE_PERCENTAGE_FOR_ONE_REGION);
}