test_config.cpp 22.6 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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
TEST_F(ConfigTest, SERVER_CONFIG_VALID_TEST) {
    std::string config_path(CONFIG_PATH);
    milvus::server::Config& config = milvus::server::Config::GetInstance();
    milvus::Status s;
    std::string str_val;
    int64_t int64_val;
    float float_val;
    bool bool_val;

    /* server config */
    std::string server_addr = "192.168.1.155";
    s = config.SetServerConfigAddress(server_addr);
    ASSERT_TRUE(s.ok());
    s = config.GetServerConfigAddress(str_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(str_val == server_addr);

    std::string server_port = "12345";
    s = config.SetServerConfigPort(server_port);
    ASSERT_TRUE(s.ok());
    s = config.GetServerConfigPort(str_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(str_val == server_port);

    std::string server_mode = "cluster_readonly";
    s = config.SetServerConfigDeployMode(server_mode);
    ASSERT_TRUE(s.ok());
    s = config.GetServerConfigDeployMode(str_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(str_val == server_mode);

    std::string server_time_zone = "UTC+6";
    s = config.SetServerConfigTimeZone(server_time_zone);
    ASSERT_TRUE(s.ok());
    s = config.GetServerConfigTimeZone(str_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(str_val == server_time_zone);

    /* db config */
    std::string db_primary_path = "/home/zilliz";
    s = config.SetDBConfigPrimaryPath(db_primary_path);
    ASSERT_TRUE(s.ok());
    s = config.GetDBConfigPrimaryPath(str_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(str_val == db_primary_path);

    std::string db_secondary_path = "/home/zilliz";
    s = config.SetDBConfigSecondaryPath(db_secondary_path);
    ASSERT_TRUE(s.ok());
    s = config.GetDBConfigSecondaryPath(str_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(str_val == db_secondary_path);

    std::string db_backend_url = "mysql://root:123456@127.0.0.1:19530/milvus";
    s = config.SetDBConfigBackendUrl(db_backend_url);
    ASSERT_TRUE(s.ok());
    s = config.GetDBConfigBackendUrl(str_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(str_val == db_backend_url);

Y
yudong.cai 已提交
179
    int64_t db_archive_disk_threshold = 100;
Z
Zhiru Zhu 已提交
180 181
    s = config.SetDBConfigArchiveDiskThreshold(std::to_string(db_archive_disk_threshold));
    ASSERT_TRUE(s.ok());
Y
yudong.cai 已提交
182
    s = config.GetDBConfigArchiveDiskThreshold(int64_val);
Z
Zhiru Zhu 已提交
183
    ASSERT_TRUE(s.ok());
Y
yudong.cai 已提交
184
    ASSERT_TRUE(int64_val == db_archive_disk_threshold);
Z
Zhiru Zhu 已提交
185

Y
yudong.cai 已提交
186
    int64_t db_archive_days_threshold = 365;
Z
Zhiru Zhu 已提交
187 188
    s = config.SetDBConfigArchiveDaysThreshold(std::to_string(db_archive_days_threshold));
    ASSERT_TRUE(s.ok());
Y
yudong.cai 已提交
189
    s = config.GetDBConfigArchiveDaysThreshold(int64_val);
Z
Zhiru Zhu 已提交
190
    ASSERT_TRUE(s.ok());
Y
yudong.cai 已提交
191
    ASSERT_TRUE(int64_val == db_archive_days_threshold);
Z
Zhiru Zhu 已提交
192

Y
yudong.cai 已提交
193
    int64_t db_insert_buffer_size = 2;
Z
Zhiru Zhu 已提交
194 195
    s = config.SetDBConfigInsertBufferSize(std::to_string(db_insert_buffer_size));
    ASSERT_TRUE(s.ok());
Y
yudong.cai 已提交
196
    s = config.GetDBConfigInsertBufferSize(int64_val);
Z
Zhiru Zhu 已提交
197
    ASSERT_TRUE(s.ok());
Y
yudong.cai 已提交
198
    ASSERT_TRUE(int64_val == db_insert_buffer_size);
Z
Zhiru Zhu 已提交
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221

    /* metric config */
    bool metric_enable_monitor = false;
    s = config.SetMetricConfigEnableMonitor(std::to_string(metric_enable_monitor));
    ASSERT_TRUE(s.ok());
    s = config.GetMetricConfigEnableMonitor(bool_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(bool_val == metric_enable_monitor);

    std::string metric_collector = "prometheus";
    s = config.SetMetricConfigCollector(metric_collector);
    ASSERT_TRUE(s.ok());
    s = config.GetMetricConfigCollector(str_val);
    ASSERT_TRUE(str_val == metric_collector);

    std::string metric_prometheus_port = "2222";
    s = config.SetMetricConfigPrometheusPort(metric_prometheus_port);
    ASSERT_TRUE(s.ok());
    s = config.GetMetricConfigPrometheusPort(str_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(str_val == metric_prometheus_port);

    /* cache config */
Y
yukun 已提交
222
    int64_t cache_cpu_cache_capacity = 1;
Z
Zhiru Zhu 已提交
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
    s = config.SetCacheConfigCpuCacheCapacity(std::to_string(cache_cpu_cache_capacity));
    ASSERT_TRUE(s.ok());
    s = config.GetCacheConfigCpuCacheCapacity(int64_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(int64_val == cache_cpu_cache_capacity);

    float cache_cpu_cache_threshold = 0.1;
    s = config.SetCacheConfigCpuCacheThreshold(std::to_string(cache_cpu_cache_threshold));
    ASSERT_TRUE(s.ok());
    s = config.GetCacheConfigCpuCacheThreshold(float_val);
    ASSERT_TRUE(float_val == cache_cpu_cache_threshold);

    bool cache_insert_data = true;
    s = config.SetCacheConfigCacheInsertData(std::to_string(cache_insert_data));
    ASSERT_TRUE(s.ok());
    s = config.GetCacheConfigCacheInsertData(bool_val);
    ASSERT_TRUE(bool_val == cache_insert_data);

    /* engine config */
Y
yudong.cai 已提交
242
    int64_t engine_use_blas_threshold = 50;
Z
Zhiru Zhu 已提交
243 244
    s = config.SetEngineConfigUseBlasThreshold(std::to_string(engine_use_blas_threshold));
    ASSERT_TRUE(s.ok());
Y
yudong.cai 已提交
245
    s = config.GetEngineConfigUseBlasThreshold(int64_val);
Z
Zhiru Zhu 已提交
246
    ASSERT_TRUE(s.ok());
Y
yudong.cai 已提交
247
    ASSERT_TRUE(int64_val == engine_use_blas_threshold);
Z
Zhiru Zhu 已提交
248

Y
yukun 已提交
249
    int64_t engine_omp_thread_num = 1;
Z
Zhiru Zhu 已提交
250 251
    s = config.SetEngineConfigOmpThreadNum(std::to_string(engine_omp_thread_num));
    ASSERT_TRUE(s.ok());
Y
yudong.cai 已提交
252
    s = config.GetEngineConfigOmpThreadNum(int64_val);
Z
Zhiru Zhu 已提交
253
    ASSERT_TRUE(s.ok());
Y
yudong.cai 已提交
254
    ASSERT_TRUE(int64_val == engine_omp_thread_num);
Z
Zhiru Zhu 已提交
255

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

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

Y
yudong.cai 已提交
272 273 274 275 276 277 278 279 280 281 282 283 284 285
    int64_t gpu_cache_capacity = 1;
    s = config.SetGpuResourceConfigCacheCapacity(std::to_string(gpu_cache_capacity));
    ASSERT_TRUE(s.ok());
    s = config.GetGpuResourceConfigCacheCapacity(int64_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(int64_val == gpu_cache_capacity);

    float gpu_cache_threshold = 0.2;
    s = config.SetGpuResourceConfigCacheThreshold(std::to_string(gpu_cache_threshold));
    ASSERT_TRUE(s.ok());
    s = config.GetGpuResourceConfigCacheThreshold(float_val);
    ASSERT_TRUE(float_val == gpu_cache_threshold);

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

Y
yudong.cai 已提交
298
    std::vector<std::string> build_index_resources = {"gpu0"};
Y
yudong.cai 已提交
299
    std::vector<int64_t> build_index_res_vec;
Y
yudong.cai 已提交
300
    std::string build_index_res_str;
301
    milvus::server::StringHelpFunctions::MergeStringWithDelimeter(
Y
yudong.cai 已提交
302 303
        build_index_resources, milvus::server::CONFIG_GPU_RESOURCE_DELIMITER, build_index_res_str);
    s = config.SetGpuResourceConfigBuildIndexResources(build_index_res_str);
Z
Zhiru Zhu 已提交
304
    ASSERT_TRUE(s.ok());
Y
yudong.cai 已提交
305
    s = config.GetGpuResourceConfigBuildIndexResources(build_index_res_vec);
Z
Zhiru Zhu 已提交
306
    ASSERT_TRUE(s.ok());
Y
yudong.cai 已提交
307
    for (size_t i = 0; i < build_index_resources.size(); i++) {
Y
yudong.cai 已提交
308
        ASSERT_TRUE(std::stoll(build_index_resources[i].substr(3)) == build_index_res_vec[i]);
309
    }
Y
yudong.cai 已提交
310
#endif
Z
Zhiru Zhu 已提交
311 312
}

C
Cai Yudong 已提交
313
std::string gen_get_command(const std::string& parent_node, const std::string& child_node) {
314
    std::string cmd = "get_config " + parent_node + ms::CONFIG_NODE_DELIMITER + child_node;
C
Cai Yudong 已提交
315 316 317 318
    return cmd;
}

std::string gen_set_command(const std::string& parent_node, const std::string& child_node, const std::string& value) {
319
    std::string cmd = "set_config " + parent_node + ms::CONFIG_NODE_DELIMITER + child_node + " " + value;
C
Cai Yudong 已提交
320 321 322 323 324 325 326 327 328 329 330
    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;

331 332 333
    s = config.ProcessConfigCli(result, "get_config *");
    ASSERT_TRUE(s.ok());

C
Cai Yudong 已提交
334 335 336 337
    /* 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);
338
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
339
    ASSERT_FALSE(s.ok());
340
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
341 342 343 344 345 346
    ASSERT_TRUE(s.ok());

    /* db config */
    std::string db_primary_path = "/home/zilliz";
    get_cmd = gen_get_command(ms::CONFIG_DB, ms::CONFIG_DB_PRIMARY_PATH);
    set_cmd = gen_set_command(ms::CONFIG_DB, ms::CONFIG_DB_PRIMARY_PATH, db_primary_path);
347
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
348
    ASSERT_FALSE(s.ok());
349
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
350 351 352 353 354 355
    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);
356
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
357
    ASSERT_FALSE(s.ok());
358
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
359 360 361
    ASSERT_TRUE(s.ok());

    /* cache config */
Y
yukun 已提交
362
    std::string cache_cpu_cache_capacity = "1";
C
Cai Yudong 已提交
363 364
    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);
365
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
366
    ASSERT_TRUE(s.ok());
367
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
368 369 370 371 372 373
    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);
374
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
375
    ASSERT_TRUE(s.ok());
376
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
377 378 379 380 381
    ASSERT_TRUE(result == cache_cpu_cache_threshold);

    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);
382
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
383
    ASSERT_TRUE(s.ok());
384
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
385 386 387 388 389 390
    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);
391
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
392
    ASSERT_TRUE(s.ok());
393
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
394 395 396
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == engine_use_blas_threshold);

Y
yukun 已提交
397
    std::string engine_omp_thread_num = "1";
C
Cai Yudong 已提交
398 399
    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);
400
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
401
    ASSERT_TRUE(s.ok());
402
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
403 404 405 406 407 408 409
    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);
410
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
411
    ASSERT_TRUE(s.ok());
412
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
413 414 415 416 417 418 419
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == engine_gpu_search_threshold);

    /* gpu resource config */
    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);
420
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
421
    ASSERT_TRUE(s.ok());
422
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
423 424 425 426 427 428
    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);
429
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
430
    ASSERT_TRUE(s.ok());
431
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
432 433 434 435 436 437
    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);
