Skip to content

Commit

Permalink
Document and fix recorded metric forwarding
Browse files Browse the repository at this point in the history
This should address most of #104

- fix target cache lookup for recorded metrics
- update documentation with examples

Also: allow overriding docker FROM target with DOCKER_IMAGE_BASE env var
(helpful for testing and runtime scenarios where /bin/sh is needed)
  • Loading branch information
n-oden committed Jan 15, 2021
1 parent 28afb60 commit d0f7588
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 143 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM gcr.io/distroless/static:latest
ARG DOCKER_IMAGE_BASE=gcr.io/distroless/static:latest
FROM $DOCKER_IMAGE_BASE
LABEL maintainer "Stackdriver Engineering <engineering@stackdriver.com>"

COPY stackdriver-prometheus-sidecar /bin/stackdriver-prometheus-sidecar
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
PREFIX ?= $(shell pwd)
BIN_DIR ?= $(shell pwd)
# Private repo.
DOCKER_IMAGE_BASE ?= gcr.io/distroless/static:latest
DOCKER_IMAGE_NAME ?= gcr.io/stackdriver-prometheus/stackdriver-prometheus-sidecar
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))

Expand Down Expand Up @@ -113,7 +114,7 @@ tarball: promu

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

push: test docker
@echo ">> pushing docker image"
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ static_metadata:
* All `static_metadata` entries must have `type` specified. This specifies the Stackdriver metric type and overrides the metric type chosen by the Prometheus client.
* If `value_type` is specified, it will override the default value type for counters and gauges. All Prometheus metrics have a default type of double.

#### Dealing with recording rules

The default Prometheus naming format for [recording rules](https://prometheus.io/docs/practices/rules/) is `level:metric:operations`, e.g. `instance:requests_total:sum`, but colons are not legal names for Stackdriver metric descriptors. To forward a recorded Prometheus metric to Stackdriver, you must use the `metric_renames` feature to replace the colon characters:

```yaml
metric_renames:
- from: instance:requests_total_sum
to: recorded_instance_requests_total_sum
```
Additionally, the sidecar assumes that any recorded metrics are gauges. If this is not the case (e.g. for a Prometheus counter metric) you will need to specify that in `static_metadata`:

```yaml
static_metadata:
- metric: recorded_instance_requests_total_sum
type: counter
value_type: double
help: an arbitrary help string
```

#### Counter Aggregator

Counter Aggregator is an advanced feature of the sidecar that can be used to export a sum of multiple Prometheus counters to Stackdriver as a single CUMULATIVE metric.
Expand Down
28 changes: 1 addition & 27 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,28 @@ module github.com/Stackdriver/stackdriver-prometheus-sidecar

require (
cloud.google.com/go v0.49.0
cloud.google.com/go/bigquery v1.3.0 // indirect
cloud.google.com/go/pubsub v1.1.0 // indirect
cloud.google.com/go/storage v1.4.0 // indirect
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.8
dmitri.shuralyov.com/gpu/mtl v0.0.0-20191126053124-fec1b7b612ab // indirect
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999 // indirect
github.com/Azure/azure-sdk-for-go v36.2.0+incompatible // indirect
github.com/Azure/go-autorest v13.3.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.9.2 // indirect
github.com/Azure/go-autorest/autorest/adal v0.8.0 // indirect
github.com/Azure/go-autorest/autorest/azure/auth v0.4.0 // indirect
github.com/Azure/go-autorest/autorest/to v0.3.0 // indirect
github.com/Azure/go-autorest/autorest/validation v0.2.0 // indirect
github.com/Masterminds/semver v1.5.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.25.44 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/creack/pty v1.1.9 // indirect
github.com/envoyproxy/go-control-plane v0.9.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-20191027212112-611e8accdfc9 // indirect
github.com/golang/lint v0.0.0-20180702182130-06c8688daad7 // indirect
github.com/golang/protobuf v1.3.2
github.com/google/btree v1.0.0 // indirect
github.com/google/go-cmp v0.3.1
github.com/google/pprof v0.0.0-20191105193234-27840fff0d09 // indirect
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
Expand All @@ -46,8 +32,6 @@ require (
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/jstemmer/go-junit-report v0.9.1 // indirect
github.com/kr/pty v1.1.8 // 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
Expand All @@ -61,25 +45,15 @@ require (
github.com/prometheus/prometheus v0.0.0-20190710134608-e5b22494857d
github.com/prometheus/tsdb v0.10.0
github.com/rakyll/statik v0.1.6
github.com/rogpeppe/go-internal v1.5.0 // indirect
github.com/samuel/go-zookeeper v0.0.0-20190801204459-3c104360edc8 // indirect
github.com/shopspring/decimal v0.0.0-20191125035519-b054a8dfd10d // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/cobra v0.0.5 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.2.0 // indirect
go.opencensus.io v0.22.2
golang.org/x/crypto v0.0.0-20191128160524-b544559bb6d1 // indirect
golang.org/x/exp v0.0.0-20191129062945-2f5052295587 // indirect
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 // indirect
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f // indirect
golang.org/x/mobile v0.0.0-20191130191448-5c0e7e404af8 // indirect
golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933 // indirect
golang.org/x/oauth2 v0.0.0-20191122200657-5d9234df094c // indirect
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d // indirect
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 // indirect
google.golang.org/appengine v1.6.5 // indirect
google.golang.org/genproto v0.0.0-20191115221424-83cc0476cb11
google.golang.org/grpc v1.25.1
Expand Down
Loading

0 comments on commit d0f7588

Please sign in to comment.