Stackdriver / stackdriver-prometheus-sidecar

A sidecar for the Prometheus server that can send metrics to Stackdriver.
https://cloud.google.com/monitoring/kubernetes-engine/prometheus
Apache License 2.0
120 stars 43 forks source link

Initialize the labels map in the response. #238

Closed qingling128 closed 4 years ago

qingling128 commented 4 years ago

Fixes the following error when the labels is not initialized:

Container logs:
level=info ts=2020-03-02T03:17:42.590Z caller=main.go:293 msg="Starting Stackdriver Prometheus sidecar" version="(version=0.7.3, branch=master, revision=2548e8a7b383adc9217afe8570247ea84e3ef2c0)"
level=info ts=2020-03-02T03:17:42.591Z caller=main.go:294 build_context="(go=go1.12, user=kbuilder@kokoro-gcp-ubuntu-prod-40088225, date=20200206-15:24:17)"
level=info ts=2020-03-02T03:17:42.591Z caller=main.go:295 host_details="(Linux 4.14.138+ #1 SMP Tue Sep 3 02:58:08 PDT 2019 x86_64 apigee-metrics-v111-fd6fj (none))"
level=info ts=2020-03-02T03:17:42.592Z caller=main.go:296 fd_limits="(soft=1048576, hard=1048576)"
panic: assignment to entry in nil map

Labels can be optionally extracted from OC_RESOURCE_TYPE and OC_RESOURCE_LABELS env vars (https://github.com/census-instrumentation/opencensus-go/blob/1901b56b9515b0c34f5d25a5bce982dfc543d64b/resource/resource.go#L30). In case those envs are not set, labels will not be initialized: https://github.com/census-instrumentation/opencensus-go/blob/1901b56b9515b0c34f5d25a5bce982dfc543d64b/resource/resource.go#L98

For the case here, we are in fact sending metrics to Stackdriver. So OC_RESOURCE_TYPE and OC_RESOURCE_LABELS may not be needed. But we should init the Labels field.

I'll send an equivalent PR to the upstream repo as well.

quentinmit commented 4 years ago

You can't make changes to the vendor directory like that; modern Go tooling will overwrite/ignore it. You need to put this upstream, or fork the upstream repo and change go.mod to point to the fork.

qingling128 commented 4 years ago

The upstream PR has been approved and merged: https://github.com/census-ecosystem/opencensus-go-exporter-stackdriver/pull/264.

qingling128 commented 4 years ago

Hi, when is the next release gonna happen? Any rough ETA?

tsekine354 commented 4 years ago

Please reopen this issue. As mentioned in https://github.com/Stackdriver/stackdriver-prometheus-sidecar/pull/238#issuecomment-644326957 somehow, go.mod should be updated for contrib.go.opencensus.io/exporter/stackdriver. It is still pointing v0.12.8, but should be v0.13.2 (or higher).

qingling128 commented 3 years ago

Oh, sorry. The Hi, when is the next release gonna happen? Any rough ETA? is meant for the other PR in upstream (https://github.com/census-ecosystem/opencensus-go-exporter-stackdriver/pull/264). I put it in the wrong PR. This current one is already closed.