test_config.cpp 14.7 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.

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

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

G
groot 已提交
28 29
namespace {

S
starlord 已提交
30
static constexpr uint64_t KB = 1024;
S
starlord 已提交
31 32
static constexpr uint64_t MB = KB * 1024;
static constexpr uint64_t GB = MB * 1024;
S
starlord 已提交
33

S
starlord 已提交
34
} // namespace
G
groot 已提交
35

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

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

S
starlord 已提交
42
    std::string config_path(CONFIG_PATH);
S
starlord 已提交
43
    s = config_mgr->LoadConfigFile(config_path + INVALID_CONFIG_FILE);
Y
yudong.cai 已提交
44
    ASSERT_FALSE(s.ok());
G
groot 已提交
45

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

G
groot 已提交
49 50
    config_mgr->Print();

S
starlord 已提交
51 52 53 54 55
    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 已提交
56
    milvus::server::ConfigNode invalid_config = root_config.GetChild("invalid_config");
S
starlord 已提交
57 58 59
    auto valus = invalid_config.GetSequence("not_exist");
    float ff = invalid_config.GetFloatValue("not_exist", 3.0);
    ASSERT_EQ(ff, 3.0);
G
groot 已提交
60 61 62 63

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

    server_config.SetValue("test", "2.5");
    double test = server_config.GetDoubleValue("test");
    ASSERT_EQ(test, 2.5);

S
starlord 已提交
70
    milvus::server::ConfigNode fake;
G
groot 已提交
71 72
    server_config.AddChild("fake", fake);
    fake = server_config.GetChild("fake");
S
starlord 已提交
73
    milvus::server::ConfigNodeArr arr;
G
groot 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    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 已提交
90
    milvus::server::ConfigNode combine;
G
groot 已提交
91 92 93 94 95 96
    combine.Combine(server_config);

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

G
groot 已提交
97 98 99 100 101
    server_config.ClearSequences();
    auto seqs = server_config.GetSequences();
    ASSERT_TRUE(seqs.empty());
}

102
TEST_F(ConfigTest, SERVER_CONFIG_VALID_TEST) {
S
starlord 已提交
103
    std::string config_path(CONFIG_PATH);
104 105 106 107 108 109 110 111 112 113 114 115 116
    milvus::server::Config &config = milvus::server::Config::GetInstance();
    milvus::Status s;
    std::string str_val;
    int32_t int32_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);
Y
yudong.cai 已提交
117
    ASSERT_TRUE(s.ok());
118
    ASSERT_TRUE(str_val == server_addr);
G
groot 已提交
119

120 121
    std::string server_port = "12345";
    s = config.SetServerConfigPort(server_port);
Y
yudong.cai 已提交
122
    ASSERT_TRUE(s.ok());
123 124 125
    s = config.GetServerConfigPort(str_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(str_val == server_port);
S
starlord 已提交
126

127 128 129 130 131 132
    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);