438
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
439
    ASSERT_TRUE(s.ok());
440
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
441 442 443 444 445
    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);
446
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
447
    ASSERT_TRUE(s.ok());
448
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
449 450 451 452 453 454 455
    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);
456
    s = config.ProcessConfigCli(dummy, set_cmd);
C
Cai Yudong 已提交
457
    ASSERT_TRUE(s.ok());
458
    s = config.ProcessConfigCli(result, get_cmd);
C
Cai Yudong 已提交
459 460 461 462 463
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == build_index_resources);
#endif
}

Z
Zhiru Zhu 已提交
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
TEST_F(ConfigTest, SERVER_CONFIG_INVALID_TEST) {
    std::string config_path(CONFIG_PATH);
    milvus::server::Config& config = milvus::server::Config::GetInstance();
    milvus::Status s;

    s = config.LoadConfigFile("");
    ASSERT_FALSE(s.ok());

    s = config.LoadConfigFile(config_path + INVALID_CONFIG_FILE);
    ASSERT_FALSE(s.ok());
    s = config.LoadConfigFile(config_path + "dummy.yaml");
    ASSERT_FALSE(s.ok());

    /* server config */
    s = config.SetServerConfigAddress("0.0.0");
    ASSERT_FALSE(s.ok());
    s = config.SetServerConfigAddress("0.0.0.256");
    ASSERT_FALSE(s.ok());

    s = config.SetServerConfigPort("a");
    ASSERT_FALSE(s.ok());
    s = config.SetServerConfigPort("99999");
    ASSERT_FALSE(s.ok());

    s = config.SetServerConfigDeployMode("cluster");
    ASSERT_FALSE(s.ok());

    s = config.SetServerConfigTimeZone("GM");
    ASSERT_FALSE(s.ok());
    s = config.SetServerConfigTimeZone("GMT8");
    ASSERT_FALSE(s.ok());
    s = config.SetServerConfigTimeZone("UTCA");
    ASSERT_FALSE(s.ok());

    /* db config */
    s = config.SetDBConfigPrimaryPath("");
    ASSERT_FALSE(s.ok());

    //    s = config.SetDBConfigSecondaryPath("");
    //    ASSERT_FALSE(s.ok());

    s = config.SetDBConfigBackendUrl("http://www.google.com");
    ASSERT_FALSE(s.ok());
    s = config.SetDBConfigBackendUrl("sqlite://:@:");
    ASSERT_FALSE(s.ok());
    s = config.SetDBConfigBackendUrl("mysql://root:123456@127.0.0.1/milvus");
    ASSERT_FALSE(s.ok());

    s = config.SetDBConfigArchiveDiskThreshold("0x10");
    ASSERT_FALSE(s.ok());

    s = config.SetDBConfigArchiveDaysThreshold("0x10");
    ASSERT_FALSE(s.ok());

    s = config.SetDBConfigInsertBufferSize("a");
    ASSERT_FALSE(s.ok());
    s = config.SetDBConfigInsertBufferSize("0");
    ASSERT_FALSE(s.ok());
    s = config.SetDBConfigInsertBufferSize("2048");
    ASSERT_FALSE(s.ok());

    /* metric config */
    s = config.SetMetricConfigEnableMonitor("Y");
    ASSERT_FALSE(s.ok());

    s = config.SetMetricConfigCollector("zilliz");
    ASSERT_FALSE(s.ok());

    s = config.SetMetricConfigPrometheusPort("0xff");
    ASSERT_FALSE(s.ok());

    /* cache config */
    s = config.SetCacheConfigCpuCacheCapacity("a");
    ASSERT_FALSE(s.ok());
    s = config.SetCacheConfigCpuCacheCapacity("0");
    ASSERT_FALSE(s.ok());
    s = config.SetCacheConfigCpuCacheCapacity("2048");
    ASSERT_FALSE(s.ok());

    s = config.SetCacheConfigCpuCacheThreshold("a");
    ASSERT_FALSE(s.ok());
    s = config.SetCacheConfigCpuCacheThreshold("1.0");
    ASSERT_FALSE(s.ok());

    s = config.SetCacheConfigCacheInsertData("N");
    ASSERT_FALSE(s.ok());

    /* engine config */
    s = config.SetEngineConfigUseBlasThreshold("0xff");
    ASSERT_FALSE(s.ok());

    s = config.SetEngineConfigOmpThreadNum("a");
    ASSERT_FALSE(s.ok());
    s = config.SetEngineConfigOmpThreadNum("10000");
    ASSERT_FALSE(s.ok());

G
groot 已提交
560
#ifdef MILVUS_GPU_VERSION
Z
Zhiru Zhu 已提交
561 562 563
    s = config.SetEngineConfigGpuSearchThreshold("-1");
    ASSERT_FALSE(s.ok());

G
groot 已提交
564
    /* gpu resource config */
565
    s = config.SetGpuResourceConfigEnable("ok");
Z
Zhiru Zhu 已提交
566 567
    ASSERT_FALSE(s.ok());

Y
yudong.cai 已提交
568 569 570
    s = config.SetGpuResourceConfigCacheCapacity("a");
    ASSERT_FALSE(s.ok());
    s = config.SetGpuResourceConfigCacheCapacity("128");
Z
Zhiru Zhu 已提交
571 572
    ASSERT_FALSE(s.ok());

Y
yudong.cai 已提交
573 574 575
    s = config.SetGpuResourceConfigCacheThreshold("a");
    ASSERT_FALSE(s.ok());
    s = config.SetGpuResourceConfigCacheThreshold("1.0");
Z
Zhiru Zhu 已提交
576 577
    ASSERT_FALSE(s.ok());

Y
yudong.cai 已提交
578 579
    s = config.SetGpuResourceConfigSearchResources("gpu10");
    ASSERT_FALSE(s.ok());
580

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

S
starlord 已提交
588
TEST_F(ConfigTest, SERVER_CONFIG_TEST) {
S
starlord 已提交
589
    std::string config_path(CONFIG_PATH);
S
starlord 已提交
590
    milvus::server::Config& config = milvus::server::Config::GetInstance();
S
starlord 已提交
591
    milvus::Status s = config.LoadConfigFile(config_path + VALID_CONFIG_FILE);
Y
yudong.cai 已提交
592
    ASSERT_TRUE(s.ok());
G
groot 已提交
593

Y
yudong.cai 已提交
594 595
    s = config.ValidateConfig();
    ASSERT_TRUE(s.ok());
S
starlord 已提交
596

597 598 599
    std::string config_json_str;
    config.GetConfigJsonStr(config_json_str);
    std::cout << config_json_str << std::endl;
Y
yudong.cai 已提交
600 601 602

    s = config.ResetDefaultConfig();
    ASSERT_TRUE(s.ok());
S
starlord 已提交
603
}