@@ -28,18 +28,22 @@ type MetricData interface {
2828type AggregationTemporality struct {
2929 // Aggregation describes if the aggregator reports delta changes
3030 // since last report time, or cumulative changes since a fixed start time.
31- Aggregation pmetric.AggregationTemporality
32- }
33-
34- // UnmarshalText implements the encoding.TextUnmarshaler interface.
35- func (agg * AggregationTemporality ) UnmarshalText (text []byte ) error {
36- switch vtStr := string (text ); vtStr {
37- case "cumulative" :
38- agg .Aggregation = pmetric .AggregationTemporalityCumulative
39- case "delta" :
40- agg .Aggregation = pmetric .AggregationTemporalityDelta
41- default :
42- return fmt .Errorf ("invalid aggregation: %q" , vtStr )
31+ Aggregation pmetric.AggregationTemporality `mapstructure:"aggregation_temporality"`
32+ }
33+
34+ func (agg * AggregationTemporality ) Unmarshal (parser * confmap.Conf ) error {
35+ v := parser .Get ("aggregation_temporality" )
36+ if aggValue , ok := v .(pmetric.AggregationTemporality ); ok {
37+ agg .Aggregation = aggValue
38+ } else {
39+ switch v {
40+ case "cumulative" :
41+ agg .Aggregation = pmetric .AggregationTemporalityCumulative
42+ case "delta" :
43+ agg .Aggregation = pmetric .AggregationTemporalityDelta
44+ default :
45+ return fmt .Errorf ("invalid aggregation: %q" , v )
46+ }
4347 }
4448 return nil
4549}
@@ -73,22 +77,17 @@ func (mit MetricInputType) String() string {
7377// MetricValueType defines the metric number type.
7478type MetricValueType struct {
7579 // ValueType is type of the metric number, options are "double", "int".
76- ValueType pmetric.NumberDataPointValueType
80+ ValueType pmetric.NumberDataPointValueType `mapstructure:"value_type"`
7781}
7882
7983func (mvt * MetricValueType ) Unmarshal (parser * confmap.Conf ) error {
8084 if ! parser .IsSet ("value_type" ) {
8185 return errors .New ("missing required field: `value_type`" )
8286 }
83- return nil
84- }
85-
86- // UnmarshalText implements the encoding.TextUnmarshaler interface.
87- func (mvt * MetricValueType ) UnmarshalText (text []byte ) error {
88- switch vtStr := string (text ); vtStr {
89- case "int" :
87+ switch vtStr := parser .Get ("value_type" ); vtStr {
88+ case "int" , pmetric .NumberDataPointValueTypeInt :
9089 mvt .ValueType = pmetric .NumberDataPointValueTypeInt
91- case "double" :
90+ case "double" , pmetric . NumberDataPointValueTypeDouble :
9291 mvt .ValueType = pmetric .NumberDataPointValueTypeDouble
9392 default :
9493 return fmt .Errorf ("invalid value_type: %q" , vtStr )
@@ -116,7 +115,7 @@ func (mvt MetricValueType) BasicType() string {
116115}
117116
118117type gauge struct {
119- MetricValueType `mapstructure:"value_type "`
118+ MetricValueType `mapstructure:",squash "`
120119 MetricInputType `mapstructure:",squash"`
121120}
122121
@@ -141,9 +140,9 @@ func (d gauge) HasAggregated() bool {
141140}
142141
143142type sum struct {
144- AggregationTemporality `mapstructure:"aggregation_temporality "`
143+ AggregationTemporality `mapstructure:",squash "`
145144 Mono `mapstructure:",squash"`
146- MetricValueType `mapstructure:"value_type "`
145+ MetricValueType `mapstructure:",squash "`
147146 MetricInputType `mapstructure:",squash"`
148147}
149148
0 commit comments