55 "fmt"
66 "math"
77 "sort"
8+ "strings"
89 "time"
910
10- "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil"
1111 "go.opentelemetry.io/collector/pdata/pcommon"
1212 "go.opentelemetry.io/collector/pdata/pmetric"
1313 semconv "go.opentelemetry.io/collector/semconv/v1.16.0"
@@ -27,9 +27,9 @@ func NewLineProtocolToOtelMetrics(logger common.Logger) (*LineProtocolToOtelMetr
2727
2828func (c * LineProtocolToOtelMetrics ) NewBatch () * MetricsBatch {
2929 return & MetricsBatch {
30- rmByAttributes : make (map [[ 16 ] byte ]pmetric.ResourceMetrics ),
31- ilmByRMAttributesAndIL : make (map [[ 16 ] byte ]map [string ]pmetric.ScopeMetrics ),
32- metricByRMIL : make (map [[ 16 ] byte ]map [string ]map [string ]pmetric.Metric ),
30+ rmByAttributes : make (map [string ]pmetric.ResourceMetrics ),
31+ ilmByRMAttributesAndIL : make (map [string ]map [string ]pmetric.ScopeMetrics ),
32+ metricByRMIL : make (map [string ]map [string ]map [string ]pmetric.Metric ),
3333 histogramDataPointsByMDPK : make (map [pmetric.Metric ]map [dataPointKey ]pmetric.HistogramDataPoint ),
3434 summaryDataPointsByMDPK : make (map [pmetric.Metric ]map [dataPointKey ]pmetric.SummaryDataPoint ),
3535
@@ -38,9 +38,9 @@ func (c *LineProtocolToOtelMetrics) NewBatch() *MetricsBatch {
3838}
3939
4040type MetricsBatch struct {
41- rmByAttributes map [[ 16 ] byte ]pmetric.ResourceMetrics
42- ilmByRMAttributesAndIL map [[ 16 ] byte ]map [string ]pmetric.ScopeMetrics
43- metricByRMIL map [[ 16 ] byte ]map [string ]map [string ]pmetric.Metric
41+ rmByAttributes map [string ]pmetric.ResourceMetrics
42+ ilmByRMAttributesAndIL map [string ]map [string ]pmetric.ScopeMetrics
43+ metricByRMIL map [string ]map [string ]map [string ]pmetric.Metric
4444 histogramDataPointsByMDPK map [pmetric.Metric ]map [dataPointKey ]pmetric.HistogramDataPoint
4545 summaryDataPointsByMDPK map [pmetric.Metric ]map [dataPointKey ]pmetric.SummaryDataPoint
4646
@@ -74,6 +74,23 @@ func (b *MetricsBatch) AddPoint(measurement string, tags map[string]string, fiel
7474
7575var errValueTypeUnknown = errors .New ("value type unknown" )
7676
77+ func attributeMapKey (attributes pcommon.Map ) string {
78+ keys := make ([]string , 0 , attributes .Len ())
79+ attributes .Range (func (key string , _ pcommon.Value ) bool {
80+ keys = append (keys , key )
81+ return true
82+ })
83+ sort .Strings (keys )
84+
85+ var key strings.Builder
86+ for _ , name := range keys {
87+ value , _ := attributes .Get (name )
88+ valueText := value .AsString ()
89+ fmt .Fprintf (& key , "%d:%s:%d:%d:%s" , len (name ), name , value .Type (), len (valueText ), valueText )
90+ }
91+ return key .String ()
92+ }
93+
7794func (b * MetricsBatch ) lookupMetric (metricName string , tags map [string ]string , vType common.InfluxMetricValueType ) (pmetric.Metric , pcommon.Map , error ) {
7895 var ilName , ilVersion string
7996 rAttributes := pcommon .NewMap ()
@@ -98,7 +115,7 @@ func (b *MetricsBatch) lookupMetric(metricName string, tags map[string]string, v
98115 }
99116 }
100117
101- rKey := pdatautil . MapHash (rAttributes )
118+ rKey := attributeMapKey (rAttributes )
102119 var resourceMetrics pmetric.ResourceMetrics
103120 if rm , found := b .rmByAttributes [rKey ]; found {
104121 resourceMetrics = rm
0 commit comments