Skip to content

Commit

Permalink
Add git commit id (#82)
Browse files Browse the repository at this point in the history
* add git commit id and binary built time

* adjust log output format
  • Loading branch information
JackyWoo authored Aug 16, 2023
1 parent 38afa50 commit 3438d13
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
7 changes: 6 additions & 1 deletion base/daemon/BaseDaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,12 @@ void BaseDaemon::initializeTerminationAndSignalProcessing()

void BaseDaemon::logRevision() const
{
Poco::Logger::root().information("Starting " + std::string{VERSION_FULL} + ", " + build_id_info + ", PID " + std::to_string(getpid()));
Poco::Logger::root().information(
"Starting " + std::string{VERSION_FULL}
+ ", git commit hash: " + std::string{GIT_COMMIT_HASH}
+ ", binary built on: " + std::string{BUILD_TIME}
+ ", binary built id: " + build_id_info
+ ", PID: " + std::to_string(getpid()));
}

void BaseDaemon::defineOptions(Poco::Util::OptionSet & new_options)
Expand Down
22 changes: 22 additions & 0 deletions cmake/version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,25 @@ set (VERSION_NAME "${PROJECT_NAME}")
set (VERSION_FULL "${VERSION_NAME} ${VERSION_STRING}")

math (EXPR VERSION_INTEGER "${VERSION_PATCH} + ${VERSION_MINOR}*1000 + ${VERSION_MAJOR}*1000000")

find_package(Git QUIET)
if (GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else ()
set(GIT_COMMIT_HASH "Unknown")
endif ()

find_program(DATE_CMD NAMES date)
if (DATE_CMD)
execute_process(
COMMAND ${DATE_CMD} "+%Y-%m-%d %H:%M:%S"
OUTPUT_VARIABLE BUILD_TIME
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else ()
set(BUILD_TIME, "Unknown")
endif ()
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ set (CONFIG_VERSION ${CMAKE_CURRENT_BINARY_DIR}/Common/config_version.h)
set (CONFIG_COMMON ${CMAKE_CURRENT_BINARY_DIR}/Common/config.h)

include (../cmake/version.cmake)
message (STATUS "Will build ${VERSION_FULL}")
message (STATUS "Will build ${VERSION_FULL} ${GIT_COMMIT_HASH}")
configure_file (Common/config.h.in ${CONFIG_COMMON})
configure_file (Common/config_version.h.in ${CONFIG_VERSION})

Expand Down
2 changes: 2 additions & 0 deletions src/Common/config_version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
#cmakedefine VERSION_STRING "@VERSION_STRING@"
#cmakedefine VERSION_FULL "@VERSION_FULL@"
#cmakedefine VERSION_INTEGER @VERSION_INTEGER@
#cmakedefine GIT_COMMIT_HASH "@GIT_COMMIT_HASH@"
#cmakedefine BUILD_TIME "@BUILD_TIME@"
10 changes: 9 additions & 1 deletion src/Service/FourLetterCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,15 @@ ConnectionStats stats = keeper_dispatcher.getKeeperConnectionStats();
const auto & state_machine = keeper_dispatcher.getStateMachine();

StringBuffer ret;
print(ret, "version", VERSION_FULL);

WriteBufferFromOwnString version;
writeText(VERSION_FULL, version);
writeText("-", version);
writeText(GIT_COMMIT_HASH, version);
writeText(", built on ", version);
writeText(BUILD_TIME, version);

print(ret, "version", version.str());

print(ret, "avg_latency", stats.getAvgLatency());
print(ret, "max_latency", stats.getMaxLatency());
Expand Down

0 comments on commit 3438d13

Please sign in to comment.