Skip to content

Fix version flag #494

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

Merged
merged 1 commit into from
Mar 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 5 additions & 24 deletions cmd/postgres_exporter/postgres_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"net/url"
"os"
"regexp"
"runtime"
"strconv"
"strings"
"sync"
Expand All @@ -45,22 +44,6 @@ import (
"gopkg.in/yaml.v2"
)

// Branch is set during build to the git branch.
var Branch string

// BuildDate is set during build to the ISO-8601 date and time.
var BuildDate string

// Revision is set during build to the git commit revision.
var Revision string

// Version is set during build to the git describe version
// (semantic version)-(commitish) form.
var Version = "0.0.1-rev"

// VersionShort is set during build to the semantic version.
var VersionShort = "0.0.1"

var (
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9187").Envar("PG_EXPORTER_WEB_LISTEN_ADDRESS").String()
webConfig = webflag.AddFlags(kingpin.CommandLine)
Expand All @@ -82,6 +65,8 @@ const (
namespace = "pg"
// Subsystems.
exporter = "exporter"
// The name of the exporter.
exporterName = "postgres_exporter"
// Metric label used for static string data thats handy to send to Prometheus
// e.g. version
staticLabelName = "static"
Expand Down Expand Up @@ -1796,9 +1781,10 @@ func contains(a []string, x string) bool {
}

func main() {
kingpin.Version(fmt.Sprintf("postgres_exporter %s (built with %s)\n", Version, runtime.Version()))
kingpin.Version(version.Print(exporterName))
promlogConfig := &promlog.Config{}
flag.AddFlags(kingpin.CommandLine, promlogConfig)
kingpin.HelpFlag.Short('h')
kingpin.Parse()
logger = promlog.New(promlogConfig)

Expand Down Expand Up @@ -1843,12 +1829,7 @@ func main() {
exporter.servers.Close()
}()

// Setup build info metric.
version.Branch = Branch
version.BuildDate = BuildDate
version.Revision = Revision
version.Version = VersionShort
prometheus.MustRegister(version.NewCollector("postgres_exporter"))
prometheus.MustRegister(version.NewCollector(exporterName))

prometheus.MustRegister(exporter)

Expand Down