Skip to content

Commit

Permalink
feat(manager): Add custom version / service info headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Thurman committed May 12, 2020
1 parent 58cca12 commit fea48d3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build/compile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ BUILD_DIR ?= ./bin/
PROJECT_MODULE ?= $(shell $(GO) list -m)
# $b replaced by the binary name in the compile loop, -s/w remove debug symbols
# TODO: Remove the compile time 'main.NewRelicAPIKey'
LDFLAGS ?= "-s -w -X main.NewRelicAPIKey=${NEWRELIC_API_KEY} -X main.version=$(PROJECT_VER) -X main.appName=$$b"
LDFLAGS ?= "-s -w -X $(PROJECT_NAME)/internal/info.Name=$(PROJECT_NAME) -X $(PROJECT_MODULE)/internal/info.Version=$(PROJECT_VER)"
SRCDIR ?= .
COMPILE_OS ?= darwin linux windows

Expand Down
7 changes: 2 additions & 5 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"

nrv1 "github.com/newrelic/newrelic-kubernetes-operator/api/v1"
"github.com/newrelic/newrelic-kubernetes-operator/internal/info"
// +kubebuilder:scaffold:imports
)

const appName = "newrelic-kubernetes-operator"

var (
version = "dev"

scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
)
Expand All @@ -59,7 +56,7 @@ func main() {
flag.Parse()

if showVersion {
fmt.Printf("%s version %s\n", appName, version)
fmt.Printf("%s version %s\n", info.Name, info.Version)
os.Exit(0)
}

Expand Down
4 changes: 4 additions & 0 deletions interfaces/new_relic_alert_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/newrelic/newrelic-client-go/pkg/alerts"
"github.com/newrelic/newrelic-client-go/pkg/config"
"github.com/newrelic/newrelic-client-go/pkg/region"

"github.com/newrelic/newrelic-kubernetes-operator/internal/info"
)

//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . NewRelicAlertsClient
Expand All @@ -22,6 +24,8 @@ type NewRelicAlertsClient interface {
func InitializeAlertsClient(apiKey string, regionName string) (NewRelicAlertsClient, error) {
configuration := config.New()
configuration.PersonalAPIKey = apiKey
configuration.ServiceName = info.Name
configuration.UserAgent = info.UserAgent()

regName, err := region.Parse(regionName)
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions internal/info/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package info

// Version of this library
var (
Name string = "newrelic-kubernetes-operator"
Version string = "dev"
)

const RepoURL = "https://github.com/newrelic/newrelic-kubernetes-operator"

func UserAgent() string {
return Name + "/" + Version + " (" + RepoURL + ")"
}

0 comments on commit fea48d3

Please sign in to comment.