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
2
16
3
17
import (
4
18
"context"
@@ -9,16 +23,11 @@ import (
9
23
"go.opencensus.io/stats"
10
24
"go.opencensus.io/stats/view"
11
25
"go.opencensus.io/tag"
12
- monitoredrespb "google.golang.org/genproto/googleapis/api/monitoredres"
26
+ mrpb "google.golang.org/genproto/googleapis/api/monitoredres"
13
27
)
14
28
15
29
// This file defines various data needed for testing.
16
30
17
- func init () {
18
- // For testing convenience, we reduce maximum time series that metric client accepts.
19
- MaxTimeSeriesPerUpload = 3
20
- }
21
-
22
31
const (
23
32
label1name = "key_1"
24
33
label2name = "key_2"
@@ -32,11 +41,15 @@ const (
32
41
value4 = "value_4"
33
42
value5 = "value_5"
34
43
value6 = "value_6"
44
+ value7 = "value_7"
45
+ value8 = "value_8"
35
46
36
47
metric1name = "metric_1"
37
48
metric1desc = "this is metric 1"
38
49
metric2name = "metric_2"
39
50
metric2desc = "this is metric 2"
51
+ metric3name = "metric_3"
52
+ metric3desc = "this is metric 3"
40
53
41
54
project1 = "project-1"
42
55
project2 = "project-2"
@@ -45,14 +58,16 @@ const (
45
58
var (
46
59
ctx = context .Background ()
47
60
61
+ invalidDataErrStr = "invalid data"
48
62
// This error is used for test to catch some error happpened.
49
- invalidDataError = errors .New ("invalid data" )
63
+ invalidDataError = errors .New (invalidDataErrStr )
50
64
// This error is used for unexpected error.
51
65
unrecognizedDataError = errors .New ("unrecognized data" )
52
66
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 )
56
71
57
72
view1 = & view.View {
58
73
Name : metric1name ,
68
83
Measure : stats .Int64 (metric2name , metric2desc , stats .UnitDimensionless ),
69
84
Aggregation : view .Sum (),
70
85
}
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
+ }
71
93
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.
74
96
view1row1 = & view.Row {
75
97
Tags : nil ,
76
98
Data : & view.SumData {Value : 1 },
@@ -91,23 +113,30 @@ var (
91
113
Tags : []tag.Tag {{key1 , value4 }, {key2 , value5 }, {key3 , value6 }},
92
114
Data : & view.SumData {Value : 5 },
93
115
}
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
+ }
94
128
// This Row does not have valid Data field, so is invalid.
95
129
invalidRow = & view.Row {Data : nil }
96
130
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 {
103
132
Type : "cloudsql_database" ,
104
133
Labels : map [string ]string {
105
134
"project_id" : project1 ,
106
135
"region" : "us-central1" ,
107
136
"database_id" : "cloud-SQL-instance-1" ,
108
137
},
109
138
}
110
- resource2 = & monitoredrespb .MonitoredResource {
139
+ resource2 = & mrpb .MonitoredResource {
111
140
Type : "gce_instance" ,
112
141
Labels : map [string ]string {
113
142
"project_id" : project2 ,
@@ -117,6 +146,23 @@ var (
117
146
}
118
147
)
119
148
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
+
120
166
func getKey (name string ) tag.Key {
121
167
key , err := tag .NewKey (name )
122
168
if err != nil {
0 commit comments