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

Version info is not compiled into binary #24

Closed
carlpett opened this issue Sep 16, 2016 · 15 comments · Fixed by #35
Closed

Version info is not compiled into binary #24

carlpett opened this issue Sep 16, 2016 · 15 comments · Fixed by #35
Labels
Milestone

Comments

@carlpett
Copy link
Collaborator

Noticed that version info is not compiled into the binary, so log lines don't show much. I'm guessing we're not doing all the things that is expected from prometheus/common? Since most prometheus tools use promu, maybe there is some magic there? For instance, the promu.yml file adds some ldflags: https://github.com/prometheus/promu/blob/master/.promu.yml

@carlpett
Copy link
Collaborator Author

Verified that it works if adding the ldflags. Then the question is how to do this in a reasonable way - the commandline becomes long enough that it is not something you'd want to write yourself.

The first solution that comes to mind is using promu, since that is used to build a lot of other things in the Prometheus ecosystem. Sadly, the windows support isn't that good. I've put a few hours on trying to fix it, but it is not all that simple (dependent libraries that basically only work on linux).

Another common approach is having a Makefile, but since this is quite a Windows oriented repo, I'm unsure if it is a good idea. I've had quite bad experiences with make on Windows, at least.

Third option is to just write some simple build script.

@martinlindhe Any strong opinions in this?

@carlpett carlpett added this to the 0.1 milestone Sep 17, 2016
@carlpett carlpett mentioned this issue Sep 17, 2016
4 tasks
@martinlindhe
Copy link
Collaborator

martinlindhe commented Sep 19, 2016

Something might be missing, but the prometheus hookup is this stuff: https://github.com/martinlindhe/wmi_exporter/blob/master/exporter.go#L109

wmi_exporter master = $ .\wmi_exporter.exe -version
wmi_exporter, version  (branch: , revision: )
  build user:
  build date:
  go version:       go1.7.1

Personally I'm a Makefile lover, so that works for me. (using http://scoop.sh, which packages http://www.equation.com/servlet/equation.cmd?fa=make myself)

Also, option 3: write a build script works for me. Assuming it must be written in powershell.

@carlpett
Copy link
Collaborator Author

The magic is supposed to happen here: https://github.com/prometheus/common/blob/master/version/info.go#L27. Building with -ldflags -X vendor/github.com/prometheus/common/version.version=0.1.2 and so on populates those values.

After messing about with it a bit more, I think promu would be best, if we can get it to work. I did a PR which has been merged, but still needs a few more. An iterim solution with a build script (or just hacking up the appveyor config - that is the most important case anyway) might be the way to get something working, though.

@carlpett
Copy link
Collaborator Author

I did a bit of testing to set everything directly in the AppVeyor config, which was not a pleasurable experience. I'll do a bit more hacking on promu and see if that is feasible

@martinlindhe
Copy link
Collaborator

Had a look too

If one add a VERSION containing 0.1.0 and a .promu.yml like

repository:
    path: github.com/martinlindhe/wmi_exporter
build:
    ldflags: |
        -X {{repoPath}}/vendor/github.com/prometheus/common/version.Version={{.Version}}
        -X {{repoPath}}/vendor/github.com/prometheus/common/version.Revision={{.Revision}}
        -X {{repoPath}}/vendor/github.com/prometheus/common/version.Branch={{.Branch}}
        -X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
        -X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
tarball:
    files:
        - LICENSE

then run

$ promu build -v .

edit the output command, which fails silently and remove the -extldflags "-static" part of command (double quotes mess up go command),
result is a binary with version info

wmi_exporter version-info % $ .\wmi_exporter.exe
time="2016-09-29T10:24:19+02:00" level=info msg="Enabled collectors: cpu, logical_disk, net, os" source="exporter.go:156"
time="2016-09-29T10:24:19+02:00" level=info msg="Starting WMI exporter (version=0.1.0, branch=version-info, revision=ef04d2c51c41ff8fa07dbe26565cd7e2750fe248)" source="exporter.go:167"
time="2016-09-29T10:24:19+02:00" level=info msg="Build context (go=go1.7.1, user=xxx, date=20160929-08:23:24)" source="exporter.go:168"
time="2016-09-29T10:24:19+02:00" level=info msg="Starting server on :9182" source="exporter.go:171"

@martinlindhe
Copy link
Collaborator

Also @carlpett reported issue upstream: prometheus/promu#44

@carlpett
Copy link
Collaborator Author

The problem as far as I understand is the go-shell library which makes some Linuxy assumptions (such as always executing /bin/sh), and not working great when those don't hold. Since Go does it's own pass of quoting in exec on Windows, there is extra confusion.
I'm surprised you actually got any output from promu - on my machine it silently fails to build at all...

@martinlindhe
Copy link
Collaborator

Yep. working on a patch for promu that removes much of dependency of go-shell.

@martinlindhe
Copy link
Collaborator

Regarding output, the -v switch to promu should enable verbose output.

@carlpett
Copy link
Collaborator Author

carlpett commented Sep 29, 2016

Yep. working on a patch for promu that removes much of dependency of go-shell.

Ah, you too? :) I'm probably not going to have time to do any more work on my patch until the weekend anyway, though, so if you're on it that is great!

@martinlindhe
Copy link
Collaborator

prometheus/promu#47

@martinlindhe
Copy link
Collaborator

Related: #32

@martinlindhe
Copy link
Collaborator

Sorry if i caused extra work, I should have asked for your progress before starting on this.

@carlpett
Copy link
Collaborator Author

No worries, and great work!

@martinlindhe
Copy link
Collaborator

Created a final pr #35 to make use of the version info by using promu in appveyor.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants