Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Initialize the labels map in the response. #264

Merged
merged 1 commit into from
Jun 16, 2020

Conversation

qingling128
Copy link
Contributor

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.

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+ census-ecosystem#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.
@codecov-commenter
Copy link

Codecov Report

Merging #264 into master will decrease coverage by 0.08%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #264      +/-   ##
==========================================
- Coverage   72.02%   71.94%   -0.09%     
==========================================
  Files          17       17              
  Lines        1691     1693       +2     
==========================================
  Hits         1218     1218              
- Misses        397      399       +2     
  Partials       76       76              
Impacted Files Coverage Δ
stackdriver.go 31.06% <0.00%> (-0.62%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1905f46...35b0752. Read the comment docs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants