From 6f75d02c65ae56dc0f6f1c1e006b837cfcf0bbe1 Mon Sep 17 00:00:00 2001 From: Ten Thousand Leaves <69466447+soothing-rain@users.noreply.github.com> Date: Wed, 20 Apr 2022 17:23:46 +0800 Subject: [PATCH] Disable knowhere logging for embedded Milvus and some other tweaks (#16496) /kind enhancement issue: #15711 Signed-off-by: Yuchen Gao --- Makefile | 2 +- cmd/milvus/milvus.go | 16 +++++++++++----- internal/core/src/config/CMakeLists.txt | 6 ++++++ internal/core/src/config/ConfigKnowhere.cpp | 12 ++++++++++++ .../core/src/indexbuilder/VecIndexCreator.cpp | 3 ++- internal/proxy/authentication_interceptor.go | 2 +- internal/proxy/error.go | 4 ++-- internal/util/etcd/etcd_server.go | 1 + 8 files changed, 36 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index a0d6aaf0d8..4202473212 100644 --- a/Makefile +++ b/Makefile @@ -129,7 +129,7 @@ milvus: build-cpp print-build-info embd-milvus: build-cpp-embd print-build-info @echo "Building **Embedded** Milvus ..." @mkdir -p $(INSTALL_PATH) && go env -w CGO_ENABLED="1" && GO111MODULE=on $(GO) build \ - -ldflags="-X '$(OBJPREFIX).BuildTags=$(BUILD_TAGS)' -X '$(OBJPREFIX).BuildTime=$(BUILD_TIME)' -X '$(OBJPREFIX).GitCommit=$(GIT_COMMIT)' -X '$(OBJPREFIX).GoVersion=$(GO_VERSION)'" \ + -ldflags="-r /tmp/milvus/lib/ -X '$(OBJPREFIX).BuildTags=$(BUILD_TAGS)' -X '$(OBJPREFIX).BuildTime=$(BUILD_TIME)' -X '$(OBJPREFIX).GitCommit=$(GIT_COMMIT)' -X '$(OBJPREFIX).GoVersion=$(GO_VERSION)'" \ -buildmode=c-shared -o $(INSTALL_PATH)/embd-milvus.so $(PWD)/pkg/embedded/embedded.go 1>/dev/null build-go: milvus diff --git a/cmd/milvus/milvus.go b/cmd/milvus/milvus.go index 2480ff018b..9c7c94e8e2 100644 --- a/cmd/milvus/milvus.go +++ b/cmd/milvus/milvus.go @@ -189,20 +189,26 @@ func printUsage(w io.Writer, f *flag.Flag) { } // create runtime folder -func createRuntimeDir() string { +func createRuntimeDir(sType string) string { + var writer io.Writer + if sType == typeutil.EmbeddedRole { + writer = io.Discard + } else { + writer = os.Stderr + } runtimeDir := "/run/milvus" if runtime.GOOS == "windows" { runtimeDir = "run" if err := makeRuntimeDir(runtimeDir); err != nil { - fmt.Fprintf(os.Stderr, "Create runtime directory at %s failed\n", runtimeDir) + fmt.Fprintf(writer, "Create runtime directory at %s failed\n", runtimeDir) os.Exit(-1) } } else { if err := makeRuntimeDir(runtimeDir); err != nil { - fmt.Fprintf(os.Stderr, "Set runtime dir at %s failed, set it to /tmp/milvus directory\n", runtimeDir) + fmt.Fprintf(writer, "Set runtime dir at %s failed, set it to /tmp/milvus directory\n", runtimeDir) runtimeDir = "/tmp/milvus" if err = makeRuntimeDir(runtimeDir); err != nil { - fmt.Fprintf(os.Stderr, "Create runtime directory at %s failed\n", runtimeDir) + fmt.Fprintf(writer, "Create runtime directory at %s failed\n", runtimeDir) os.Exit(-1) } } @@ -311,7 +317,7 @@ func RunMilvus(args []string) { params.SetLogger(0) } - runtimeDir := createRuntimeDir() + runtimeDir := createRuntimeDir(serverType) filename := getPidFileName(serverType, svrAlias) switch command { case "run": diff --git a/internal/core/src/config/CMakeLists.txt b/internal/core/src/config/CMakeLists.txt index 08ed267216..f9ea8b053e 100644 --- a/internal/core/src/config/CMakeLists.txt +++ b/internal/core/src/config/CMakeLists.txt @@ -14,6 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. +option( EMBEDDED_MILVUS "Enable embedded Milvus" OFF ) + +if ( EMBEDDED_MILVUS ) + add_compile_definitions( EMBEDDED_MILVUS ) +endif() + set(CONFIG_SRC ConfigKnowhere.cpp ) diff --git a/internal/core/src/config/ConfigKnowhere.cpp b/internal/core/src/config/ConfigKnowhere.cpp index ae6554871c..b6d6ad3992 100644 --- a/internal/core/src/config/ConfigKnowhere.cpp +++ b/internal/core/src/config/ConfigKnowhere.cpp @@ -35,6 +35,18 @@ KnowhereInitImpl() { knowhere::KnowhereConfig::SetStatisticsLevel(0); el::Configurations el_conf; el_conf.setGlobally(el::ConfigurationType::Enabled, std::to_string(false)); +#if defined(EMBEDDED_MILVUS) + el::Configurations defaultConf; + defaultConf.setToDefault(); + // Disable all logs for embedded milvus. + defaultConf.set(el::Level::Trace, el::ConfigurationType::Enabled, "false"); + defaultConf.set(el::Level::Debug, el::ConfigurationType::Enabled, "false"); + defaultConf.set(el::Level::Info, el::ConfigurationType::Enabled, "false"); + defaultConf.set(el::Level::Warning, el::ConfigurationType::Enabled, "false"); + defaultConf.set(el::Level::Error, el::ConfigurationType::Enabled, "false"); + defaultConf.set(el::Level::Fatal, el::ConfigurationType::Enabled, "false"); + el::Loggers::reconfigureLogger("default", defaultConf); +#endif }; std::call_once(init_knowhere_once_, init); diff --git a/internal/core/src/indexbuilder/VecIndexCreator.cpp b/internal/core/src/indexbuilder/VecIndexCreator.cpp index 708e086bf0..12385812a1 100644 --- a/internal/core/src/indexbuilder/VecIndexCreator.cpp +++ b/internal/core/src/indexbuilder/VecIndexCreator.cpp @@ -165,7 +165,8 @@ VecIndexCreator::BuildWithoutIds(const knowhere::DatasetPtr& dataset) { } } auto conf_adapter = knowhere::AdapterMgr::GetInstance().GetAdapter(index_type); - std::cout << "Konwhere BuildWithoutIds config_ is " << config_ << std::endl; + // TODO: Use easylogging instead, if you really need to keep this log. + // std::cout << "Konwhere BuildWithoutIds config_ is " << config_ << std::endl; AssertInfo(conf_adapter->CheckTrain(config_, index_mode), "something wrong in index parameters!"); if (is_in_need_id_list(index_type)) { diff --git a/internal/proxy/authentication_interceptor.go b/internal/proxy/authentication_interceptor.go index 2fc9ab8b30..a06ed9b690 100644 --- a/internal/proxy/authentication_interceptor.go +++ b/internal/proxy/authentication_interceptor.go @@ -63,7 +63,7 @@ func AuthenticationInterceptor(ctx context.Context) (context.Context, error) { return nil, ErrMissingMetadata() } if globalMetaCache == nil { - return nil, ErrGlobalMetaCacheUninitialized() + return nil, ErrProxyNotReady() } // check: // 1. if rpc call from a member (like index/query/data component) diff --git a/internal/proxy/error.go b/internal/proxy/error.go index 9a3df0129f..63c45f34b6 100644 --- a/internal/proxy/error.go +++ b/internal/proxy/error.go @@ -80,6 +80,6 @@ func ErrUnauthenticated() error { return fmt.Errorf("unauthenticated: invalid credential") } -func ErrGlobalMetaCacheUninitialized() error { - return fmt.Errorf("internal: globalMetaCache not initialized") +func ErrProxyNotReady() error { + return fmt.Errorf("internal: Milvus Proxy is not ready yet. please wait") } diff --git a/internal/util/etcd/etcd_server.go b/internal/util/etcd/etcd_server.go index f261e5ea5d..c38be3f80a 100644 --- a/internal/util/etcd/etcd_server.go +++ b/internal/util/etcd/etcd_server.go @@ -45,6 +45,7 @@ func InitEtcdServer(etcdCfg *paramtable.EtcdConfig) error { cfg.LogLevel = etcdCfg.EtcdLogLevel e, err := embed.StartEtcd(cfg) if err != nil { + log.Error("failed to init embedded Etcd server", zap.Error(err)) initError = err } etcdServer = e