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

Commit b5c7a2c

Browse files
authored
Enable test coverage. (#200)
* Enable test coverage. * Use makefile in travis * enable addlicense and staticcheck * enable goimports * Enable coverage without package tests check * Remove addlicense * Exclude testpb package from tools. * Add a tools.go to ensure consistent version of the tools
1 parent dd3a274 commit b5c7a2c

21 files changed

Lines changed: 177 additions & 115 deletions

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
/vendor/
1+
# GoLand IDEA
22
/.idea/
33
*.iml
44

5+
# VS Code
6+
.vscode
57

8+
# Coverage
9+
coverage.txt
10+
coverage.html

.travis.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
language: go
22

33
go:
4-
- 1.11.x
4+
- 1.12.x
55

66
go_import_path: contrib.go.opencensus.io/exporter/stackdriver
77

88
env:
99
global:
1010
GO111MODULE=on
1111

12-
before_script:
13-
- GO_FILES=$(find . -iname '*.go' | grep -v /vendor/) # All the .go files, excluding vendor/ if any
14-
- PKGS=$(go list ./... | grep -v /vendor/) # All the import paths, excluding vendor/ if any
12+
install:
13+
- go mod download
14+
- make install-tools
1515

1616
script:
17-
- go build ./... # Ensure dependency updates don't break build
18-
- if [ -n "$(gofmt -s -l $GO_FILES)" ]; then echo "gofmt the following files:"; gofmt -s -l $GO_FILES; exit 1; fi
19-
- go vet ./...
20-
- go test -v -race $PKGS # Run all the tests with the race detector enabled
21-
- GO111MODULE=off go get -t ./...
22-
- GO111MODULE=off go build ./...
23-
- GO111MODULE=off go test -v -race $PKGS # Make sure tests still pass when not using Go modules.
24-
- 'if [[ $TRAVIS_GO_VERSION = 1.8* ]]; then ! golint ./... | grep -vE "(_mock|_string|\.pb)\.go:"; fi'
17+
- make travis-ci
18+
19+
after_success:
20+
- bash <(curl -s https://codecov.io/bash)

Makefile

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# TODO: Fix this on windows.
22
ALL_SRC := $(shell find . -name '*.go' \
3-
-not -path './vendor/*' \
4-
-not -path '*/gen-go/*' \
3+
-not -path '*/internal/testpb/*' \
4+
-not -name 'tools.go' \
55
-type f | sort)
66
ALL_PKGS := $(shell go list $(sort $(dir $(ALL_SRC))))
77

@@ -10,20 +10,21 @@ GOTEST_OPT_WITH_COVERAGE = $(GOTEST_OPT) -coverprofile=coverage.txt -covermode=a
1010
GOTEST=go test
1111
GOFMT=gofmt
1212
GOLINT=golint
13+
GOIMPORTS=goimports
1314
GOVET=go vet
1415
EMBEDMD=embedmd
16+
STATICCHECK=staticcheck
1517
# TODO decide if we need to change these names.
1618
README_FILES := $(shell find . -name '*README.md' | sort | tr '\n' ' ')
1719

20+
.DEFAULT_GOAL := defaul-goal
1821

19-
.DEFAULT_GOAL := fmt-lint-vet-embedmd-test
22+
.PHONY: defaul-goal
23+
defaul-goal: fmt lint vet embedmd goimports staticcheck test
2024

21-
.PHONY: fmt-lint-vet-embedmd-test
22-
fmt-lint-vet-embedmd-test: fmt lint vet embedmd test
23-
24-
# TODO enable test-with-coverage in tavis
25+
# TODO: enable test-with-cover when find out why "scripts/check-test-files.sh: 4: set: Illegal option -o pipefail"
2526
.PHONY: travis-ci
26-
travis-ci: fmt lint vet embedmd test test-386
27+
travis-ci: fmt lint vet embedmd goimports staticcheck test test-386 test-with-coverage
2728

2829
all-pkgs:
2930
@echo $(ALL_PKGS) | tr ' ' '\n' | sort
@@ -41,7 +42,19 @@ test-386:
4142

4243
.PHONY: test-with-coverage
4344
test-with-coverage:
45+
@echo pre-compiling tests
46+
@time go test -i $(ALL_PKGS)
47+
$(GOTEST) $(GOTEST_OPT_WITH_COVERAGE) $(ALL_PKGS)
48+
go tool cover -html=coverage.txt -o coverage.html
49+
50+
.PHONY: test-with-cover
51+
test-with-cover:
52+
@echo Verifying that all packages have test files to count in coverage
53+
@scripts/check-test-files.sh $(subst contrib.go.opencensus.io/exporter/stackdriver,./,$(ALL_PKGS))
54+
@echo pre-compiling tests
55+
@time go test -i $(ALL_PKGS)
4456
$(GOTEST) $(GOTEST_OPT_WITH_COVERAGE) $(ALL_PKGS)
57+
go tool cover -html=coverage.txt -o coverage.html
4558

4659
.PHONY: fmt
4760
fmt:
@@ -88,8 +101,25 @@ embedmd:
88101
echo "Embedmd finished successfully"; \
89102
fi
90103

104+
.PHONY: goimports
105+
goimports:
106+
@IMPORTSOUT=`$(GOIMPORTS) -d . 2>&1`; \
107+
if [ "$$IMPORTSOUT" ]; then \
108+
echo "$(GOIMPORTS) FAILED => fix the following goimports errors:\n"; \
109+
echo "$$IMPORTSOUT\n"; \
110+
exit 1; \
111+
else \
112+
echo "Goimports finished successfully"; \
113+
fi
114+
115+
.PHONY: staticcheck
116+
staticcheck:
117+
$(STATICCHECK) ./...
118+
91119
.PHONY: install-tools
92120
install-tools:
93-
go get -u golang.org/x/tools/cmd/cover
94-
go get -u golang.org/x/lint/golint
95-
go get -u github.com/rakyll/embedmd
121+
GO111MODULE=on go install \
122+
golang.org/x/lint/golint \
123+
golang.org/x/tools/cmd/goimports \
124+
github.com/rakyll/embedmd \
125+
honnef.co/go/tools/cmd/staticcheck

example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func Example_defaults() {
4141

4242
// Subscribe views to see stats in Stackdriver Monitoring.
4343
if err := view.Register(
44-
ochttp.ClientLatencyView,
45-
ochttp.ClientResponseBytesView,
44+
ochttp.ClientRoundtripLatencyDistribution,
45+
ochttp.ClientReceivedBytesDistribution,
4646
); err != nil {
4747
log.Fatal(err)
4848
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/census-instrumentation/opencensus-proto v0.2.1
77
github.com/davecgh/go-spew v1.1.1 // indirect
88
github.com/golang/protobuf v1.3.2
9+
github.com/google/addlicense v0.0.0-20190510175307-22550fa7c1b0 // indirect
910
github.com/google/go-cmp v0.3.1
1011
github.com/hashicorp/golang-lru v0.5.3 // indirect
1112
github.com/stretchr/testify v1.3.0 // indirect

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ cloud.google.com/go v0.38.0 h1:ROfEUZz+Gh5pa62DJWXSaonyu3StP6EA6lPEXPI6mCo=
55
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
66
cloud.google.com/go v0.43.0 h1:banaiRPAM8kUVYneOSkhgcDsLzEvL25FinuiSZaH/2w=
77
cloud.google.com/go v0.43.0/go.mod h1:BOSR3VbTLkk6FDC/TcffxP4NF/FFBGA5ku+jvKOP7pg=
8+
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
89
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
910
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
1011
github.com/aws/aws-sdk-go v1.22.1 h1://WJvJi9iq/i5TWHuK3hIC23xCZYH7Qv7SIN2vZVqxY=
1112
github.com/aws/aws-sdk-go v1.22.1/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
1213
github.com/census-instrumentation/opencensus-proto v0.2.1 h1:glEXhBS5PSLLv4IXzLA5yPRVX4bilULVyxxbrfOtDAk=
1314
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
15+
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
1416
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
1517
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
1618
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -27,6 +29,8 @@ github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg
2729
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
2830
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
2931
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
32+
github.com/google/addlicense v0.0.0-20190510175307-22550fa7c1b0 h1:ydbHzabf84uucKri5fcfiqYxGg+rYgP/zQfLLN8lyP0=
33+
github.com/google/addlicense v0.0.0-20190510175307-22550fa7c1b0/go.mod h1:QtPG26W17m+OIQgE6gQ24gC1M6pUaMBAbFrTIDtwG/E=
3034
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
3135
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
3236
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
@@ -50,9 +54,12 @@ github.com/hashicorp/golang-lru v0.5.3 h1:YPkqC67at8FYaadspW/6uE0COsBxS2656RLEr8
5054
github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
5155
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
5256
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
57+
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024 h1:rBMNdlhTLzJjJSDIjNEXX1Pz3Hmwmz91v+zycvx9PJc=
5358
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
5459
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5560
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
61+
github.com/rakyll/embedmd v0.0.0-20171029212350-c8060a0752a2 h1:1jfy6i1g66ijpffgfaF/7pIFYZnSZzvo9P9DFkFmRIM=
62+
github.com/rakyll/embedmd v0.0.0-20171029212350-c8060a0752a2/go.mod h1:7jOTMgqac46PZcF54q6l2hkLEG8op93fZu61KmxWDV4=
5663
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
5764
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
5865
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
@@ -68,6 +75,7 @@ golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTk
6875
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
6976
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
7077
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
78+
golang.org/x/lint v0.0.0-20190409202823-959b441ac422 h1:QzoH/1pFpZguR8NrRHLcO6jKqfv2zpuSqZLgdm7ZmjI=
7179
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
7280
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
7381
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -127,6 +135,7 @@ golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBn
127135
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
128136
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
129137
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
138+
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0 h1:Dh6fw+p6FyRl5x/FvNswO1ji0lIGzm3KP8Y9VkS9PTE=
130139
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
131140
google.golang.org/api v0.4.0 h1:KKgc1aqhV8wDPbDzlDtpvyjZFY3vjz85FP7p4wcQUyI=
132141
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
@@ -159,5 +168,6 @@ google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac
159168
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
160169
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
161170
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
171+
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc h1:/hemPrYIhOhy8zYrNj+069zDB68us2sMGsfkFJO0iZs=
162172
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
163173
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=

internal/tools.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2019, OpenCensus Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
16+
// +build tools
17+
18+
package internal
19+
20+
// This file follows the recommendation at
21+
// https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module
22+
// on how to pin tooling dependencies to a go.mod file.
23+
// This ensures that all systems use the same version of tools in addition to regular dependencies.
24+
25+
import (
26+
_ "github.com/jstemmer/go-junit-report"
27+
_ "golang.org/x/lint/golint"
28+
_ "golang.org/x/tools/cmd/goimports"
29+
_ "honnef.co/go/tools/cmd/staticcheck"
30+
)

metrics.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ directly to Stackdriver Metrics.
2121

2222
import (
2323
"context"
24-
"errors"
2524
"fmt"
2625

2726
"github.com/golang/protobuf/proto"
@@ -39,11 +38,6 @@ import (
3938
"go.opencensus.io/resource"
4039
)
4140

42-
var (
43-
errLableExtraction = errors.New("error extracting labels")
44-
errUnspecifiedMetricKind = errors.New("metric kind is unpsecified")
45-
)
46-
4741
const (
4842
exemplarAttachmentTypeString = "type.googleapis.com/google.protobuf.StringValue"
4943
exemplarAttachmentTypeSpanCtx = "type.googleapis.com/google.monitoring.v3.SpanContext"
@@ -74,7 +68,7 @@ func (se *statsExporter) handleMetricsUpload(metrics []*metricdata.Metric) {
7468
}
7569

7670
func (se *statsExporter) uploadMetrics(metrics []*metricdata.Metric) error {
77-
ctx, cancel := se.o.newContextWithTimeout()
71+
ctx, cancel := newContextWithTimeout(se.o.Context, se.o.Timeout)
7872
defer cancel()
7973

8074
ctx, span := trace.StartSpan(
@@ -182,7 +176,7 @@ func metricLabelsToTsLabels(defaults map[string]labelValue, labelKeys []metricda
182176

183177
// Perform this sanity check now.
184178
if len(labelKeys) != len(labelValues) {
185-
return labels, fmt.Errorf("Length mismatch: len(labelKeys)=%d len(labelValues)=%d", len(labelKeys), len(labelValues))
179+
return labels, fmt.Errorf("length mismatch: len(labelKeys)=%d len(labelValues)=%d", len(labelKeys), len(labelValues))
186180
}
187181

188182
for i, labelKey := range labelKeys {
@@ -461,11 +455,9 @@ func metricExemplarToPbExemplar(exemplar *metricdata.Exemplar, projectID string)
461455
func attachmentsToPbAttachments(attachments metricdata.Attachments, projectID string) []*any.Any {
462456
var pbAttachments []*any.Any
463457
for _, v := range attachments {
464-
switch v.(type) {
465-
case trace.SpanContext:
466-
spanCtx, _ := v.(trace.SpanContext)
458+
if spanCtx, succ := v.(trace.SpanContext); succ {
467459
pbAttachments = append(pbAttachments, toPbSpanCtxAttachment(spanCtx, projectID))
468-
default:
460+
} else {
469461
// Treat everything else as plain string for now.
470462
// TODO(songy23): add support for dropped label attachments.
471463
pbAttachments = append(pbAttachments, toPbStringAttachment(v))

metrics_batcher.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ import (
2424
)
2525

2626
type metricsBatcher struct {
27-
projectID string
28-
allReqs []*monitoringpb.CreateTimeSeriesRequest
29-
allTss []*monitoringpb.TimeSeries
30-
allErrs []error
27+
projectName string
28+
allReqs []*monitoringpb.CreateTimeSeriesRequest
29+
allTss []*monitoringpb.TimeSeries
30+
allErrs []error
3131
// Counts all dropped TimeSeries by this exporter.
3232
droppedTimeSeries int
3333
}
3434

3535
func newMetricsBatcher(projectID string) *metricsBatcher {
3636
return &metricsBatcher{
37-
projectID: projectID,
37+
projectName: fmt.Sprintf("projects/%s", projectID),
3838
allTss: make([]*monitoringpb.TimeSeries, 0, maxTimeSeriesPerUpload),
3939
droppedTimeSeries: 0,
4040
}
@@ -49,7 +49,7 @@ func (mb *metricsBatcher) addTimeSeries(ts *monitoringpb.TimeSeries) {
4949
mb.allTss = append(mb.allTss, ts)
5050
if len(mb.allTss) == maxTimeSeriesPerUpload {
5151
mb.allReqs = append(mb.allReqs, &monitoringpb.CreateTimeSeriesRequest{
52-
Name: monitoring.MetricProjectPath(mb.projectID),
52+
Name: mb.projectName,
5353
TimeSeries: mb.allTss,
5454
})
5555
mb.allTss = make([]*monitoringpb.TimeSeries, 0, maxTimeSeriesPerUpload)
@@ -60,7 +60,7 @@ func (mb *metricsBatcher) export(ctx context.Context, mc *monitoring.MetricClien
6060
// Last batch, if any.
6161
if len(mb.allTss) > 0 {
6262
mb.allReqs = append(mb.allReqs, &monitoringpb.CreateTimeSeriesRequest{
63-
Name: monitoring.MetricProjectPath(mb.projectID),
63+
Name: mb.projectName,
6464
TimeSeries: mb.allTss,
6565
})
6666
}

metrics_proto.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (se *statsExporter) PushMetricsProto(ctx context.Context, node *commonpb.No
5454
return 0, errNilMetricOrMetricDescriptor
5555
}
5656

57-
ctx, cancel := se.o.newContextWithTimeout()
57+
ctx, cancel := newContextWithTimeout(ctx, se.o.Timeout)
5858
defer cancel()
5959

6060
// Caches the resources seen so far
@@ -284,7 +284,7 @@ func labelsPerTimeSeries(defaults map[string]labelValue, labelKeys []string, lab
284284

285285
// Perform this sanity check now.
286286
if len(labelKeys) != len(labelValues) {
287-
return labels, fmt.Errorf("Length mismatch: len(labelKeys)=%d len(labelValues)=%d", len(labelKeys), len(labelValues))
287+
return labels, fmt.Errorf("length mismatch: len(labelKeys)=%d len(labelValues)=%d", len(labelKeys), len(labelValues))
288288
}
289289

290290
for i, labelKey := range labelKeys {

0 commit comments

Comments
 (0)