test_config.cpp 25.2 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// 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.

S
starlord 已提交
18
#include <gtest/gtest-death-test.h>
Y
youny626 已提交
19
#include <gtest/gtest.h>
20
#include <cmath>
G
groot 已提交
21

Y
yudong.cai 已提交
22
#include "config/YamlConfigMgr.h"
S
starlord 已提交
23
#include "server/Config.h"
S
starlord 已提交
24
#include "server/utils.h"
Y
youny626 已提交
25
#include "utils/CommonUtil.h"
Z
Zhiru Zhu 已提交
26
#include "utils/StringHelpFunctions.h"
Y
youny626 已提交
27
#include "utils/ValidationUtil.h"
G
groot 已提交
28

G
groot 已提交
29 30
#include <limits>

G
groot 已提交
31 32
namespace {

S
starlord 已提交
33
static constexpr uint64_t KB = 1024;
S
starlord 已提交
34 35
static constexpr uint64_t MB = KB * 1024;
static constexpr uint64_t GB = MB * 1024;
S
starlord 已提交
36

Y
youny626 已提交
37
}  // namespace
G
groot 已提交
38

C
Cai Yudong 已提交
39 40
namespace ms = milvus::server;

S
starlord 已提交
41
TEST_F(ConfigTest, CONFIG_TEST) {
S
starlord 已提交
42
    milvus::server::ConfigMgr* config_mgr = milvus::server::YamlConfigMgr::GetInstance();
G
groot 已提交
43

Y
yudong.cai 已提交
44 45
    milvus::Status s = config_mgr->LoadConfigFile("");
    ASSERT_FALSE(s.ok());
G
groot 已提交
46

S
starlord 已提交
47
    std::string config_path(CONFIG_PATH);
S
starlord 已提交
48
    s = config_mgr->LoadConfigFile(config_path + INVALID_CONFIG_FILE);
Y
yudong.cai 已提交
49
    ASSERT_FALSE(s.ok());
G
groot 已提交
50

S
starlord 已提交
51
    s = config_mgr->LoadConfigFile(config_path + VALID_CONFIG_FILE);
Y
yudong.cai 已提交
52
    ASSERT_TRUE(s.ok());
G
groot 已提交
53

G
groot 已提交
54 55
    config_mgr->Print();

S
starlord 已提交
56 57 58 59 60
    milvus::server::ConfigNode& root_config = config_mgr->GetRootNode();
    milvus::server::ConfigNode& server_config = root_config.GetChild("server_config");
    milvus::server::ConfigNode& db_config = root_config.GetChild("db_config");
    milvus::server::ConfigNode& metric_config = root_config.GetChild("metric_config");
    milvus::server::ConfigNode& cache_config = root_config.GetChild("cache_config");
S
starlord 已提交
61
    milvus::server::ConfigNode invalid_config = root_config.GetChild("invalid_config");
S
starlord 已提交
62 63 64
    auto valus = invalid_config.GetSequence("not_exist");
    float ff = invalid_config.GetFloatValue("not_exist", 3.0);
    ASSERT_EQ(ff, 3.0);
G
groot 已提交
65 66 67 68

    std::string address = server_config.GetValue("address");
    ASSERT_TRUE(!address.empty());
    int64_t port = server_config.GetInt64Value("port");
S
starlord 已提交
69
    ASSERT_NE(port, 0);
G
groot 已提交
70

G
groot 已提交
71 72
    server_config.SetValue("float_test", "2.5");
    double dbl = server_config.GetDoubleValue("float_test");
73
    ASSERT_LE(std::fabs(dbl - 2.5), std::numeric_limits<double>::epsilon());
G
groot 已提交
74
    float flt = server_config.GetFloatValue("float_test");
75
    ASSERT_LE(std::fabs(flt - 2.5), std::numeric_limits<float>::epsilon());
G
groot 已提交
76 77 78 79 80 81 82 83 84 85

    server_config.SetValue("bool_test", "true");
    bool blt = server_config.GetBoolValue("bool_test");
    ASSERT_TRUE(blt);

    server_config.SetValue("int_test", "34");
    int32_t it32 = server_config.GetInt32Value("int_test");
    ASSERT_EQ(it32, 34);
    int64_t it64 = server_config.GetInt64Value("int_test");
    ASSERT_EQ(it64, 34);
G
groot 已提交
86

S
starlord 已提交
87
    milvus::server::ConfigNode fake;
G
groot 已提交
88 89
    server_config.AddChild("fake", fake);
    fake = server_config.GetChild("fake");
S
starlord 已提交
90
    milvus::server::ConfigNodeArr arr;
G
groot 已提交
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    server_config.GetChildren(arr);
    ASSERT_EQ(arr.size(), 1UL);

    server_config.ClearChildren();
    auto children = server_config.GetChildren();
    ASSERT_TRUE(children.empty());

    server_config.ClearConfig();
    auto configs = server_config.GetConfig();
    ASSERT_TRUE(configs.empty());

    server_config.AddSequenceItem("seq", "aaa");
    server_config.AddSequenceItem("seq", "bbb");
    auto seq = server_config.GetSequence("seq");
    ASSERT_EQ(seq.size(), 2UL);

S
starlord 已提交
107
    milvus::server::ConfigNode combine;
G
groot 已提交
108 109 110 111 112 113
    combine.Combine(server_config);

    combine.PrintAll();
    std::string all = combine.DumpString();
    ASSERT_TRUE(!all.empty());

G
groot 已提交
114 115 116 117 118
    server_config.ClearSequences();
    auto seqs = server_config.GetSequences();
    ASSERT_TRUE(seqs.empty());
}

