Skip to content

Commit 3f25a33

Browse files
committed
fix suggested by easwars
1 parent fcf87af commit 3f25a33

File tree

6 files changed

+488
-282
lines changed

6 files changed

+488
-282
lines changed

monitoring/exporter/stackdriver/data_test.go

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
package exporter
1+
// Copyright 2018 Google Inc. All Rights Reserved.
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+
package stackdriver
216

317
import (
418
"context"
@@ -9,16 +23,11 @@ import (
923
"go.opencensus.io/stats"
1024
"go.opencensus.io/stats/view"
1125
"go.opencensus.io/tag"
12-
monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres"
26+
mrpb "google.golang.org/genproto/googleapis/api/monitoredres"
1327
)
1428

1529
// This file defines various data needed for testing.
1630

17-
func init() {
18-
// For testing convenience, we reduce maximum time series that metric client accepts.
19-
MaxTimeSeriesPerUpload = 3
20-
}
21-
2231
const (
2332
label1name = "key_1"
2433
label2name = "key_2"
@@ -32,11 +41,15 @@ const (
3241
value4 = "value_4"
3342
value5 = "value_5"
3443
value6 = "value_6"
44+
value7 = "value_7"
45+
value8 = "value_8"
3546

3647
metric1name = "metric_1"
3748
metric1desc = "this is metric 1"
3849
metric2name = "metric_2"
3950
metric2desc = "this is metric 2"
51+
metric3name = "metric_3"
52+
metric3desc = "this is metric 3"
4053

4154
project1 = "project-1"
4255
project2 = "project-2"
@@ -45,14 +58,16 @@ const (
4558
var (
4659
ctx = context.Background()
4760

61+
invalidDataErrStr = "invalid data"
4862
// This error is used for test to catch some error happpened.
49-
invalidDataError = errors.New("invalid data")
63+
invalidDataError = errors.New(invalidDataErrStr)
5064
// This error is used for unexpected error.
5165
unrecognizedDataError = errors.New("unrecognized data")
5266

53-
key1 = getKey(label1name)
54-
key2 = getKey(label2name)
55-
key3 = getKey(label3name)
67+
key1 = getKey(label1name)
68+
key2 = getKey(label2name)
69+
key3 = getKey(label3name)
70+
projectKey = getKey(ProjectKeyName)
5671

5772
view1 = &view.View{
5873
Name: metric1name,
@@ -68,9 +83,16 @@ var (
6883
Measure: stats.Int64(metric2name, metric2desc, stats.UnitDimensionless),
6984
Aggregation: view.Sum(),
7085
}
86+
view3 = &view.View{
87+
Name: metric3name,
88+
Description: metric3desc,
89+
TagKeys: []tag.Key{projectKey},
90+
Measure: stats.Int64(metric3name, metric3desc, stats.UnitDimensionless),
91+
Aggregation: view.Sum(),
92+
}
7193

72-
// To make verification easy, we require all valid rows should int64 values and all of them
73-
// must be distinct.
94+
// To make verification easy, we require all valid rows should have int64 values and all of
95+
// them must be distinct.
7496
view1row1 = &view.Row{
7597
Tags: nil,
7698
Data: &view.SumData{Value: 1},
@@ -91,23 +113,30 @@ var (
91113
Tags: []tag.Tag{{key1, value4}, {key2, value5}, {key3, value6}},
92114
Data: &view.SumData{Value: 5},
93115
}
116+
view3row1 = &view.Row{
117+
Tags: []tag.Tag{{projectKey, project1}},
118+
Data: &view.SumData{Value: 6},
119+
}
120+
view3row2 = &view.Row{
121+
Tags: []tag.Tag{{projectKey, project2}},
122+
Data: &view.SumData{Value: 7},
123+
}
124+
view3row3 = &view.Row{
125+
Tags: []tag.Tag{{projectKey, project1}},
126+
Data: &view.SumData{Value: 8},
127+
}
94128
// This Row does not have valid Data field, so is invalid.
95129
invalidRow = &view.Row{Data: nil}
96130

97-
startTime1 = endTime1.Add(-10 * time.Second)
98-
endTime1 = startTime2.Add(-time.Second)
99-
startTime2 = endTime2.Add(-10 * time.Second)
100-
endTime2 = time.Now()
101-
102-
resource1 = &monitoredrespb.MonitoredResource{
131+
resource1 = &mrpb.MonitoredResource{
103132
Type: "cloudsql_database",
104133
Labels: map[string]string{
105134
"project_id": project1,
106135
"region": "us-central1",
107136
"database_id": "cloud-SQL-instance-1",
108137
},
109138
}
110-
resource2 = &monitoredrespb.MonitoredResource{
139+
resource2 = &mrpb.MonitoredResource{
111140
Type: "gce_instance",
112141
Labels: map[string]string{
113142
"project_id": project2,
@@ -117,6 +146,23 @@ var (
117146
}
118147
)
119148

149+
// Timestamps. We make sure that all time stamps are strictly increasing.
150+
var (
151+
startTime1, endTime1, startTime2, endTime2 time.Time
152+
startTime3, endTime3, startTime4, endTime4 time.Time
153+
)
154+
155+
func init() {
156+
ts := time.Now()
157+
for _, t := range []*time.Time{
158+
&startTime1, &endTime1, &startTime2, &endTime2,
159+
&startTime3, &endTime3, &startTime4, &endTime4,
160+
} {
161+
*t = ts
162+
ts = ts.Add(time.Second)
163+
}
164+
}
165+
120166
func getKey(name string) tag.Key {
121167
key, err := tag.NewKey(name)
122168
if err != nil {

0 commit comments

Comments
 (0)