Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
6 changes: 5 additions & 1 deletion .promu.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
verbose: false
go:
version: 1.12.0
cgo: false
repository:
path: github.com/Stackdriver/stackdriver-prometheus-sidecar
build:
binaries:
- name: stackdriver-prometheus-sidecar
path: ./cmd/stackdriver-prometheus-sidecar
flags: -a -tags netgo
flags: -mod=vendor -a -tags netgo
ldflags: |
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Version={{.Version}}
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Revision={{.Revision}}
Expand Down
16 changes: 15 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
language: go
script: make goveralls

go:
- 1.12.x

go_import_path: github.com/Stackdriver/stackdriver-prometheus-sidecar

# Skip dependency fetch. We store all dependencies under vendor/.
install: true

# make goveralls runs all tests as well.
script:
- make goveralls
# TODO(jkohen): `make goveralls` is causing a diff in go.mod. Prevent that and uncomment the line below.
#- git diff --exit-code

# Contains tokens for Coveralls. See https://docs.coveralls.io/go
env:
global:
Expand Down
71 changes: 50 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,34 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Ensure GOBIN is not set during build so that promu is installed to the correct path
unexport GOBIN

GO ?= go
GOFMT ?= $(GO)fmt
FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
GOHOSTOS ?= $(shell $(GO) env GOHOSTOS)
GOHOSTARCH ?= $(shell $(GO) env GOHOSTARCH)

# Enforce Go modules support just in case the directory is inside GOPATH (and for Travis CI).
GO111MODULE := on
# Always use the local vendor/ directory to satisfy the dependencies.
GOOPTS := $(GOOPTS) -mod=vendor

PROMU := $(FIRST_GOPATH)/bin/promu
STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck
GOVERALLS := $(FIRST_GOPATH)/bin/goveralls
pkgs = $(shell $(GO) list ./... | grep -v /vendor/)
pkgs = ./...

ifeq (arm, $(GOHOSTARCH))
GOHOSTARM ?= $(shell GOARM= $(GO) env GOARM)
GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)v$(GOHOSTARM)
else
GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)
endif

PROMU_VERSION ?= 0.5.0
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz

PREFIX ?= $(shell pwd)
BIN_DIR ?= $(shell pwd)
Expand All @@ -40,41 +61,48 @@ check_license:
@echo ">> checking license header"
@./scripts/check_license.sh

# TODO(fabxc): example tests temporarily removed.
deps:
@echo ">> getting dependencies"
ifdef GO111MODULE
GO111MODULE=$(GO111MODULE) $(GO) mod download
else
$(GO) get $(GOOPTS) -t ./...
endif

test-short:
@echo ">> running short tests"
@$(GO) test -short $(shell $(GO) list ./... | grep -v /vendor/ | grep -v examples)
$(GO) test -short $(GOOPTS) $(pkgs)

test:
@echo ">> running all tests"
@$(GO) test $(shell $(GO) list ./... | grep -v /vendor/ | grep -v examples)
$(GO) test $(GOOPTS) $(pkgs)

cover:
@echo ">> running all tests with coverage"
@$(GO) test -coverprofile=coverage.out $(shell $(GO) list ./... | grep -v /vendor/ | grep -v examples)
$(GO) test -coverprofile=coverage.out $(GOOPTS) $(pkgs)

format:
@echo ">> formatting code"
@$(GO) fmt $(pkgs)
$(GO) fmt $(pkgs)

vet:
@echo ">> vetting code"
@$(GO) vet $(pkgs)
$(GO) vet $(GOOPTS) $(pkgs)

staticcheck: $(STATICCHECK)
@echo ">> running staticcheck"
@$(STATICCHECK) $(pkgs)
$(STATICCHECK) $(pkgs)

