@@ -45,12 +45,14 @@ func TestProtoMetricToCreateTimeSeriesRequest(t *testing.T) {
4545 }
4646
4747 tests := []struct {
48+ name string
4849 in * metricspb.Metric
4950 want []* monitoringpb.CreateTimeSeriesRequest
5051 wantErr string
5152 statsExporter * statsExporter
5253 }{
5354 {
55+ name : "Test converting Distribution" ,
5456 in : & metricspb.Metric {
5557 MetricDescriptor : & metricspb.MetricDescriptor {
5658 Name : "with_metric_descriptor" ,
@@ -133,6 +135,65 @@ func TestProtoMetricToCreateTimeSeriesRequest(t *testing.T) {
133135 },
134136 },
135137 },
138+ {
139+ name : "Test some label keys don't have values" ,
140+ in : & metricspb.Metric {
141+ MetricDescriptor : & metricspb.MetricDescriptor {
142+ Name : "with_metric_descriptor_2" ,
143+ Description : "This is a test" ,
144+ Unit : "By" ,
145+ LabelKeys : []* metricspb.LabelKey {{Key : "key1" }, {Key : "key2" }, {Key : "key3" }},
146+ },
147+ Timeseries : []* metricspb.TimeSeries {
148+ {
149+ StartTimestamp : startTimestamp ,
150+ LabelValues : []* metricspb.LabelValue {{}, {}, {HasValue : true , Value : "val3" }},
151+ Points : []* metricspb.Point {
152+ {
153+ Timestamp : endTimestamp ,
154+ Value : & metricspb.Point_DoubleValue {
155+ DoubleValue : 25.0 ,
156+ },
157+ },
158+ },
159+ },
160+ },
161+ },
162+ statsExporter : & statsExporter {
163+ o : Options {ProjectID : "foo" , MapResource : defaultMapResource },
164+ },
165+ want : []* monitoringpb.CreateTimeSeriesRequest {
166+ {
167+ Name : "projects/foo" ,
168+ TimeSeries : []* monitoringpb.TimeSeries {
169+ {
170+ Metric : & googlemetricpb.Metric {
171+ Type : "custom.googleapis.com/opencensus/with_metric_descriptor_2" ,
172+ Labels : map [string ]string {"key3" : "val3" },
173+ },
174+ Resource : & monitoredrespb.MonitoredResource {
175+ Type : "global" ,
176+ },
177+ MetricKind : googlemetricpb .MetricDescriptor_CUMULATIVE ,
178+ ValueType : googlemetricpb .MetricDescriptor_DISTRIBUTION ,
179+ Points : []* monitoringpb.Point {
180+ {
181+ Interval : & monitoringpb.TimeInterval {
182+ StartTime : startTimestamp ,
183+ EndTime : endTimestamp ,
184+ },
185+ Value : & monitoringpb.TypedValue {
186+ Value : & monitoringpb.TypedValue_DoubleValue {
187+ DoubleValue : 25.0 ,
188+ },
189+ },
190+ },
191+ },
192+ },
193+ },
194+ },
195+ },
196+ },
136197 }
137198
138199 seenResources := make (map [* resourcepb.Resource ]* monitoredrespb.MonitoredResource )
@@ -145,12 +206,12 @@ func TestProtoMetricToCreateTimeSeriesRequest(t *testing.T) {
145206 allTss , err := protoMetricToTimeSeries (context .Background (), se , se .getResource (nil , tt .in , seenResources ), tt .in )
146207 if tt .wantErr != "" {
147208 if err == nil || ! strings .Contains (err .Error (), tt .wantErr ) {
148- t .Errorf ("#%d : unmatched error. Got\n \t %v\n Want\n \t %v" , i , err , tt .wantErr )
209+ t .Errorf ("#%v : unmatched error. Got\n \t %v\n Want\n \t %v" , tt . name , err , tt .wantErr )
149210 }
150211 continue
151212 }
152213 if err != nil {
153- t .Errorf ("#%d : unexpected error: %v" , i , err )
214+ t .Errorf ("#%v : unexpected error: %v" , tt . name , err )
154215 continue
155216 }
156217
0 commit comments