@@ -42,6 +42,7 @@ import (
4242)
4343
4444var errNilMetric = errors .New ("expecting a non-nil metric" )
45+ var errNilMetricDescriptor = errors .New ("expecting a non-nil metric descriptor" )
4546
4647type metricProtoPayload struct {
4748 node * commonpb.Node
@@ -189,7 +190,10 @@ func (se *statsExporter) protoMetricToTimeSeries(ctx context.Context, node *comm
189190 resource = metric .Resource
190191 }
191192
192- metricName , _ , _ , _ := metricProseFromProto (metric )
193+ metricName , _ , _ , err := metricProseFromProto (metric )
194+ if err != nil {
195+ return nil , err
196+ }
193197 metricType , _ := se .metricTypeFromProto (metricName )
194198 metricLabelKeys := metric .GetMetricDescriptor ().GetLabelKeys ()
195199 metricKind , _ := protoMetricDescriptorTypeToMetricKind (metric )
@@ -322,7 +326,10 @@ func (se *statsExporter) protoToMonitoringMetricDescriptor(metric *metricspb.Met
322326 return nil , errNilMetric
323327 }
324328
325- metricName , description , unit , _ := metricProseFromProto (metric )
329+ metricName , description , unit , err := metricProseFromProto (metric )
330+ if err != nil {
331+ return nil , err
332+ }
326333 metricType , _ := se .metricTypeFromProto (metricName )
327334 displayName := se .displayName (metricName )
328335 metricKind , valueType := protoMetricDescriptorTypeToMetricKind (metric )
@@ -364,26 +371,23 @@ func labelDescriptorsFromProto(defaults map[string]labelValue, protoLabelKeys []
364371 return labelDescriptors
365372}
366373
367- func metricProseFromProto (metric * metricspb.Metric ) (name , description , unit string , ok bool ) {
368- mname := metric .GetMetricDescriptor ().GetName ()
369- if mname != "" {
370- name = mname
371- return
372- }
373-
374+ func metricProseFromProto (metric * metricspb.Metric ) (name , description , unit string , err error ) {
374375 md := metric .GetMetricDescriptor ()
376+ if md == nil {
377+ return "" , "" , "" , errNilMetricDescriptor
378+ }
375379
376380 name = md .GetName ()
377381 unit = md .GetUnit ()
378382 description = md .GetDescription ()
379383
380- if md != nil && md .Type == metricspb .MetricDescriptor_CUMULATIVE_INT64 {
384+ if md .Type == metricspb .MetricDescriptor_CUMULATIVE_INT64 {
381385 // If the aggregation type is count, which counts the number of recorded measurements, the unit must be "1",
382386 // because this view does not apply to the recorded values.
383387 unit = stats .UnitDimensionless
384388 }
385389
386- return
390+ return name , description , unit , nil
387391}
388392
389393func (se * statsExporter ) metricTypeFromProto (name string ) (string , bool ) {
0 commit comments