@@ -136,6 +136,46 @@ func TestSample(t *testing.T) {
136136 }
137137 },
138138 },
139+ {
140+ name : "histogram with label" ,
141+ collect : func () {
142+ ss .AddSampleWithLabels ([]string {"foo" , "bar" }, 5.0 , []metrics.Label {metrics.Label {Name : "env" , Value : "dev" }})
143+ },
144+ createFn : func (t * testing.T ) func (context.Context , * monitoringpb.CreateTimeSeriesRequest ) (* emptypb.Empty , error ) {
145+ return func (_ context.Context , req * monitoringpb.CreateTimeSeriesRequest ) (* emptypb.Empty , error ) {
146+ want := & monitoringpb.CreateTimeSeriesRequest {
147+ Name : "projects/foo" ,
148+ TimeSeries : []* monitoringpb.TimeSeries {
149+ & monitoringpb.TimeSeries {
150+ Metric : & metricpb.Metric {
151+ Type : "custom.googleapis.com/go-metrics/foo_bar" ,
152+ Labels : map [string ]string {
153+ "env" : "dev" ,
154+ },
155+ },
156+ MetricKind : metric .MetricDescriptor_CUMULATIVE ,
157+ Points : []* monitoringpb.Point {
158+ & monitoringpb.Point {
159+ Value : & monitoringpb.TypedValue {
160+ Value : & monitoringpb.TypedValue_DistributionValue {
161+ DistributionValue : & distributionpb.Distribution {
162+ BucketCounts : []int64 {1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
163+ Count : 1 ,
164+ },
165+ },
166+ },
167+ },
168+ },
169+ },
170+ },
171+ }
172+ if diff := diffCreateMsg (want , req ); diff != "" {
173+ t .Errorf ("unexpected CreateTimeSeriesRequest (-want +got):\n %s" , diff )
174+ }
175+ return & emptypb.Empty {}, nil
176+ }
177+ },
178+ },
139179 {
140180 name : "hisogram with samples in multiple buckets" ,
141181 collect : func () {
@@ -249,6 +289,43 @@ func TestSample(t *testing.T) {
249289 }
250290 },
251291 },
292+ {
293+ name : "counter with label" ,
294+ collect : func () {
295+ ss .IncrCounterWithLabels ([]string {"foo" , "bar" }, 1.0 , []metrics.Label {metrics.Label {Name : "env" , Value : "dev" }})
296+ },
297+ createFn : func (t * testing.T ) func (context.Context , * monitoringpb.CreateTimeSeriesRequest ) (* emptypb.Empty , error ) {
298+ return func (_ context.Context , req * monitoringpb.CreateTimeSeriesRequest ) (* emptypb.Empty , error ) {
299+ want := & monitoringpb.CreateTimeSeriesRequest {
300+ Name : "projects/foo" ,
301+ TimeSeries : []* monitoringpb.TimeSeries {
302+ & monitoringpb.TimeSeries {
303+ Metric : & metricpb.Metric {
304+ Type : "custom.googleapis.com/go-metrics/foo_bar_counter" ,
305+ Labels : map [string ]string {
306+ "env" : "dev" ,
307+ },
308+ },
309+ MetricKind : metric .MetricDescriptor_GAUGE ,
310+ Points : []* monitoringpb.Point {
311+ & monitoringpb.Point {
312+ Value : & monitoringpb.TypedValue {
313+ Value : & monitoringpb.TypedValue_DoubleValue {
314+ DoubleValue : 1.0 ,
315+ },
316+ },
317+ },
318+ },
319+ },
320+ },
321+ }
322+ if diff := diffCreateMsg (want , req ); diff != "" {
323+ t .Errorf ("unexpected CreateTimeSeriesRequest (-want +got):\n %s" , diff )
324+ }
325+ return & emptypb.Empty {}, nil
326+ }
327+ },
328+ },
252329 {
253330 name : "multiple counts" ,
254331 collect : func () {
@@ -319,6 +396,43 @@ func TestSample(t *testing.T) {
319396 }
320397 },
321398 },
399+ {
400+ name : "gauge with label" ,
401+ collect : func () {
402+ ss .SetGaugeWithLabels ([]string {"foo" , "bar" }, 1.0 , []metrics.Label {metrics.Label {Name : "env" , Value : "dev" }})
403+ },
404+ createFn : func (t * testing.T ) func (context.Context , * monitoringpb.CreateTimeSeriesRequest ) (* emptypb.Empty , error ) {
405+ return func (_ context.Context , req * monitoringpb.CreateTimeSeriesRequest ) (* emptypb.Empty , error ) {
406+ want := & monitoringpb.CreateTimeSeriesRequest {
407+ Name : "projects/foo" ,
408+ TimeSeries : []* monitoringpb.TimeSeries {
409+ & monitoringpb.TimeSeries {
410+ Metric : & metricpb.Metric {
411+ Type : "custom.googleapis.com/go-metrics/foo_bar_gauge" ,
412+ Labels : map [string ]string {
413+ "env" : "dev" ,
414+ },
415+ },
416+ MetricKind : metric .MetricDescriptor_GAUGE ,
417+ Points : []* monitoringpb.Point {
418+ & monitoringpb.Point {
419+ Value : & monitoringpb.TypedValue {
420+ Value : & monitoringpb.TypedValue_DoubleValue {
421+ DoubleValue : 1.0 ,
422+ },
423+ },
424+ },
425+ },
426+ },
427+ },
428+ }
429+ if diff := diffCreateMsg (want , req ); diff != "" {
430+ t .Errorf ("unexpected CreateTimeSeriesRequest (-want +got):\n %s" , diff )
431+ }
432+ return & emptypb.Empty {}, nil
433+ }
434+ },
435+ },
322436 {
323437 name : "repeated gauge" ,
324438 collect : func () {
@@ -501,6 +615,123 @@ func TestExtract(t *testing.T) {
501615 }
502616 },
503617 },
618+ {
619+ name : "histogram with label" ,
620+ collect : func () {
621+ ss .AddSampleWithLabels ([]string {"foo" , "bar" }, 5.0 , []metrics.Label {metrics.Label {Name : "env" , Value : "dev" }})
622+ },
623+ createFn : func (t * testing.T ) func (context.Context , * monitoringpb.CreateTimeSeriesRequest ) (* emptypb.Empty , error ) {
624+ return func (_ context.Context , req * monitoringpb.CreateTimeSeriesRequest ) (* emptypb.Empty , error ) {
625+ want := & monitoringpb.CreateTimeSeriesRequest {
626+ Name : "projects/foo" ,
627+ TimeSeries : []* monitoringpb.TimeSeries {
628+ & monitoringpb.TimeSeries {
629+ Metric : & metricpb.Metric {
630+ Type : "custom.googleapis.com/go-metrics/foo" ,
631+ Labels : map [string ]string {
632+ "env" : "dev" ,
633+ "method" : "bar" ,
634+ },
635+ },
636+ MetricKind : metric .MetricDescriptor_CUMULATIVE ,
637+ Points : []* monitoringpb.Point {
638+ & monitoringpb.Point {
639+ Value : & monitoringpb.TypedValue {
640+ Value : & monitoringpb.TypedValue_DistributionValue {
641+ DistributionValue : & distributionpb.Distribution {
642+ BucketCounts : []int64 {1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
643+ Count : 1 ,
644+ },
645+ },
646+ },
647+ },
648+ },
649+ },
650+ },
651+ }
652+ if diff := diffCreateMsg (want , req ); diff != "" {
653+ t .Errorf ("unexpected CreateTimeSeriesRequest (-want +got):\n %s" , diff )
654+ }
655+ return & emptypb.Empty {}, nil
656+ }
657+ },
658+ },
659+ {
660+ name : "counter with label" ,
661+ collect : func () {
662+ ss .IncrCounterWithLabels ([]string {"foo" , "bar" }, 1.0 , []metrics.Label {metrics.Label {Name : "env" , Value : "dev" }})
663+ },
664+ createFn : func (t * testing.T ) func (context.Context , * monitoringpb.CreateTimeSeriesRequest ) (* emptypb.Empty , error ) {
665+ return func (_ context.Context , req * monitoringpb.CreateTimeSeriesRequest ) (* emptypb.Empty , error ) {
666+ want := & monitoringpb.CreateTimeSeriesRequest {
667+ Name : "projects/foo" ,
668+ TimeSeries : []* monitoringpb.TimeSeries {
669+ & monitoringpb.TimeSeries {
670+ Metric : & metricpb.Metric {
671+ Type : "custom.googleapis.com/go-metrics/foo" ,
672+ Labels : map [string ]string {
673+ "env" : "dev" ,
674+ "method" : "bar" ,
675+ },
676+ },
677+ MetricKind : metric .MetricDescriptor_GAUGE ,
678+ Points : []* monitoringpb.Point {
679+ & monitoringpb.Point {
680+ Value : & monitoringpb.TypedValue {
681+ Value : & monitoringpb.TypedValue_DoubleValue {
682+ DoubleValue : 1.0 ,
683+ },
684+ },
685+ },
686+ },
687+ },
688+ },
689+ }
690+ if diff := diffCreateMsg (want , req ); diff != "" {
691+ t .Errorf ("unexpected CreateTimeSeriesRequest (-want +got):\n %s" , diff )
692+ }
693+ return & emptypb.Empty {}, nil
694+ }
695+ },
696+ },
697+ {
698+ name : "gauge with label" ,
699+ collect : func () {
700+ ss .SetGaugeWithLabels ([]string {"foo" , "bar" }, 1.0 , []metrics.Label {metrics.Label {Name : "env" , Value : "dev" }})
701+ },
702+ createFn : func (t * testing.T ) func (context.Context , * monitoringpb.CreateTimeSeriesRequest ) (* emptypb.Empty , error ) {
703+ return func (_ context.Context , req * monitoringpb.CreateTimeSeriesRequest ) (* emptypb.Empty , error ) {
704+ want := & monitoringpb.CreateTimeSeriesRequest {
705+ Name : "projects/foo" ,
706+ TimeSeries : []* monitoringpb.TimeSeries {
707+ & monitoringpb.TimeSeries {
708+ Metric : & metricpb.Metric {
709+ Type : "custom.googleapis.com/go-metrics/foo" ,
710+ Labels : map [string ]string {
711+ "env" : "dev" ,
712+ "method" : "bar" ,
713+ },
714+ },
715+ MetricKind : metric .MetricDescriptor_GAUGE ,
716+ Points : []* monitoringpb.Point {
717+ & monitoringpb.Point {
718+ Value : & monitoringpb.TypedValue {
719+ Value : & monitoringpb.TypedValue_DoubleValue {
720+ DoubleValue : 1.0 ,
721+ },
722+ },
723+ },
724+ },
725+ },
726+ },
727+ }
728+ if diff := diffCreateMsg (want , req ); diff != "" {
729+ t .Errorf ("unexpected CreateTimeSeriesRequest (-want +got):\n %s" , diff )
730+ }
731+ return & emptypb.Empty {}, nil
732+ }
733+ },
734+ },
504735 }
505736
506737 for _ , tc := range tests {
0 commit comments