Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion cmd/postgres_exporter/postgres_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,26 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"github.com/prometheus/common/version"
"gopkg.in/alecthomas/kingpin.v2"
"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"
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()
Expand Down Expand Up @@ -1641,6 +1654,13 @@ 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(exporter)

http.Handle(*metricPath, promhttp.Handler())
Expand Down
31 changes: 30 additions & 1 deletion magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,31 @@ var goDirs []string
var goPkgs []string
var goCmds []string

var branch = func() string {
if v := os.Getenv("BRANCH"); v != "" {
return v
}
out, _ := sh.Output("git", "rev-parse", "--abbrev-ref", "HEAD")

return out
}()

var buildDate = func() string {
if v := os.Getenv("BUILDDATE"); v != "" {
return v
}
return time.Now().Format("2006-01-02T15:04:05-0700")
}()

var revision = func() string {
if v := os.Getenv("REVISION"); v != "" {
return v
}
out, _ := sh.Output("git", "rev-parse", "HEAD")

return out
}()

var version = func() string {
if v := os.Getenv("VERSION"); v != "" {
return v
Expand Down Expand Up @@ -533,7 +558,11 @@ func IntegrationTestBinary() error {
if (changed && (err == nil)) || os.IsNotExist(err) {
return sh.RunWith(map[string]string{"CGO_ENABLED": "0"}, "go", "test", "./cmd/postgres_exporter",
"-c", "-tags", "integration",
"-a", "-ldflags", "-extldflags '-static'", "-X", fmt.Sprintf("main.Version=%s", version),
"-a", "-ldflags", "-extldflags '-static'",
"-X", fmt.Sprintf("main.Branch=%s", branch),
"-X", fmt.Sprintf("main.BuildDate=%s", buildDate),
"-X", fmt.Sprintf("main.Revision=%s", revision),
"-X", fmt.Sprintf("main.VersionShort=%s", versionShort),
"-o", "postgres_exporter_integration_test", "-cover", "-covermode", "count")
}
return err
Expand Down
113 changes: 0 additions & 113 deletions vendor/github.com/Sirupsen/logrus/CHANGELOG.md

This file was deleted.

21 changes: 0 additions & 21 deletions vendor/github.com/Sirupsen/logrus/LICENSE

This file was deleted.

Loading