Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document and fix recorded metric forwarding #266

Merged
merged 2 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -110,7 +111,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
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ stackdriver-prometheus-sidecar --include='{__name__!~"cadvisor_.+",job="k8s"}' .

This drops all series which do not have a `job` label `k8s` and all metrics that have a name starting with `cadvisor_`.

For equality filter on metric name you can use the simpler notation, e.g. `--include='metric_name{label="foo"}'`.
For equality filter on metric name you can use the simpler notation, e.g., `--include='metric_name{label="foo"}'`.

The flag may be repeated to provide several sets of filters, in which case the metric will be forwarded if it matches at least one of them. Please note that inclusion filters only apply to Prometheus metrics proxied directly, and do not apply to [aggregated counters](#counter-aggregator).

Expand All @@ -95,6 +95,28 @@ 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
n-oden marked this conversation as resolved.
Show resolved Hide resolved

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 allowed in Stackdriver metric descriptor names. 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: int64
help: an arbitrary help string
```

*Warning:* recorded metrics _must_ have minimally an "instance" and "job" label, otherwise they will not be forwarded.

#### 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
2 changes: 1 addition & 1 deletion targets/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func targetMatch(targets []*Target, lset labels.Labels) (*Target, bool) {
Outer:
for _, t := range targets {
for _, tl := range t.Labels {
if lset.Get(tl.Name) != tl.Value {
if v := lset.Get(tl.Name); v != "" && v != tl.Value {
continue Outer
}
}
Expand Down