Z
Zhiru Zhu 已提交
119 120 121 122 123 124 125 126 127 128
TEST_F(ConfigTest, SERVER_CONFIG_VALID_TEST) {
    std::string config_path(CONFIG_PATH);
    milvus::server::Config& config = milvus::server::Config::GetInstance();
    std::string str_val;
    int64_t int64_val;
    float float_val;
    bool bool_val;

    /* server config */
    std::string server_addr = "192.168.1.155";
C
Cai Yudong 已提交
129 130
    ASSERT_TRUE(config.SetServerConfigAddress(server_addr).ok());
    ASSERT_TRUE(config.GetServerConfigAddress(str_val).ok());
Z
Zhiru Zhu 已提交
131 132 133
    ASSERT_TRUE(str_val == server_addr);

    std::string server_port = "12345";
C
Cai Yudong 已提交
134 135
    ASSERT_TRUE(config.SetServerConfigPort(server_port).ok());
    ASSERT_TRUE(config.GetServerConfigPort(str_val).ok());
Z
Zhiru Zhu 已提交
136 137
    ASSERT_TRUE(str_val == server_port);

B
BossZou 已提交
138 139 140 141 142
    std::string web_port = "19999";
    ASSERT_TRUE(config.SetServerConfigWebPort(web_port).ok());
    ASSERT_TRUE(config.GetServerConfigWebPort(str_val).ok());
    ASSERT_TRUE(str_val == web_port);

Z
Zhiru Zhu 已提交
143
    std::string server_mode = "cluster_readonly";
C
Cai Yudong 已提交
144 145
    ASSERT_TRUE(config.SetServerConfigDeployMode(server_mode).ok());
    ASSERT_TRUE(config.GetServerConfigDeployMode(str_val).ok());
Z
Zhiru Zhu 已提交
146 147 148
    ASSERT_TRUE(str_val == server_mode);

    std::string server_time_zone = "UTC+6";
C
Cai Yudong 已提交
149 150
    ASSERT_TRUE(config.SetServerConfigTimeZone(server_time_zone).ok());
    ASSERT_TRUE(config.GetServerConfigTimeZone(str_val).ok());
Z
Zhiru Zhu 已提交
151 152 153 154
    ASSERT_TRUE(str_val == server_time_zone);

    /* db config */
    std::string db_backend_url = "mysql://root:123456@127.0.0.1:19530/milvus";
C
Cai Yudong 已提交
155 156
    ASSERT_TRUE(config.SetDBConfigBackendUrl(db_backend_url).ok());
    ASSERT_TRUE(config.GetDBConfigBackendUrl(str_val).ok());
Z
Zhiru Zhu 已提交
157 158
    ASSERT_TRUE(str_val == db_backend_url);

Y
yudong.cai 已提交
159
    int64_t db_archive_disk_threshold = 100;
C
Cai Yudong 已提交
160 161
    ASSERT_TRUE(config.SetDBConfigArchiveDiskThreshold(std::to_string(db_archive_disk_threshold)).ok());
    ASSERT_TRUE(config.GetDBConfigArchiveDiskThreshold(int64_val).ok());
Y
yudong.cai 已提交
162
    ASSERT_TRUE(int64_val == db_archive_disk_threshold);
Z
Zhiru Zhu 已提交
163

Y
yudong.cai 已提交
164
    int64_t db_archive_days_threshold = 365;
C
Cai Yudong 已提交
165 166
    ASSERT_TRUE(config.SetDBConfigArchiveDaysThreshold(std::to_string(db_archive_days_threshold)).ok());
    ASSERT_TRUE(config.GetDBConfigArchiveDaysThreshold(int64_val).ok());
Y
yudong.cai 已提交
167
    ASSERT_TRUE(int64_val == db_archive_days_threshold);
Z
Zhiru Zhu 已提交
168

C
Cai Yudong 已提交
169
    /* storage config */
170 171 172 173 174 175 176 177 178 179
    std::string storage_primary_path = "/home/zilliz";
    ASSERT_TRUE(config.SetStorageConfigPrimaryPath(storage_primary_path).ok());
    ASSERT_TRUE(config.GetStorageConfigPrimaryPath(str_val).ok());
    ASSERT_TRUE(str_val == storage_primary_path);

    std::string storage_secondary_path = "/home/zilliz";
    ASSERT_TRUE(config.SetStorageConfigSecondaryPath(storage_secondary_path).ok());
    ASSERT_TRUE(config.GetStorageConfigSecondaryPath(str_val).ok());
    ASSERT_TRUE(str_val == storage_secondary_path);

180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
    bool storage_s3_enable = true;
    ASSERT_TRUE(config.SetStorageConfigS3Enable(std::to_string(storage_s3_enable)).ok());
    ASSERT_TRUE(config.GetStorageConfigS3Enable(bool_val).ok());
    ASSERT_TRUE(bool_val == storage_s3_enable);

    std::string storage_s3_addr = "192.168.1.100";
    ASSERT_TRUE(config.SetStorageConfigS3Address(storage_s3_addr).ok());
    ASSERT_TRUE(config.GetStorageConfigS3Address(str_val).ok());
    ASSERT_TRUE(str_val == storage_s3_addr);

    std::string storage_s3_port = "12345";
    ASSERT_TRUE(config.SetStorageConfigS3Port(storage_s3_port).ok());
    ASSERT_TRUE(config.GetStorageConfigS3Port(str_val).ok());
    ASSERT_TRUE(str_val == storage_s3_port);

    std::string storage_s3_access_key = "minioadmin";
    ASSERT_TRUE(config.SetStorageConfigS3AccessKey(storage_s3_access_key).ok());
    ASSERT_TRUE(config.GetStorageConfigS3AccessKey(str_val).ok());
    ASSERT_TRUE(str_val == storage_s3_access_key);

    std::string storage_s3_secret_key = "minioadmin";
    ASSERT_TRUE(config.SetStorageConfigS3SecretKey(storage_s3_secret_key).ok());
    ASSERT_TRUE(config.GetStorageConfigS3SecretKey(str_val).ok());
    ASSERT_TRUE(str_val == storage_s3_secret_key);

    std::string storage_s3_bucket = "s3bucket";
    ASSERT_TRUE(config.SetStorageConfigS3Bucket(storage_s3_bucket).ok());
    ASSERT_TRUE(config.GetStorageConfigS3Bucket(str_val).ok());
    ASSERT_TRUE(str_val == storage_s3_bucket);
C
Cai Yudong 已提交
209

Z
Zhiru Zhu 已提交
210 211
    /* metric config */
    bool metric_enable_monitor = false;
C
Cai Yudong 已提交
212 213
    ASSERT_TRUE(config.SetMetricConfigEnableMonitor(std::to_string(metric_enable_monitor)).ok());
    ASSERT_TRUE(config.GetMetricConfigEnableMonitor(bool_val).ok());
Z
Zhiru Zhu 已提交
214 215
    ASSERT_TRUE(bool_val == metric_enable_monitor);

C
Cai Yudong 已提交
216 217 218 219
    std::string metric_address = "192.168.0.2";
    ASSERT_TRUE(config.SetMetricConfigAddress(metric_address).ok());
    ASSERT_TRUE(config.GetMetricConfigAddress(str_val).ok());
    ASSERT_TRUE(str_val == metric_address);
Z
Zhiru Zhu 已提交
220

C
Cai Yudong 已提交
221 222 223 224
    std::string metric_port = "2222";
    ASSERT_TRUE(config.SetMetricConfigPort(metric_port).ok());
    ASSERT_TRUE(config.GetMetricConfigPort(str_val).ok());
    ASSERT_TRUE(str_val == metric_port);
Z
Zhiru Zhu 已提交
225 226

    /* cache config */
Y
yukun 已提交
227
    int64_t cache_cpu_cache_capacity = 1;
C
Cai Yudong 已提交
228 229
    ASSERT_TRUE(config.SetCacheConfigCpuCacheCapacity(std::to_string(cache_cpu_cache_capacity)).ok());
    ASSERT_TRUE(config.GetCacheConfigCpuCacheCapacity(int64_val).ok());
Z
Zhiru Zhu 已提交
230 231 232
    ASSERT_TRUE(int64_val == cache_cpu_cache_capacity);

    float cache_cpu_cache_threshold = 0.1;
C
Cai Yudong 已提交
233 234
    ASSERT_TRUE(config.SetCacheConfigCpuCacheThreshold(std::to_string(cache_cpu_cache_threshold)).ok());
    ASSERT_TRUE(config.GetCacheConfigCpuCacheThreshold(float_val).ok());
Z
Zhiru Zhu 已提交
235 236
    ASSERT_TRUE(float_val == cache_cpu_cache_threshold);

237 238 239 240 241
    int64_t cache_insert_buffer_size = 2;
    ASSERT_TRUE(config.SetCacheConfigInsertBufferSize(std::to_string(cache_insert_buffer_size)).ok());
    ASSERT_TRUE(config.GetCacheConfigInsertBufferSize(int64_val).ok());
    ASSERT_TRUE(int64_val == cache_insert_buffer_size);

Z
Zhiru Zhu 已提交
242
    bool cache_insert_data = true;
C
Cai Yudong 已提交
243 244
    ASSERT_TRUE(config.SetCacheConfigCacheInsertData(std::to_string(cache_insert_data)).ok());
    ASSERT_TRUE(config.GetCacheConfigCacheInsertData(bool_val).ok());
Z
Zhiru Zhu 已提交
245 246 247
    ASSERT_TRUE(bool_val == cache_insert_data);

    /* engine config */
Y
yudong.cai 已提交
248
    int64_t engine_use_blas_threshold = 50;
C
Cai Yudong 已提交
249 250
    ASSERT_TRUE(config.SetEngineConfigUseBlasThreshold(std::to_string(engine_use_blas_threshold)).ok());
    ASSERT_TRUE(config.GetEngineConfigUseBlasThreshold(int64_val).ok());
Y
yudong.cai 已提交
251
    ASSERT_TRUE(int64_val == engine_use_blas_threshold);
Z
Zhiru Zhu 已提交
252

Y
yukun 已提交
253
    int64_t engine_omp_thread_num = 1;
C
Cai Yudong 已提交
254 255
    ASSERT_TRUE(config.SetEngineConfigOmpThreadNum(std::to_string(engine_omp_thread_num)).ok());
    ASSERT_TRUE(config.GetEngineConfigOmpThreadNum(int64_val).ok());
Y
yudong.cai 已提交
256
    ASSERT_TRUE(int64_val == engine_omp_thread_num);
Z
Zhiru Zhu 已提交
257

G
groot 已提交
258
#ifdef MILVUS_GPU_VERSION
Y
yudong.cai 已提交
259
    int64_t engine_gpu_search_threshold = 800;
C
Cai Yudong 已提交
260 261
    ASSERT_TRUE(config.SetEngineConfigGpuSearchThreshold(std::to_string(engine_gpu_search_threshold)).ok());
    ASSERT_TRUE(config.GetEngineConfigGpuSearchThreshold(int64_val).ok());
Y
yudong.cai 已提交
262
    ASSERT_TRUE(int64_val == engine_gpu_search_threshold);
C
Cai Yudong 已提交
263
#endif
Z
Zhiru Zhu 已提交
264

Y
yudong.cai 已提交
265
    /* gpu resource config */
C
Cai Yudong 已提交
266
#ifdef MILVUS_GPU_VERSION
Y
yudong.cai 已提交
267
    bool resource_enable_gpu = true;
C
Cai Yudong 已提交
268 269
    ASSERT_TRUE(config.SetGpuResourceConfigEnable(std::to_string(resource_enable_gpu)).ok());
    ASSERT_TRUE(config.GetGpuResourceConfigEnable(bool_val).ok());
Y
yudong.cai 已提交
270
    ASSERT_TRUE(bool_val == resource_enable_gpu);
Z
Zhiru Zhu 已提交
271

Y
yudong.cai 已提交
272
    int64_t gpu_cache_capacity = 1;
C
Cai Yudong 已提交
273 274
    ASSERT_TRUE(config.SetGpuResourceConfigCacheCapacity(std::to_string(gpu_cache_capacity)).ok());
    ASSERT_TRUE(config.GetGpuResourceConfigCacheCapacity(int64_val).ok());
Y
yudong.cai 已提交
275 276 277
    ASSERT_TRUE(int64_val == gpu_cache_capacity);

    float gpu_cache_threshold = 0.2;
C
Cai Yudong 已提交
278 279
    ASSERT_TRUE(config.SetGpuResourceConfigCacheThreshold(std::to_string(gpu_cache_threshold)).ok());
    ASSERT_TRUE(config.GetGpuResourceConfigCacheThreshold(float_val).ok());
Y
yudong.cai 已提交
280 281 282
    ASSERT_TRUE(float_val == gpu_cache_threshold);

    std::vector<std::string> search_resources = {"gpu0"};
Y
yudong.cai 已提交
283
    std::vector<int64_t> search_res_vec;
284
    std::string search_res_str;
Z
Zhiru Zhu 已提交
285
    milvus::server::StringHelpFunctions::MergeStringWithDelimeter(
Y
yudong.cai 已提交
286
        search_resources, milvus::server::CONFIG_GPU_RESOURCE_DELIMITER, search_res_str);
C
Cai Yudong 已提交
287 288
    ASSERT_TRUE(config.SetGpuResourceConfigSearchResources(search_res_str).ok());
    ASSERT_TRUE(config.GetGpuResourceConfigSearchResources(search_res_vec).ok());
Z
Zhiru Zhu 已提交
289
    for (size_t i = 0; i < search_resources.size(); i++) {
Y
yudong.cai 已提交
290
        ASSERT_TRUE(std::stoll(search_resources[i].substr(3)) == search_res_vec[i]);
Z
Zhiru Zhu 已提交
291 292
    }

Y
yudong.cai 已提交
293
    std::vector<std::string> build_index_resources = {"gpu0"};
Y
yudong.cai 已提交
294
    std::vector<int64_t> build_index_res_vec;
Y
yudong.cai 已提交
295
    std::string build_index_res_str;
296
    milvus::server::StringHelpFunctions::MergeStringWithDelimeter(
Y
yudong.cai 已提交
297
        build_index_resources, milvus::server::CONFIG_GPU_RESOURCE_DELIMITER, build_index_res_str);
C
Cai Yudong 已提交
298 299
    ASSERT_TRUE(config.SetGpuResourceConfigBuildIndexResources(build_index_res_str).ok());
    ASSERT_TRUE(config.GetGpuResourceConfigBuildIndexResources(build_index_res_vec).ok());
Y
yudong.cai 已提交
300
    for (size_t i = 0; i < build_index_resources.size(); i++) {
Y
yudong.cai 已提交
301
        ASSERT_TRUE(std::stoll(build_index_resources[i].substr(3)) == build_index_res_vec[i]);
302
    }
Y
yudong.cai 已提交
303
#endif
Z
Zhiru Zhu 已提交
304 305
}

