Skip to content

Commit

Permalink
Introduce version command and handler (#517)
Browse files Browse the repository at this point in the history
* Introduce version command and handler

Signed-off-by: Pavol Loffay <ploffay@redhat.com>

* Use flags not persistent flags

Signed-off-by: Pavol Loffay <ploffay@redhat.com>

* xdock java depend on agent

Signed-off-by: Pavol Loffay <ploffay@redhat.com>
  • Loading branch information
pavolloffay committed Nov 9, 2017
1 parent 2b73fe9 commit a2ed9b8
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 7 deletions.
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ FMT_LOG=fmt.log
LINT_LOG=lint.log
MKDOCS_VIRTUAL_ENV=.mkdocs-virtual-env

GIT_SHA=$(shell git rev-parse HEAD)
GIT_CLOSEST_TAG=$(shell git describe --abbrev=0 --tags)
DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
BUILD_INFO_IMPORT_PATH=github.com/uber/jaeger/pkg/version
BUILD_INFO=-ldflags "-X $(BUILD_INFO_IMPORT_PATH).commitSHA=$(GIT_SHA) -X $(BUILD_INFO_IMPORT_PATH).latestVersion=$(GIT_CLOSEST_TAG) -X $(BUILD_INFO_IMPORT_PATH).date=$(DATE)"

SED=sed
THRIFT_VER=0.9.3
THRIFT_IMG=thrift:$(THRIFT_VER)
Expand Down Expand Up @@ -102,19 +108,19 @@ build_ui:

.PHONY: build-all-in-one-linux
build-all-in-one-linux: build_ui
CGO_ENABLED=0 GOOS=linux installsuffix=cgo go build -o ./cmd/standalone/standalone-linux ./cmd/standalone/main.go
CGO_ENABLED=0 GOOS=linux installsuffix=cgo go build -o ./cmd/standalone/standalone-linux $(BUILD_INFO) ./cmd/standalone/main.go

.PHONY: build-agent-linux
build-agent-linux:
CGO_ENABLED=0 GOOS=linux installsuffix=cgo go build -o ./cmd/agent/agent-linux ./cmd/agent/main.go
CGO_ENABLED=0 GOOS=linux installsuffix=cgo go build -o ./cmd/agent/agent-linux $(BUILD_INFO) ./cmd/agent/main.go

.PHONY: build-query-linux
build-query-linux:
CGO_ENABLED=0 GOOS=linux installsuffix=cgo go build -o ./cmd/query/query-linux ./cmd/query/main.go
CGO_ENABLED=0 GOOS=linux installsuffix=cgo go build -o ./cmd/query/query-linux $(BUILD_INFO) ./cmd/query/main.go

.PHONY: build-collector-linux
build-collector-linux:
CGO_ENABLED=0 GOOS=linux installsuffix=cgo go build -o ./cmd/collector/collector-linux ./cmd/collector/main.go
CGO_ENABLED=0 GOOS=linux installsuffix=cgo go build -o ./cmd/collector/collector-linux $(BUILD_INFO) ./cmd/collector/main.go

.PHONY: docker-no-ui
docker-no-ui: build-agent-linux build-collector-linux build-query-linux build-crossdock-linux
Expand Down
3 changes: 3 additions & 0 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/uber/jaeger/cmd/flags"
"github.com/uber/jaeger/pkg/config"
"github.com/uber/jaeger/pkg/metrics"
"github.com/uber/jaeger/pkg/version"
)

func main() {
Expand Down Expand Up @@ -58,6 +59,8 @@ func main() {
},
}

command.AddCommand(version.Command())

config.AddFlags(
v,
command,
Expand Down
3 changes: 3 additions & 0 deletions cmd/collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/uber/jaeger/pkg/config"
"github.com/uber/jaeger/pkg/healthcheck"
"github.com/uber/jaeger/pkg/recoveryhandler"
"github.com/uber/jaeger/pkg/version"
jc "github.com/uber/jaeger/thrift-gen/jaeger"
zc "github.com/uber/jaeger/thrift-gen/zipkincore"
)
Expand Down Expand Up @@ -129,6 +130,8 @@ func main() {
},
}

