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

Add a -version flag #156

Open
mytlogos opened this issue Nov 16, 2022 · 1 comment
Open

Add a -version flag #156

mytlogos opened this issue Nov 16, 2022 · 1 comment

Comments

@mytlogos
Copy link

Steps for Reproduction

  1. Run pihole_exporter -version or any other possible equivalents

Expected behavior:
Return the current pihole_exporter version, at least just a line like pihole_exporter version x.x.x, at best something like what node_exporter --version outputs:

node_exporter, version 1.4.0 (branch: HEAD, revision: 7da1321761b3b8dfc9e496e1a60e6a476fec6018)
  build user:       root@83d90983e89c
  build date:       20220926-12:33:37
  go version:       go1.19.1
  platform:         linux/arm64

Actual behavior:
Outputs the cli help as an unknown flag was given.

Platforms:

  • every supported (at least arm64)

Include browser, operating system and respective versions

Versions:

Which versions are you running?
I do not know, but most likely the current latest, version 0.3.0.

Additional Info

Currently one cannot know what version of this software is being used, as it does not has a "-version" or "--version" flag, nor a /version endpoint nor does it expose its version in the /metrics endpoint.
Knowing the current used version is very helpful in e.g. deciding if a upgrade is necessary (e.g. for ansible).
As far as i know, node_exporter uses the prometheus/commons library to provide the output of the --version flag and it somehow works maybe with make? and the VERSION file in its repository, though i personally could not make out its specifics.

@mytlogos
Copy link
Author

mytlogos commented May 3, 2023

You can embed the current version when building, by using the ldflag "-X":

// main.go
var (
    version = ""
    commit = ""
    date = ""
)
go build -ldflags '-X main.version=0.5.0 -X main.commit=hash -X main.date=2023 -X main.builtBy=eko'

The -X ldflag sets variable values (not const i think), to specific values.
The variables is loaded by an import path like "main" for package main in main.go or for example github.com/eko/pihole-exporter/config.

I could try to provide a PR, by integrating it also in github action and the dockerfile.

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

No branches or pull requests

1 participant