306 307
std::string
gen_get_command(const std::string& parent_node, const std::string& child_node) {
308
    std::string cmd = "get_config " + parent_node + ms::CONFIG_NODE_DELIMITER + child_node;
C
Cai Yudong 已提交
309 310 311
    return cmd;
}

312 313
std::string
gen_set_command(const std::string& parent_node, const std::string& child_node, const std::string& value) {
314
    std::string cmd = "set_config " + parent_node + ms::CONFIG_NODE_DELIMITER + child_node + " " + value;
C
Cai Yudong 已提交
315 316 317 318 319 320 321 322 323 324 325
    return cmd;
}

TEST_F(ConfigTest, SERVER_CONFIG_CLI_TEST) {
    std::string config_path(CONFIG_PATH);
    milvus::server::Config& config = milvus::server::Config::GetInstance();
    milvus::Status s;

    std::string get_cmd, set_cmd;
    std::string result, dummy;

326 327 328
    s = config.ProcessConfigCli(result, "get_config *");
    ASSERT_TRUE(s.ok());

C
Cai Yudong 已提交
329 330 331 332
    /* server config */
    std::string server_addr = "192.168.1.155";
    get_cmd = gen_get_command(ms::CONFIG_SERVER, ms::CONFIG_SERVER_ADDRESS);
    set_cmd = gen_set_command(ms::CONFIG_SERVER, ms::CONFIG_SERVER_ADDRESS, server_addr);
333
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
334
    ASSERT_FALSE(s.ok());
335
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
336 337 338
    ASSERT_TRUE(s.ok());

    /* db config */
339 340 341
    std::string db_backend_url = "bad_url";
    get_cmd = gen_get_command(ms::CONFIG_DB, ms::CONFIG_DB_BACKEND_URL);
    set_cmd = gen_set_command(ms::CONFIG_DB, ms::CONFIG_DB_BACKEND_URL, db_backend_url);
342
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
343
    ASSERT_FALSE(s.ok());
344
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
345 346 347 348 349 350
    ASSERT_TRUE(s.ok());

    /* metric config */
    std::string metric_enable_monitor = "false";
    get_cmd = gen_get_command(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR);
    set_cmd = gen_set_command(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR, metric_enable_monitor);
351
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
352
    ASSERT_FALSE(s.ok());
353
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
354 355
    ASSERT_TRUE(s.ok());

C
Cai Yudong 已提交
356
    /* storage config */
357 358 359
    std::string storage_s3_enable = "true";
    get_cmd = gen_get_command(ms::CONFIG_STORAGE, ms::CONFIG_STORAGE_S3_ENABLE);
    set_cmd = gen_set_command(ms::CONFIG_STORAGE, ms::CONFIG_STORAGE_S3_ENABLE, storage_s3_enable);
C
Cai Yudong 已提交
360 361 362 363 364
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_FALSE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());

