Windows_exporter: Version info is not compiled into binary

Created on 16 Sep 2016  路  15Comments  路  Source: prometheus-community/windows_exporter

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

bug

All 15 comments

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?

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.

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.

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

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"

Also @carlpett reported issue upstream: https://github.com/prometheus/promu/issues/44

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...

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

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

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!

Related: #32

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

No worries, and great work!

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

Was this page helpful?
0 / 5 - 0 ratings