goveralls: cover $(GOVERALLS)
ifndef COVERALLS_TOKEN
$(error COVERALLS_TOKEN is undefined, follow https://docs.coveralls.io/go to create one and go to https://coveralls.io to retrieve existing ones)
endif
@echo ">> running goveralls"
@$(GOVERALLS) -coverprofile=coverage.out -service=travis-ci -repotoken "${COVERALLS_TOKEN}"
$(GOVERALLS) -coverprofile=coverage.out -service=travis-ci -repotoken "${COVERALLS_TOKEN}"

build: promu
@echo ">> building binaries"
@$(PROMU) build --prefix $(PREFIX)
$(PROMU) build --prefix $(PREFIX)

build-linux-amd64: promu
@echo ">> building linux amd64 binaries"
Expand All @@ -86,29 +114,30 @@ tarball: promu

docker: build-linux-amd64
@echo ">> building docker image"
@docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .
docker build -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .

push: test docker
@echo ">> pushing docker image"
docker push "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)"

assets:
@echo ">> writing assets"
@$(GO) get -u github.com/jteeuwen/go-bindata/...
@go-bindata $(bindata_flags) -pkg ui -o web/ui/bindata.go -ignore '(.*\.map|bootstrap\.js|bootstrap-theme\.css|bootstrap\.css)' web/ui/templates/... web/ui/static/...
@$(GO) fmt ./web/ui
$(GO) get -u github.com/jteeuwen/go-bindata/...
go-bindata $(bindata_flags) -pkg ui -o web/ui/bindata.go -ignore '(.*\.map|bootstrap\.js|bootstrap-theme\.css|bootstrap\.css)' web/ui/templates/... web/ui/static/...
$(GO) fmt ./web/ui

promu:
@echo ">> fetching promu"
@GOOS=$(shell uname -s | tr A-Z a-z) \
GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \
GO="$(GO)" \
$(GO) get -u github.com/prometheus/promu
$(eval PROMU_TMP := $(shell mktemp -d))
curl -s -L $(PROMU_URL) | tar -xvzf - -C $(PROMU_TMP)
mkdir -p $(FIRST_GOPATH)/bin
cp $(PROMU_TMP)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(FIRST_GOPATH)/bin/promu
rm -r $(PROMU_TMP)

$(FIRST_GOPATH)/bin/staticcheck:
@GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck
GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck

$(FIRST_GOPATH)/bin/goveralls:
@GOOS= GOARCH= $(GO) get -u github.com/mattn/goveralls
GOOS= GOARCH= $(GO) get -u github.com/mattn/goveralls

.PHONY: all style check_license format build test vet assets tarball docker promu staticcheck $(FIRST_GOPATH)/bin/staticcheck goveralls $(FIRST_GOPATH)/bin/goveralls
.PHONY: all style check_license deps format build test vet assets tarball docker promu staticcheck $(FIRST_GOPATH)/bin/staticcheck goveralls $(FIRST_GOPATH)/bin/goveralls
21 changes: 11 additions & 10 deletions cmd/stackdriver-prometheus-sidecar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"time"

md "cloud.google.com/go/compute/metadata"
oc_prometheus "contrib.go.opencensus.io/exporter/prometheus"
oc_stackdriver "contrib.go.opencensus.io/exporter/stackdriver"
"github.com/Stackdriver/stackdriver-prometheus-sidecar/metadata"
"github.com/Stackdriver/stackdriver-prometheus-sidecar/retrieval"
Expand All @@ -53,7 +54,6 @@ import (
"github.com/prometheus/prometheus/pkg/textparse"
"github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/scrape"
oc_prometheus "go.opencensus.io/exporter/prometheus"
"go.opencensus.io/plugin/ocgrpc"
"go.opencensus.io/plugin/ochttp"
"go.opencensus.io/stats/view"
Expand Down Expand Up @@ -196,8 +196,7 @@ type mainConfig struct {
UseRestrictedIPs bool
manualResolver *manual.Resolver
MonitoringBackends []string

LogLevel promlog.AllowedLevel
PromlogConfig promlog.Config
}

func main() {
Expand Down Expand Up @@ -269,7 +268,7 @@ func main() {
a.Flag("filter", "PromQL-style matcher for a single label which must pass for a series to be forwarded to Stackdriver. If repeated, the series must pass all filters to be forwarded. Deprecated, please use --include instead.").
StringsVar(&cfg.Filters)

promlogflag.AddFlags(a, &cfg.LogLevel)
promlogflag.AddFlags(a, &cfg.PromlogConfig)

_, err := a.Parse(os.Args[1:])
if err != nil {
Expand All @@ -278,7 +277,7 @@ func main() {
os.Exit(2)
}

logger := promlog.New(cfg.LogLevel)
logger := promlog.New(&cfg.PromlogConfig)
if cfg.ConfigFilename != "" {
cfg.MetricRenames, cfg.StaticMetadata, cfg.Aggregations, err = parseConfigFile(cfg.ConfigFilename)
if err != nil {
Expand Down Expand Up @@ -365,11 +364,13 @@ func main() {
// to resolve GCP API calls to the resolver.
cfg.manualResolver, _ = manual.GenerateAndRegisterManualResolver()
// These IP addresses correspond to restricted.googleapis.com and are not expected to change.
cfg.manualResolver.InitialAddrs([]resolver.Address{
{Addr: "199.36.153.4:443"},
{Addr: "199.36.153.5:443"},
{Addr: "199.36.153.6:443"},
{Addr: "199.36.153.7:443"},
cfg.manualResolver.InitialState(resolver.State{
Addresses: []resolver.Address{
{Addr: "199.36.153.4:443"},
{Addr: "199.36.153.5:443"},
{Addr: "199.36.153.6:443"},
{Addr: "199.36.153.7:443"},
},
})
}
targetsURL, err := cfg.PrometheusURL.Parse(targets.DefaultAPIEndpoint)
Expand Down
3 changes: 2 additions & 1 deletion cmd/stackdriver-prometheus-sidecar/statusz-tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ <h1>Parsed configuration</h1>
<tr><th>Kubernetes labels: cluster name</th><td>{{.KubernetesLabels.ClusterName}}</td></tr>
<tr><th>Kubernetes labels: location</th><td>{{.KubernetesLabels.Location}}</td></tr>
<tr><th>Listen address</th><td>{{.ListenAddress}}</td></tr>
<tr><th>Log level</th><td>{{.LogLevel.String}}</td></tr>
<tr><th>Log level</th><td>{{.PromlogConfig.Level}}</td></tr>
<tr><th>Log format</th><td>{{.PromlogConfig.Format}}</td></tr>
<tr><th>Metrics prefix</th><td>{{.MetricsPrefix}}</td></tr>
<tr><th>Monitoring backends</th><td>{{.MonitoringBackends}}</td></tr>
<tr><th>Project ID resource</th><td>{{.ProjectIDResource}}</td></tr>
Expand Down
7 changes: 4 additions & 3 deletions cmd/stackdriver-prometheus-sidecar/statusz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func TestStatuszHandler(t *testing.T) {

matcher, _ := labels.NewMatcher(labels.MatchEqual, "k", "v")

var logLevel promlog.AllowedLevel
logLevel.Set("debug")
logConfig := promlog.Config{Level: &promlog.AllowedLevel{}}
logConfig.Level.Set("debug")

handler := &statuszHandler{
logger: log.NewLogfmtLogger(os.Stdout),
Expand All @@ -81,7 +81,7 @@ func TestStatuszHandler(t *testing.T) {
ClusterName: "my-cluster",
},
ListenAddress: "0.0.0.0:9091",
LogLevel: logLevel,
PromlogConfig: logConfig,
MetricRenames: map[string]string{"from1": "to1", "from2": "to2"},
MetricsPrefix: "external.googleapis.com/prometheus",
MonitoringBackends: []string{"prometheus", "stackdriver"},
Expand Down Expand Up @@ -120,6 +120,7 @@ func TestStatuszHandler(t *testing.T) {
regexp.MustCompile(`<tr><th>Kubernetes labels: location</th><td>us-central1-a</td></tr>`),
regexp.MustCompile(`<tr><th>Listen address</th><td>0.0.0.0:9091</td></tr>`),
regexp.MustCompile(`<tr><th>Log level</th><td>debug</td></tr>`),
regexp.MustCompile(`<tr><th>Log format</th><td>&lt;nil&gt;</td></tr>`),
regexp.MustCompile(`<tr><th>Metrics prefix</th><td>external.googleapis.com/prometheus</td></tr>`),
regexp.MustCompile(`<tr><th>Monitoring backends</th><td>\[prometheus stackdriver\]</td></tr>`),
regexp.MustCompile(`<tr><th>Project ID resource</th><td>my-project</td></tr>`),
Expand Down
63 changes: 63 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module github.com/Stackdriver/stackdriver-prometheus-sidecar

require (
cloud.google.com/go v0.43.0
contrib.go.opencensus.io/exporter/ocagent v0.6.0 // indirect
contrib.go.opencensus.io/exporter/prometheus v0.1.0
contrib.go.opencensus.io/exporter/stackdriver v0.12.4
github.com/Azure/azure-sdk-for-go v32.1.0+incompatible // indirect
github.com/Azure/go-autorest v12.4.1+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.5.0 // indirect
github.com/Azure/go-autorest/autorest/to v0.2.0 // indirect
github.com/Azure/go-autorest/autorest/validation v0.1.0 // indirect
github.com/Azure/go-autorest/tracing v0.2.0 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 // indirect
github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878 // indirect
github.com/aws/aws-sdk-go v1.21.10 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/evanphx/json-patch v4.5.0+incompatible // indirect
github.com/ghodss/yaml v1.0.0
github.com/go-kit/kit v0.9.0
github.com/gogo/protobuf v1.2.2-0.20190730201129-28a6bbf47e48 // indirect
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect
github.com/golang/protobuf v1.3.2
github.com/googleapis/gnostic v0.3.0 // indirect
github.com/gophercloud/gophercloud v0.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/grpc-gateway v1.9.5 // indirect
github.com/hashicorp/go-immutable-radix v1.1.0 // indirect
github.com/hashicorp/go-msgpack v0.5.5 // indirect
github.com/hashicorp/go-rootcerts v1.0.1 // indirect
github.com/hashicorp/golang-lru v0.5.3 // indirect
github.com/hashicorp/memberlist v0.1.4 // indirect
github.com/hashicorp/serf v0.8.3 // indirect
github.com/jpillora/backoff v0.0.0-20180909062703-3050d21c67d7 // indirect
github.com/json-iterator/go v1.1.7 // indirect
github.com/miekg/dns v1.1.15 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f
github.com/oklog/oklog v0.3.2
github.com/onsi/ginkgo v1.8.0 // indirect
github.com/onsi/gomega v1.5.0 // indirect
github.com/opentracing/opentracing-go v1.1.0 // indirect
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v1.0.0
github.com/prometheus/common v0.4.1
github.com/prometheus/procfs v0.0.3 // indirect
github.com/prometheus/prometheus v0.0.0-20190710134608-e5b22494857d
github.com/prometheus/tsdb v0.10.0
github.com/samuel/go-zookeeper v0.0.0-20190801204459-3c104360edc8 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
go.opencensus.io v0.22.0
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 // indirect
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64
google.golang.org/grpc v1.22.1
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/fsnotify/fsnotify.v1 v1.4.7 // indirect
k8s.io/klog v0.3.3 // indirect
k8s.io/kube-openapi v0.0.0-20190722073852-5e22f3d471e6 // indirect
k8s.io/utils v0.0.0-20190801114015-581e00157fb1 // indirect
)
Loading