C
Cai Yudong 已提交
365
    /* cache config */
Y
yukun 已提交
366
    std::string cache_cpu_cache_capacity = "1";
C
Cai Yudong 已提交
367 368
    get_cmd = gen_get_command(ms::CONFIG_CACHE, ms::CONFIG_CACHE_CPU_CACHE_CAPACITY);
    set_cmd = gen_set_command(ms::CONFIG_CACHE, ms::CONFIG_CACHE_CPU_CACHE_CAPACITY, cache_cpu_cache_capacity);
369
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
370
    ASSERT_TRUE(s.ok());
371
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
372 373 374 375 376 377
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == cache_cpu_cache_capacity);

    std::string cache_cpu_cache_threshold = "0.1";
    get_cmd = gen_get_command(ms::CONFIG_CACHE, ms::CONFIG_CACHE_CPU_CACHE_THRESHOLD);
    set_cmd = gen_set_command(ms::CONFIG_CACHE, ms::CONFIG_CACHE_CPU_CACHE_THRESHOLD, cache_cpu_cache_threshold);
378
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
379
    ASSERT_TRUE(s.ok());
380
    s = config.ProcessConfigCli(result, get_cmd);
381
    ASSERT_TRUE(s.ok());
C
Cai Yudong 已提交
382 383
    ASSERT_TRUE(result == cache_cpu_cache_threshold);

