Skip to content

Commit

Permalink
add version to ContainerPilot service registration and /status endpoi…
Browse files Browse the repository at this point in the history
…nt (#430)
  • Loading branch information
tgross authored Jul 10, 2017
1 parent 7f86ed5 commit e2fb5ec
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
7 changes: 0 additions & 7 deletions core/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ import (
log "github.com/sirupsen/logrus"
)

var (
// Version is the version for this build, set at build time via LDFLAGS
Version string
// GitHash is the short-form commit hash of this build, set at build time
GitHash string
)

// App encapsulates the state of ContainerPilot after the initial setup.
type App struct {
ControlServer *control.HTTPServer
Expand Down
5 changes: 3 additions & 2 deletions core/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/joyent/containerpilot/subcommands"
"github.com/joyent/containerpilot/version"
)

// MultiFlag provides a custom CLI flag that stores its unique values into a
Expand Down Expand Up @@ -95,8 +96,8 @@ func GetArgs() (subcommands.Handler, subcommands.Params) {

if versionFlag {
return subcommands.VersionHandler, subcommands.Params{
Version: Version,
GitHash: GitHash,
Version: version.Version,
GitHash: version.GitHash,
}
}
if configPath == "" {
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SHELL := /bin/bash

IMPORT_PATH := github.com/joyent/containerpilot
VERSION ?= dev-build-not-for-release
LDFLAGS := -X ${IMPORT_PATH}/core.GitHash='$(shell git rev-parse --short HEAD)' -X ${IMPORT_PATH}/core.Version='${VERSION}'
LDFLAGS := -X ${IMPORT_PATH}/version.GitHash=$(shell git rev-parse --short HEAD) -X ${IMPORT_PATH}/version.Version=${VERSION}

ROOT := $(shell pwd)
RUNNER := -v ${ROOT}:/go/src/${IMPORT_PATH} -w /go/src/${IMPORT_PATH} containerpilot_build
Expand Down
6 changes: 4 additions & 2 deletions telemetry/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ package telemetry
import (
"encoding/json"
"fmt"
"github.com/joyent/containerpilot/jobs"
"github.com/joyent/containerpilot/watches"
"net/http"
"strings"

"github.com/joyent/containerpilot/jobs"
"github.com/joyent/containerpilot/watches"
)

// Status persists all the data the telemetry server needs to serve
// the '/status' endpoint
type Status struct {
Version string
jobs []*jobs.Job
Services []jobStatusResponse
Watches []string
Expand Down
3 changes: 2 additions & 1 deletion telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
log "github.com/sirupsen/logrus"

"github.com/joyent/containerpilot/events"
"github.com/joyent/containerpilot/version"
)

// Telemetry represents the service to advertise for finding the metrics
Expand All @@ -32,7 +33,7 @@ func NewTelemetry(cfg *Config) *Telemetry {
}
t := &Telemetry{
Metrics: []*Metric{},
Status: &Status{},
Status: &Status{Version: version.Version},
}
t.addr = cfg.addr
router := http.NewServeMux()
Expand Down
4 changes: 4 additions & 0 deletions telemetry/telemetry_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/joyent/containerpilot/config/services"
"github.com/joyent/containerpilot/discovery"
"github.com/joyent/containerpilot/jobs"
"github.com/joyent/containerpilot/version"
)

// Config represents the service to advertise for finding the metrics
Expand Down Expand Up @@ -68,6 +69,9 @@ func (cfg *Config) Validate(disc discovery.Backend) error {

// ToJobConfig ...
func (cfg *Config) ToJobConfig() *jobs.Config {
if version.Version != "" {
cfg.Tags = append(cfg.Tags, version.Version)
}
service := &jobs.Config{
Name: "containerpilot", // TODO: hard-coded?
Health: &jobs.HealthConfig{
Expand Down
8 changes: 8 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package version

var (
// Version is the version for this build, set at build time via LDFLAGS
Version string
// GitHash is the short-form commit hash of this build, set at build time
GitHash string
)

0 comments on commit e2fb5ec

Please sign in to comment.