From a59cfc414b69cdbedd13ee5eb7f1c78bf1d9948e Mon Sep 17 00:00:00 2001 From: Yee <2520865+yixinglu@users.noreply.github.com> Date: Thu, 31 Dec 2020 17:55:48 +0800 Subject: [PATCH] Add version configurations (#547) * Add version configure file * Set nebula build version * Rename stdout/stderr log * Fix build version error * Address comments * Restore stderrthreshold --- CMakeLists.txt | 2 ++ cmake/ConfigNebulaStorage.cmake | 6 ++++++ conf/nebula-graphd.conf.default | 4 ++-- conf/nebula-graphd.conf.production | 4 ++-- src/CMakeLists.txt | 1 + src/daemons/CMakeLists.txt | 1 + src/daemons/GraphDaemon.cpp | 3 ++- src/planner/test/CMakeLists.txt | 1 + src/service/QueryEngine.cpp | 3 ++- src/version/CMakeLists.txt | 15 ++++++++++++++ src/version/Version.cpp.in | 33 ++++++++++++++++++++++++++++++ src/version/Version.h | 21 +++++++++++++++++++ 12 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 src/version/CMakeLists.txt create mode 100644 src/version/Version.cpp.in create mode 100644 src/version/Version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3aeede99..26ae7d35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,7 @@ if(NOT NEBULA_COMMON_SOURCE_DIR) set(nebula_common_source_dir ${CMAKE_SOURCE_DIR}/modules/common) set(nebula_common_build_dir ${CMAKE_BINARY_DIR}/modules/common) else() + message(STATUS "NEBULA_COMMON_SOURCE_DIR: " ${NEBULA_COMMON_SOURCE_DIR}) set(nebula_common_source_dir ${NEBULA_COMMON_SOURCE_DIR}) if(NOT NEBULA_COMMON_BUILD_DIR) set(nebula_common_build_dir ${CMAKE_BINARY_DIR}/modules/common) @@ -117,6 +118,7 @@ if(ENABLE_BUILD_STORAGE) set(nebula_storage_source_dir ${CMAKE_SOURCE_DIR}/modules/storage) set(nebula_storage_build_dir ${CMAKE_BINARY_DIR}/modules/storage) else() + message(STATUS "NEBULA_STORAGE_SOURCE_DIR: " ${NEBULA_STORAGE_SOURCE_DIR}) set(nebula_storage_source_dir ${NEBULA_STORAGE_SOURCE_DIR}) if(NOT NEBULA_STORAGE_BUILD_DIR) set(nebula_storage_build_dir ${CMAKE_BINARY_DIR}/modules/storage) diff --git a/cmake/ConfigNebulaStorage.cmake b/cmake/ConfigNebulaStorage.cmake index a03e62ae..fdea5776 100644 --- a/cmake/ConfigNebulaStorage.cmake +++ b/cmake/ConfigNebulaStorage.cmake @@ -19,6 +19,11 @@ macro(config_nebula_storage) file(MAKE_DIRECTORY ${storage_build_dir}) endif() + if (NEBULA_BUILD_VERSION) + message(STATUS "NEBULA_BUILD_VERSION: " ${NEBULA_BUILD_VERSION}) + set(storage_build_version -DNEBULA_BUILD_VERSION=${NEBULA_BUILD_VERSION}) + endif() + execute_process( COMMAND ${CMAKE_COMMAND} @@ -40,6 +45,7 @@ macro(config_nebula_storage) -DENABLE_COMPRESSED_DEBUG_INFO=${ENABLE_COMPRESSED_DEBUG_INFO} -DNEBULA_USE_LINKER=${NEBULA_USE_LINKER} -DENABLE_GDB_SCRIPT_SECTION=${ENABLE_GDB_SCRIPT_SECTION} + ${storage_build_version} ${storage_source_dir} WORKING_DIRECTORY ${storage_build_dir} RESULT_VARIABLE cmake_status diff --git a/conf/nebula-graphd.conf.default b/conf/nebula-graphd.conf.default index c8e412fc..9b2cfebd 100644 --- a/conf/nebula-graphd.conf.default +++ b/conf/nebula-graphd.conf.default @@ -18,8 +18,8 @@ # Whether to redirect stdout and stderr to separate output files --redirect_stdout=true # Destination filename of stdout and stderr, which will also reside in log_dir. ---stdout_log_file=stdout.log ---stderr_log_file=stderr.log +--stdout_log_file=graphd-stdout.log +--stderr_log_file=graphd-stderr.log # Copy log messages at or above this level to stderr in addition to logfiles. The numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively. --stderrthreshold=2 diff --git a/conf/nebula-graphd.conf.production b/conf/nebula-graphd.conf.production index 107b19c9..4e00e984 100644 --- a/conf/nebula-graphd.conf.production +++ b/conf/nebula-graphd.conf.production @@ -18,8 +18,8 @@ # Whether to redirect stdout and stderr to separate output files --redirect_stdout=true # Destination filename of stdout and stderr, which will also reside in log_dir. ---stdout_log_file=stdout.log ---stderr_log_file=stderr.log +--stdout_log_file=graphd-stdout.log +--stderr_log_file=graphd-stderr.log # Copy log messages at or above this level to stderr in addition to logfiles. The numbers of severity levels INFO, WARNING, ERROR, and FATAL are 0, 1, 2, and 3, respectively. --stderrthreshold=2 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d364bce9..b87cd158 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,3 +14,4 @@ nebula_add_subdirectory(context) nebula_add_subdirectory(scheduler) nebula_add_subdirectory(visitor) nebula_add_subdirectory(optimizer) +nebula_add_subdirectory(version) diff --git a/src/daemons/CMakeLists.txt b/src/daemons/CMakeLists.txt index 446729f5..201505bc 100644 --- a/src/daemons/CMakeLists.txt +++ b/src/daemons/CMakeLists.txt @@ -9,6 +9,7 @@ nebula_add_executable( SOURCES GraphDaemon.cpp OBJECTS + $<TARGET_OBJECTS:version_obj> $<TARGET_OBJECTS:util_obj> $<TARGET_OBJECTS:service_obj> $<TARGET_OBJECTS:session_obj> diff --git a/src/daemons/GraphDaemon.cpp b/src/daemons/GraphDaemon.cpp index 63daa44f..73536cf3 100644 --- a/src/daemons/GraphDaemon.cpp +++ b/src/daemons/GraphDaemon.cpp @@ -18,6 +18,7 @@ #include "service/GraphFlags.h" #include "common/webservice/WebService.h" #include "common/time/TimeUtils.h" +#include "version/Version.h" using nebula::Status; using nebula::ProcessUtils; @@ -34,7 +35,7 @@ static void printHelp(const char *prog); DECLARE_string(flagfile); int main(int argc, char *argv[]) { - google::SetVersionString(nebula::versionString()); + google::SetVersionString(nebula::graph::versionString()); if (argc == 1) { printHelp(argv[0]); return EXIT_FAILURE; diff --git a/src/planner/test/CMakeLists.txt b/src/planner/test/CMakeLists.txt index 89f08e33..c7ea0322 100644 --- a/src/planner/test/CMakeLists.txt +++ b/src/planner/test/CMakeLists.txt @@ -35,6 +35,7 @@ nebula_add_test( $<TARGET_OBJECTS:common_conf_obj> $<TARGET_OBJECTS:common_file_based_cluster_id_man_obj> $<TARGET_OBJECTS:common_charset_obj> + $<TARGET_OBJECTS:version_obj> $<TARGET_OBJECTS:query_engine_obj> $<TARGET_OBJECTS:session_obj> $<TARGET_OBJECTS:graph_flags_obj> diff --git a/src/service/QueryEngine.cpp b/src/service/QueryEngine.cpp index 5cd34d11..a033fcde 100644 --- a/src/service/QueryEngine.cpp +++ b/src/service/QueryEngine.cpp @@ -14,6 +14,7 @@ #include "planner/PlannersRegister.h" #include "service/QueryInstance.h" #include "service/GraphFlags.h" +#include "version/Version.h" DECLARE_bool(local_config); DECLARE_bool(enable_optimizer); @@ -34,7 +35,7 @@ Status QueryEngine::init(std::shared_ptr<folly::IOThreadPoolExecutor> ioExecutor options.role_ = meta::cpp2::HostRole::GRAPH; std::string localIP = network::NetworkUtils::getIPv4FromDevice(FLAGS_listen_netdev).value(); options.localHost_ = HostAddr{localIP, FLAGS_port}; - options.gitInfoSHA_ = NEBULA_STRINGIFY(GIT_INFO_SHA); + options.gitInfoSHA_ = nebula::graph::gitInfoSha(); metaClient_ = std::make_unique<meta::MetaClient>(ioExecutor, std::move(addrs.value()), options); // load data try 3 time diff --git a/src/version/CMakeLists.txt b/src/version/CMakeLists.txt new file mode 100644 index 00000000..175cf4e4 --- /dev/null +++ b/src/version/CMakeLists.txt @@ -0,0 +1,15 @@ +# Copyright (c) 2020 vesoft inc. All rights reserved. +# +# This source code is licensed under Apache 2.0 License, +# attached with Common Clause Condition 1.0, found in the LICENSES directory. + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/Version.cpp.in + ${CMAKE_CURRENT_BINARY_DIR}/Version.cpp + ) + +nebula_add_library( + version_obj + OBJECT + ${CMAKE_CURRENT_BINARY_DIR}/Version.cpp + ) diff --git a/src/version/Version.cpp.in b/src/version/Version.cpp.in new file mode 100644 index 00000000..e24f65d1 --- /dev/null +++ b/src/version/Version.cpp.in @@ -0,0 +1,33 @@ +/* Copyright (c) 2020 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License, + * attached with Common Clause Condition 1.0, found in the LICENSES directory. + */ + +#include "version/Version.h" + +#include <folly/String.h> + +#cmakedefine NEBULA_BUILD_VERSION + +namespace nebula { +namespace graph { + +std::string gitInfoSha() { + return "@GIT_INFO_SHA@"; +} + +std::string versionString() { + std::string version; +#if defined(NEBULA_BUILD_VERSION) + version = folly::stringPrintf("%s, ", "@NEBULA_BUILD_VERSION@"); +#endif + version += folly::stringPrintf("Git: %s", gitInfoSha().c_str()); + version += folly::stringPrintf(", Build Time: %s %s", __DATE__, __TIME__); + version += "\nThis source code is licensed under Apache 2.0 License," + " attached with Common Clause Condition 1.0."; + return version; +} + +} // namespace graph +} // namespace nebula diff --git a/src/version/Version.h b/src/version/Version.h new file mode 100644 index 00000000..be40f870 --- /dev/null +++ b/src/version/Version.h @@ -0,0 +1,21 @@ +/* Copyright (c) 2020 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License, + * attached with Common Clause Condition 1.0, found in the LICENSES directory. + */ + +#ifndef VERSION_VERSION_H_ +#define VERSION_VERSION_H_ + +#include <string> + +namespace nebula { +namespace graph { + +std::string gitInfoSha(); +std::string versionString(); + +} // namespace graph +} // namespace nebula + +#endif // VERSION_VERSION_H_ -- GitLab