Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print version information when the program starts #112

Closed
dxsup opened this issue Mar 15, 2022 · 6 comments
Closed

Print version information when the program starts #112

dxsup opened this issue Mar 15, 2022 · 6 comments
Labels
area/collector Issues or PRs related to agent metric collector area/probe Issues or PRs related to agent probe

Comments

@dxsup
Copy link
Member

dxsup commented Mar 15, 2022

Is your feature request related to a problem? Please describe.
Whenever an error occurs, we want to know clearly which version of codes the agent is on. But now there is no such information printed by the collector and only an outdated KINDLING_PROBE_VERSION: v0.1-2021-1221 printed by the probe. We can't know the exact versions of them now.

Describe the solution you'd like
The best version information is the combination of the release version and the commit revision number, IMO. We could insert these numbers as environment variables when we build the containers and print them periodically while the agent is running.

Additional context
Any ideas about how we could get this information are appreciated.

@dxsup dxsup added area/probe Issues or PRs related to agent probe area/collector Issues or PRs related to agent metric collector labels Mar 15, 2022
@zjuzzb
Copy link
Collaborator

zjuzzb commented Mar 17, 2022

I find a solution for adding build numbers from git, take a look at this.

@dxsup
Copy link
Member Author

dxsup commented Mar 17, 2022

I find a solution for adding build numbers from git, take a look at this.

Looks great! I think it is what we want. We could insert it as a parameter when building the collector, like go build -ldflags -X main.githash=xxx. Do you have any idea about how we insert it into the probe?

@zjuzzb
Copy link
Collaborator

zjuzzb commented Mar 17, 2022

Looks great! I think it is what we want. We could insert it as a parameter when building the collector, like `go build -ldflags -X main.githash=xxx". Do you have any idea about how we insert it into the probe?

add_definitions(-DBUILD_NUMBER)
find_package(Git)
if(GIT_FOUND)
    execute_process(
            COMMAND ${GIT_EXECUTABLE} describe --match build
            OUTPUT_VARIABLE BUILD_NUMBER
            OUTPUT_STRIP_TRAILING_WHITESPACE)
    add_definitions(-DBUILD_NUMBER=\ "${BUILD_NUMBER}\")
endif()

Add this code into CMakeLists.txt of probe, then just use BUILD_NUMBER macro in the source code.

@dxsup
Copy link
Member Author

dxsup commented Mar 17, 2022

add_definitions(-DBUILD_NUMBER)
find_package(Git)
if(GIT_FOUND)
    execute_process(
            COMMAND ${GIT_EXECUTABLE} describe --match build
            OUTPUT_VARIABLE BUILD_NUMBER
            OUTPUT_STRIP_TRAILING_WHITESPACE)
    add_definitions(-DBUILD_NUMBER=\ "${BUILD_NUMBER}\")
endif()

Add this code into CMakeLists.txt of probe, then just use BUILD_NUMBER macro in the source code.

But now we are compiling the probe using Bazel, is there any similar method? @jundizhou

@sugary199
Copy link
Contributor

I haven't found a way to inject version information into a program with bazel. Maybe we can generate a header file with a .sh file like this

commit_ts=`git log -1 --format="%ct"`
commit_time=`date -d@$commit_ts +"%Y-%m-%d %H:%M:%S"`
current_time=`date +"%Y-%m-%d %H:%M:%S"`
git_version=`git log -1 --format="%h"`
build_number=`git describe`
sed  s/MYVERSION/"version: $build_number commit: $commit_time build: $current_time"/g version.h.tmp > version.h
make clean
make

There will be a macro in the generated header file

#ifndef _VERSION_
#define _VERSION_ "version: build01-5-g4e4dc12 commit: 2022-03-22 12:57:52 build: 2022-03-22 13:01:26"
#endif

Would it work in our project?

@dxsup
Copy link
Member Author

dxsup commented Jun 27, 2022

The version of the probe is not needed after merging #264 because there is only one process now. The collector and the probe share the same codebase and the commit id has been printed by the collector.

@dxsup dxsup closed this as completed Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/collector Issues or PRs related to agent metric collector area/probe Issues or PRs related to agent probe
Projects
None yet
Development

No branches or pull requests

3 participants