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 version informations as a common package #38

Merged
merged 1 commit into from
May 3, 2016
Merged

Add version informations as a common package #38

merged 1 commit into from
May 3, 2016

Conversation

sdurrheimer
Copy link
Contributor

@sdurrheimer sdurrheimer commented May 1, 2016

Ref. prometheus/node_exporter#236

Usage as mentionned by @grobie

import (
    "flag"
    "fmt"
    "os"

    "github.com/prometheus/client_golang/prometheus"
    "github.com/prometheus/common/log"
    "github.com/prometheus/common/version"
)

func init() {
    prometheus.MustRegister(version.NewCollector("<program>"))
}

func main() {
    var showVersion = flag.Bool("version", false, "Print version information.")
    flat.Parse()

    if *showVersion {
        fmt.Fprintln(os.Stdout, version.Print("<program>"))
        os.exit(0)
    }

    log.Infoln("Starting <program>", version.Info())
    log.Infoln("Build context", version.BuildContext())
}

I had a second implementation, but it was a bit overkill for a single metric.

}

// VersionLog returns version, branch and revision information.
func VersionLog() string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess log might be a confusing name. Suggestions? VersionInfo?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version.Details()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about renaming :

  • version.Info() to version.Print() or version.PrintString().
  • version.VersionLog() to version.Info() or version.InfoString()
  • version.BuildLog() to version.BuildContext() or version.BuildString()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me. I'd go with the first version, the return type should make clear it's a string.

@grobie
Copy link
Member

grobie commented May 3, 2016

👍 very nice!

@sdurrheimer sdurrheimer merged commit dd586c1 into prometheus:master May 3, 2016
gouthamve pushed a commit to gouthamve/common that referenced this pull request Jul 22, 2018
'Churdown' -> 'Shutdown'.
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

Successfully merging this pull request may close these issues.

None yet

2 participants