384 385 386 387 388 389 390 391
    std::string cache_insert_buffer_size = "1";
    get_cmd = gen_get_command(ms::CONFIG_CACHE, ms::CONFIG_CACHE_INSERT_BUFFER_SIZE);
    set_cmd = gen_set_command(ms::CONFIG_CACHE, ms::CONFIG_CACHE_INSERT_BUFFER_SIZE, cache_insert_buffer_size);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());

C
Cai Yudong 已提交
392 393 394
    std::string cache_insert_data = "true";
    get_cmd = gen_get_command(ms::CONFIG_CACHE, ms::CONFIG_CACHE_CACHE_INSERT_DATA);
    set_cmd = gen_set_command(ms::CONFIG_CACHE, ms::CONFIG_CACHE_CACHE_INSERT_DATA, cache_insert_data);
395
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
396
    ASSERT_TRUE(s.ok());
397
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
398 399 400 401 402 403
    ASSERT_TRUE(result == cache_insert_data);

    /* engine config */
    std::string engine_use_blas_threshold = "50";
    get_cmd = gen_get_command(ms::CONFIG_ENGINE, ms::CONFIG_ENGINE_USE_BLAS_THRESHOLD);
    set_cmd = gen_set_command(ms::CONFIG_ENGINE, ms::CONFIG_ENGINE_USE_BLAS_THRESHOLD, engine_use_blas_threshold);
