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 build flags #76

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Add build flags #76

wants to merge 3 commits into from

Conversation

pgporada
Copy link
Member

@pgporada pgporada commented May 20, 2024

Added a new //util package which contains some variables set by the builder at build time to output more information during process startup. This was largely copied from boulder. See below:

$ ./unbound_exporter 
level=info ts=2024-05-20T15:44:53.420Z caller=unbound_exporter.go:553 msg="Starting unbound_exporter" version="(version=go1.22.2, branch=main, revision=ab17c00)"

Fixes #75

@pgporada pgporada requested a review from aarongable May 20, 2024 15:49
Copy link

@aarongable aarongable left a comment

Choose a reason for hiding this comment

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

LGTM, just some naming a documentation-consistency changes.

@@ -23,7 +23,7 @@ jobs:
persist-credentials: false

- name: build binary
run: go build
run: go build -ldflags "-X github.com/letsencrypt/unbound_exporter/util.BuildID=$(git rev-parse --short HEAD) -X github.com/letsencrypt/unbound_exporter/util.BuildBranch=$(git rev-parse --abbrev-ref HEAD) -X github.com/letsencrypt/unbound_exporter/util.BuildTime=$(date +%F-%T -u)"

Choose a reason for hiding this comment

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

Suggested change
run: go build -ldflags "-X github.com/letsencrypt/unbound_exporter/util.BuildID=$(git rev-parse --short HEAD) -X github.com/letsencrypt/unbound_exporter/util.BuildBranch=$(git rev-parse --abbrev-ref HEAD) -X github.com/letsencrypt/unbound_exporter/util.BuildTime=$(date +%F-%T -u)"
run: go build -ldflags "-X github.com/letsencrypt/unbound_exporter/build.Revision=$(git rev-parse --short HEAD) -X github.com/letsencrypt/unbound_exporter/build.Branch=$(git rev-parse --abbrev-ref HEAD)"

Comment on lines +5 to +7
// BuildID is set by the compiler (using -ldflags "-X util.BuildID $(git rev-parse --short HEAD)")
// and is used by GetID
var BuildID string

Choose a reason for hiding this comment

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

Suggested change
// BuildID is set by the compiler (using -ldflags "-X util.BuildID $(git rev-parse --short HEAD)")
// and is used by GetID
var BuildID string
// Revision is set by the compiler (using -ldflags "-X build.Revision $(git rev-parse --short HEAD)")
// and is used by GetRevision
var Revision string

Comment on lines +9 to +10
// BuildBranch is set by the compiler and is used by GetBranch
var BuildBranch string

Choose a reason for hiding this comment

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

Suggested change
// BuildBranch is set by the compiler and is used by GetBranch
var BuildBranch string
// Branch is set by the compiler and is used by GetBranch
var Branch string

Comment on lines +12 to +15
// GetBuildID identifies what build is running.
func GetID() (BuildID string) {
if BuildID != "" {
return BuildID

Choose a reason for hiding this comment

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

Suggested change
// GetBuildID identifies what build is running.
func GetID() (BuildID string) {
if BuildID != "" {
return BuildID
// GetRevision identifies what commit this binary was built from.
func GetRevision() string {
if Revision != "" {
return Revision

// and is used by GetID
var BuildID string

// BuildBranch is set by the compiler and is used by GetBranch

Choose a reason for hiding this comment

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

Suggested change
// BuildBranch is set by the compiler and is used by GetBranch
// BuildBranch is set by the compiler (using -ldflags "-X build.Branch $git rev-parse --abbrev-rev HEAD)")
// and is used by GetBranch


const Unspecified = "Unspecified"

// BuildID is set by the compiler (using -ldflags "-X util.BuildID $(git rev-parse --short HEAD)")

Choose a reason for hiding this comment

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

Suggested change
// BuildID is set by the compiler (using -ldflags "-X util.BuildID $(git rev-parse --short HEAD)")
// Revision is set by the compiler (using -ldflags "-X build.Revision $(git rev-parse --short HEAD)")

Comment on lines +21 to +24
// GetBranch identifies the building host
func GetBranch() (BuildBranch string) {
if BuildBranch != "" {
return BuildBranch

Choose a reason for hiding this comment

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

Suggested change
// GetBranch identifies the building host
func GetBranch() (BuildBranch string) {
if BuildBranch != "" {
return BuildBranch
// GetBranch identifies what git branch this binary was built from.
func GetBranch() string {
if Branch != "" {
return Branch

@jpds
Copy link
Contributor

jpds commented May 20, 2024

I was planning to push up a PR which would add a unbound_exporter_build_info metric once #75 landed.

This is what the other Prometheus exporters do: https://github.com/prometheus/node_exporter/blob/3afc0a341e3c2c6605b18a882fb045318c18c444/node_exporter.go#L123 - the functionality uses the prometheus.Version data.

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.

3 participants