command.AddCommand(version.Command())

config.AddFlags(
v,
command,
Expand Down
3 changes: 3 additions & 0 deletions cmd/query/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/uber/jaeger/pkg/config"
"github.com/uber/jaeger/pkg/healthcheck"
"github.com/uber/jaeger/pkg/recoveryhandler"
"github.com/uber/jaeger/pkg/version"
)

func main() {
Expand Down Expand Up @@ -121,6 +122,8 @@ func main() {
},
}

command.AddCommand(version.Command())

config.AddFlags(
v,
command,
Expand Down
3 changes: 3 additions & 0 deletions cmd/standalone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/uber/jaeger/pkg/config"
pMetrics "github.com/uber/jaeger/pkg/metrics"
"github.com/uber/jaeger/pkg/recoveryhandler"
"github.com/uber/jaeger/pkg/version"
"github.com/uber/jaeger/storage/spanstore/memory"
jc "github.com/uber/jaeger/thrift-gen/jaeger"
zc "github.com/uber/jaeger/thrift-gen/zipkincore"
Expand Down Expand Up @@ -78,6 +79,8 @@ func main() {
},
}

command.AddCommand(version.Command())

config.AddFlags(
v,
command,
Expand Down
3 changes: 3 additions & 0 deletions crossdock/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ services:
image: jaegertracing/xdock-java
ports:
- "8080-8082"
depends_on:
# UDP sender needs to know agent's address
- jaeger-agent

python:
image: jaegertracing/xdock-py
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ func AddFlags(v *viper.Viper, command *cobra.Command, inits ...func(*flag.FlagSe
for i := range inits {
inits[i](flagSet)
}
command.PersistentFlags().AddGoFlagSet(flagSet)
command.Flags().AddGoFlagSet(flagSet)

configureViper(v)
v.BindPFlags(command.PersistentFlags())
v.BindPFlags(command.Flags())
return v, command
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/healthcheck/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"strconv"

"go.uber.org/zap"

"github.com/uber/jaeger/pkg/version"
)

// State represents the current health check state
Expand Down Expand Up @@ -59,10 +61,11 @@ func NewHandler(s *State) (http.Handler, error) {
mu := http.NewServeMux()
mu.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(s.state)

// this is written only for response with an entity, so, it won't be used for a 204 - No content
w.Write([]byte("Server not available"))
})

version.RegisterHandler(mu, s.logger)
return mu, nil
}

Expand Down
42 changes: 42 additions & 0 deletions pkg/version/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2017 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package version

var (
// commitFromGit is a constant representing the source version that
// generated this build. It should be set during build via -ldflags.
commitSHA string
// versionFromGit is a constant representing the version tag that
// generated this build. It should be set during build via -ldflags.
latestVersion string
// build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
date string
)

// Info holds build information
type Info struct {
GitCommit string `json:"gitCommit"`
GitVersion string `json:"GitVersion"`
BuildDate string `json:"BuildDate"`
}

// Get creates and initialized Info object
func Get() Info {
return Info{
GitCommit: commitSHA,
GitVersion: latestVersion,
BuildDate: date,
}
}
41 changes: 41 additions & 0 deletions pkg/version/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2017 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package version

import (
"encoding/json"
"fmt"

"github.com/spf13/cobra"
)

// Command creates version command
func Command() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Print the version",
Long: `Print the version and build information`,
RunE: func(cmd *cobra.Command, args []string) error {
info := Get()
json, err := json.Marshal(info)
if err != nil {
return err
}
fmt.Println(string(json))

return nil
},
}
}
35 changes: 35 additions & 0 deletions pkg/version/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2017 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package version

import (
"encoding/json"
"net/http"

"go.uber.org/zap"
)

// RegisterHandler registers version handler to /version
func RegisterHandler(mu *http.ServeMux, logger *zap.Logger) {
info := Get()
json, err := json.Marshal(info)
if err != nil {
logger.Fatal("Could not get Jaeger version", zap.Error(err))
}
mu.HandleFunc("/version", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(200)
w.Write(json)
})
}

0 comments on commit a2ed9b8

Please sign in to comment.