404
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
405
    ASSERT_TRUE(s.ok());
406
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
407 408 409
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == engine_use_blas_threshold);

Y
yukun 已提交
410
    std::string engine_omp_thread_num = "1";
C
Cai Yudong 已提交
411 412
    get_cmd = gen_get_command(ms::CONFIG_ENGINE, ms::CONFIG_ENGINE_OMP_THREAD_NUM);
    set_cmd = gen_set_command(ms::CONFIG_ENGINE, ms::CONFIG_ENGINE_OMP_THREAD_NUM, engine_omp_thread_num);
413
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
414
    ASSERT_TRUE(s.ok());
415
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
416 417 418 419 420 421 422
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == engine_omp_thread_num);

#ifdef MILVUS_GPU_VERSION
    std::string engine_gpu_search_threshold = "800";
    get_cmd = gen_get_command(ms::CONFIG_ENGINE, ms::CONFIG_ENGINE_GPU_SEARCH_THRESHOLD);
    set_cmd = gen_set_command(ms::CONFIG_ENGINE, ms::CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, engine_gpu_search_threshold);
423
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
424
    ASSERT_TRUE(s.ok());
425
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
426 427
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == engine_gpu_search_threshold);
C
Cai Yudong 已提交
428
#endif
C
Cai Yudong 已提交
429 430

    /* gpu resource config */
C
Cai Yudong 已提交
431
#ifdef MILVUS_GPU_VERSION
C
Cai Yudong 已提交
432 433 434
    std::string resource_enable_gpu = "true";
    get_cmd = gen_get_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_ENABLE);
    set_cmd = gen_set_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_ENABLE, resource_enable_gpu);
435
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
436
    ASSERT_TRUE(s.ok());
437
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
438 439 440 441 442 443
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == resource_enable_gpu);

    std::string gpu_cache_capacity = "1";
    get_cmd = gen_get_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_CACHE_CAPACITY);
    set_cmd = gen_set_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_CACHE_CAPACITY, gpu_cache_capacity);
444
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
445
    ASSERT_TRUE(s.ok());
446
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
447 448 449 450 451 452
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == gpu_cache_capacity);

    std::string gpu_cache_threshold = "0.2";
    get_cmd = gen_get_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_CACHE_THRESHOLD);
    set_cmd = gen_set_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_CACHE_THRESHOLD, gpu_cache_threshold);
453
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
454
    ASSERT_TRUE(s.ok());
455
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
456 457 458 459 460
    ASSERT_TRUE(result == gpu_cache_threshold);

    std::string search_resources = "gpu0";
    get_cmd = gen_get_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_SEARCH_RESOURCES);
    set_cmd = gen_set_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_SEARCH_RESOURCES, search_resources);
461
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
462
    ASSERT_TRUE(s.ok());