Y
yudong.cai 已提交
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 179 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 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
    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);

    int32_t db_archive_disk_threshold = 100;
    s = config.SetDBConfigArchiveDiskThreshold(std::to_string(db_archive_disk_threshold));
    ASSERT_TRUE(s.ok());
    s = config.GetDBConfigArchiveDiskThreshold(int32_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(int32_val == db_archive_disk_threshold);

    int32_t db_archive_days_threshold = 365;
    s = config.SetDBConfigArchiveDaysThreshold(std::to_string(db_archive_days_threshold));
    ASSERT_TRUE(s.ok());
    s = config.GetDBConfigArchiveDaysThreshold(int32_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(int32_val == db_archive_days_threshold);

    int32_t db_insert_buffer_size = 2;
    s = config.SetDBConfigInsertBufferSize(std::to_string(db_insert_buffer_size));
    ASSERT_TRUE(s.ok());
    s = config.GetDBConfigInsertBufferSize(int32_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(int32_val == db_insert_buffer_size);

    /* 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 */
    int64_t cache_cpu_cache_capacity = 5;
    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);

    int64_t cache_gpu_cache_capacity = 1;
    s = config.SetCacheConfigGpuCacheCapacity(std::to_string(cache_gpu_cache_capacity));
    ASSERT_TRUE(s.ok());
    s = config.GetCacheConfigGpuCacheCapacity(int64_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(int64_val == cache_gpu_cache_capacity);

    float cache_gpu_cache_threshold = 0.2;
    s = config.SetCacheConfigGpuCacheThreshold(std::to_string(cache_gpu_cache_threshold));
    ASSERT_TRUE(s.ok());
    s = config.GetCacheConfigGpuCacheThreshold(float_val);
    ASSERT_TRUE(float_val == cache_gpu_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 */
    int32_t engine_use_blas_threshold = 50;
    s = config.SetEngineConfigUseBlasThreshold(std::to_string(engine_use_blas_threshold));
    ASSERT_TRUE(s.ok());
    s = config.GetEngineConfigUseBlasThreshold(int32_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(int32_val == engine_use_blas_threshold);

    int32_t engine_omp_thread_num = 8;
    s = config.SetEngineConfigOmpThreadNum(std::to_string(engine_omp_thread_num));
    ASSERT_TRUE(s.ok());
    s = config.GetEngineConfigOmpThreadNum(int32_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(int32_val == engine_omp_thread_num);

    int32_t engine_gpu_search_threshold = 800;
    s = config.SetEngineConfigGpuSearchThreshold(std::to_string(engine_gpu_search_threshold));
    ASSERT_TRUE(s.ok());
    s = config.GetEngineConfigGpuSearchThreshold(int32_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(int32_val == engine_gpu_search_threshold);

    /* resource config */
    std::string resource_mode = "simple";
    s = config.SetResourceConfigMode(resource_mode);
Y
yudong.cai 已提交
263
    ASSERT_TRUE(s.ok());
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
    s = config.GetResourceConfigMode(str_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(str_val == resource_mode);

    std::vector<std::string> search_resources = {"cpu", "gpu0"};
    std::vector<std::string> res_vec;
    std::string res_str;
    milvus::server::StringHelpFunctions::MergeStringWithDelimeter(search_resources,
            milvus::server::CONFIG_RESOURCE_SEARCH_RESOURCES_DELIMITER, res_str);
    s = config.SetResourceConfigSearchResources(res_str);
    ASSERT_TRUE(s.ok());
    s = config.GetResourceConfigSearchResources(res_vec);
    ASSERT_TRUE(s.ok());
    for (size_t i = 0; i < search_resources.size(); i++) {
        ASSERT_TRUE(search_resources[i] == res_vec[i]);
    }

    int32_t resource_index_build_device = 0;
    s = config.SetResourceConfigIndexBuildDevice("gpu" + std::to_string(resource_index_build_device));
    ASSERT_TRUE(s.ok());
    s = config.GetResourceConfigIndexBuildDevice(int32_val);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(int32_val == resource_index_build_device);
S
starlord 已提交
287
}
Y
yudong.cai 已提交
288 289 290 291 292 293 294 295 296 297 298

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());
Y
yudong.cai 已提交
299 300
    s = config.LoadConfigFile(config_path + "dummy.yaml");
    ASSERT_FALSE(s.ok());
Y
yudong.cai 已提交
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344

    /* 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());
Y
yudong.cai 已提交
345
    s = config.SetDBConfigInsertBufferSize("0");
Y
yudong.cai 已提交
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
    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());
Y
yudong.cai 已提交
363
    s = config.SetCacheConfigCpuCacheCapacity("0");
Y
yudong.cai 已提交
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
    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.SetCacheConfigGpuCacheCapacity("a");
    ASSERT_FALSE(s.ok());
    s = config.SetCacheConfigGpuCacheCapacity("128");
    ASSERT_FALSE(s.ok());

    s = config.SetCacheConfigGpuCacheThreshold("a");
    ASSERT_FALSE(s.ok());
    s = config.SetCacheConfigGpuCacheThreshold("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());
Y
yudong.cai 已提交
392
    s = config.SetEngineConfigOmpThreadNum("10000");
Y
yudong.cai 已提交
393 394 395 396 397 398 399 400 401
    ASSERT_FALSE(s.ok());

    s = config.SetEngineConfigGpuSearchThreshold("-1");
    ASSERT_FALSE(s.ok());

    /* resource config */
    s = config.SetResourceConfigMode("default");
    ASSERT_FALSE(s.ok());

402 403 404 405 406
    s = config.SetResourceConfigSearchResources("gpu10");
    ASSERT_FALSE(s.ok());
    s = config.SetResourceConfigSearchResources("cpu");
    ASSERT_FALSE(s.ok());

Y
yudong.cai 已提交
407 408 409 410
    s = config.SetResourceConfigIndexBuildDevice("gup2");
    ASSERT_FALSE(s.ok());
    s = config.SetResourceConfigIndexBuildDevice("gpu16");
    ASSERT_FALSE(s.ok());
Y
yudong.cai 已提交
411 412
}

413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
TEST_F(ConfigTest, SERVER_CONFIG_TEST) {
    std::string config_path(CONFIG_PATH);
    milvus::server::Config& config = milvus::server::Config::GetInstance();
    milvus::Status s = config.LoadConfigFile(config_path + VALID_CONFIG_FILE);
    ASSERT_TRUE(s.ok());

    s = config.ValidateConfig();
    ASSERT_TRUE(s.ok());

    config.PrintAll();

    s = config.ResetDefaultConfig();
    ASSERT_TRUE(s.ok());
}