463
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
464 465 466 467 468 469 470
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == search_resources);

    std::string build_index_resources = "gpu0";
    get_cmd = gen_get_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES);
    set_cmd =
        gen_set_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, build_index_resources);
471
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
472
    ASSERT_TRUE(s.ok());
473
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
474 475 476 477 478
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == build_index_resources);
#endif
}

Z
Zhiru Zhu 已提交
479 480 481 482 483
TEST_F(ConfigTest, SERVER_CONFIG_INVALID_TEST) {
    std::string config_path(CONFIG_PATH);
    milvus::server::Config& config = milvus::server::Config::GetInstance();
    milvus::Status s;

C
Cai Yudong 已提交
484
    ASSERT_FALSE(config.LoadConfigFile("").ok());
Z
Zhiru Zhu 已提交
485

C
Cai Yudong 已提交
486 487
    ASSERT_FALSE(config.LoadConfigFile(config_path + INVALID_CONFIG_FILE).ok());
    ASSERT_FALSE(config.LoadConfigFile(config_path + "dummy.yaml").ok());
Z
Zhiru Zhu 已提交
488 489

    /* server config */
C
Cai Yudong 已提交
490 491
    ASSERT_FALSE(config.SetServerConfigAddress("0.0.0").ok());
    ASSERT_FALSE(config.SetServerConfigAddress("0.0.0.256").ok());
Z
Zhiru Zhu 已提交
492

C
Cai Yudong 已提交
493 494
    ASSERT_FALSE(config.SetServerConfigPort("a").ok());
    ASSERT_FALSE(config.SetServerConfigPort("99999").ok());
Z
Zhiru Zhu 已提交
495

B
BossZou 已提交
496 497 498 499
    ASSERT_FALSE(config.SetServerConfigWebPort("a").ok());
    ASSERT_FALSE(config.SetServerConfigWebPort("99999").ok());
    ASSERT_FALSE(config.SetServerConfigWebPort("-1").ok());

C
Cai Yudong 已提交
500
    ASSERT_FALSE(config.SetServerConfigDeployMode("cluster").ok());
Z
Zhiru Zhu 已提交
501

C
Cai Yudong 已提交
502 503 504
    ASSERT_FALSE(config.SetServerConfigTimeZone("GM").ok());
    ASSERT_FALSE(config.SetServerConfigTimeZone("GMT8").ok());
    ASSERT_FALSE(config.SetServerConfigTimeZone("UTCA").ok());
Z
Zhiru Zhu 已提交
505 506

    /* db config */
C
Cai Yudong 已提交
507 508 509
    ASSERT_FALSE(config.SetDBConfigBackendUrl("http://www.google.com").ok());
    ASSERT_FALSE(config.SetDBConfigBackendUrl("sqlite://:@:").ok());
    ASSERT_FALSE(config.SetDBConfigBackendUrl("mysql://root:123456@127.0.0.1/milvus").ok());
Z
Zhiru Zhu 已提交
510

C
Cai Yudong 已提交
511
    ASSERT_FALSE(config.SetDBConfigArchiveDiskThreshold("0x10").ok());
Z
Zhiru Zhu 已提交
512

C
Cai Yudong 已提交
513
    ASSERT_FALSE(config.SetDBConfigArchiveDaysThreshold("0x10").ok());
Z
Zhiru Zhu 已提交
514

C
Cai Yudong 已提交
515
    /* storage config */
516 517 518 519
    ASSERT_FALSE(config.SetStorageConfigPrimaryPath("").ok());

    // ASSERT_FALSE(config.SetStorageConfigSecondaryPath("").ok());

520
    ASSERT_FALSE(config.SetStorageConfigS3Enable("10").ok());
C
Cai Yudong 已提交
521

522
    ASSERT_FALSE(config.SetStorageConfigS3Address("127.0.0").ok());
C
Cai Yudong 已提交
523

524 525
    ASSERT_FALSE(config.SetStorageConfigS3Port("100").ok());
    ASSERT_FALSE(config.SetStorageConfigS3Port("100000").ok());
C
Cai Yudong 已提交
526

527
    ASSERT_FALSE(config.SetStorageConfigS3AccessKey("").ok());
C
Cai Yudong 已提交
528

529
    ASSERT_FALSE(config.SetStorageConfigS3SecretKey("").ok());
C
Cai Yudong 已提交
530

531
    ASSERT_FALSE(config.SetStorageConfigS3Bucket("").ok());
Z
Zhiru Zhu 已提交
532 533

    /* metric config */
C
Cai Yudong 已提交
534
    ASSERT_FALSE(config.SetMetricConfigEnableMonitor("Y").ok());
Z
Zhiru Zhu 已提交
535

C
Cai Yudong 已提交
536
    ASSERT_FALSE(config.SetMetricConfigAddress("127.0.0").ok());
537

C
Cai Yudong 已提交
538
    ASSERT_FALSE(config.SetMetricConfigPort("0xff").ok());
Z
Zhiru Zhu 已提交
539 540

    /* cache config */
C
Cai Yudong 已提交
541 542 543
    ASSERT_FALSE(config.SetCacheConfigCpuCacheCapacity("a").ok());
    ASSERT_FALSE(config.SetCacheConfigCpuCacheCapacity("0").ok());
    ASSERT_FALSE(config.SetCacheConfigCpuCacheCapacity("2048").ok());
544
    ASSERT_FALSE(config.SetCacheConfigCpuCacheCapacity("-1").ok());
Z
Zhiru Zhu 已提交
545

C
Cai Yudong 已提交
546 547
    ASSERT_FALSE(config.SetCacheConfigCpuCacheThreshold("a").ok());
    ASSERT_FALSE(config.SetCacheConfigCpuCacheThreshold("1.0").ok());
548 549 550 551 552 553
    ASSERT_FALSE(config.SetCacheConfigCpuCacheThreshold("-0.1").ok());

    ASSERT_FALSE(config.SetCacheConfigInsertBufferSize("a").ok());
    ASSERT_FALSE(config.SetCacheConfigInsertBufferSize("0").ok());
    ASSERT_FALSE(config.SetCacheConfigInsertBufferSize("2048").ok());
    ASSERT_FALSE(config.SetCacheConfigInsertBufferSize("-1").ok());
Z
Zhiru Zhu 已提交
554

C
Cai Yudong 已提交
555
    ASSERT_FALSE(config.SetCacheConfigCacheInsertData("N").ok());
Z
Zhiru Zhu 已提交
556 557

    /* engine config */
C
Cai Yudong 已提交
558
    ASSERT_FALSE(config.SetEngineConfigUseBlasThreshold("0xff").ok());
Z
Zhiru Zhu 已提交
559

C
Cai Yudong 已提交
560 561
    ASSERT_FALSE(config.SetEngineConfigOmpThreadNum("a").ok());
    ASSERT_FALSE(config.SetEngineConfigOmpThreadNum("10000").ok());
562
    ASSERT_FALSE(config.SetEngineConfigOmpThreadNum("-10").ok());
Z
Zhiru Zhu 已提交
563

G
groot 已提交
564
#ifdef MILVUS_GPU_VERSION
C
Cai Yudong 已提交
565 566
    ASSERT_FALSE(config.SetEngineConfigGpuSearchThreshold("-1").ok());
#endif
Z
Zhiru Zhu 已提交
567

G
groot 已提交
568
    /* gpu resource config */
C
Cai Yudong 已提交
569 570
#ifdef MILVUS_GPU_VERSION
    ASSERT_FALSE(config.SetGpuResourceConfigEnable("ok").ok());
Z
Zhiru Zhu 已提交
571

C
Cai Yudong 已提交
572 573
    ASSERT_FALSE(config.SetGpuResourceConfigCacheCapacity("a").ok());
    ASSERT_FALSE(config.SetGpuResourceConfigCacheCapacity("128").ok());
574
    ASSERT_FALSE(config.SetGpuResourceConfigCacheCapacity("-1").ok());
Z
Zhiru Zhu 已提交
575

C
Cai Yudong 已提交
576 577
    ASSERT_FALSE(config.SetGpuResourceConfigCacheThreshold("a").ok());
    ASSERT_FALSE(config.SetGpuResourceConfigCacheThreshold("1.0").ok());
578
    ASSERT_FALSE(config.SetGpuResourceConfigCacheThreshold("-0.1").ok());
Z
Zhiru Zhu 已提交
579

C
Cai Yudong 已提交
580
    ASSERT_FALSE(config.SetGpuResourceConfigSearchResources("gpu10").ok());
581

C
Cai Yudong 已提交
582 583
    ASSERT_FALSE(config.SetGpuResourceConfigBuildIndexResources("gup2").ok());
    ASSERT_FALSE(config.SetGpuResourceConfigBuildIndexResources("gpu16").ok());
Y
yudong.cai 已提交
584
#endif
Z
Zhiru Zhu 已提交
585 586
}

S
starlord 已提交
587
TEST_F(ConfigTest, SERVER_CONFIG_TEST) {
S
starlord 已提交
588
    std::string config_path(CONFIG_PATH);
S
starlord 已提交
589
    milvus::server::Config& config = milvus::server::Config::GetInstance();
G
groot 已提交
590

C
Cai Yudong 已提交
591 592 593
    ASSERT_TRUE(config.LoadConfigFile(config_path + VALID_CONFIG_FILE).ok());

    ASSERT_TRUE(config.ValidateConfig().ok());
S
starlord 已提交
594

595 596 597
    std::string config_json_str;
    config.GetConfigJsonStr(config_json_str);
    std::cout << config_json_str << std::endl;
Y
yudong.cai 已提交
598

C
Cai Yudong 已提交
599
    ASSERT_TRUE(config.ResetDefaultConfig().ok());
S
starlord 已提交
600
}