@@ -5,14 +5,9 @@ package elasticsearchexporter // import "github.com/open-telemetry/opentelemetry
5
5
6
6
import (
7
7
"bytes"
8
- "encoding/binary"
9
8
"encoding/json"
10
9
"errors"
11
10
"fmt"
12
- "hash"
13
- "hash/fnv"
14
- "math"
15
- "slices"
16
11
"time"
17
12
18
13
"go.opentelemetry.io/collector/pdata/pcommon"
@@ -81,7 +76,6 @@ type mappingModel interface {
81
76
encodeLog (pcommon.Resource , string , plog.LogRecord , pcommon.InstrumentationScope , string , elasticsearch.Index , * bytes.Buffer ) error
82
77
encodeSpan (pcommon.Resource , string , ptrace.Span , pcommon.InstrumentationScope , string , elasticsearch.Index , * bytes.Buffer ) error
83
78
encodeSpanEvent (resource pcommon.Resource , resourceSchemaURL string , span ptrace.Span , spanEvent ptrace.SpanEvent , scope pcommon.InstrumentationScope , scopeSchemaURL string , idx elasticsearch.Index , buf * bytes.Buffer )
84
- hashDataPoint (datapoints.DataPoint ) uint32
85
79
encodeMetrics (resource pcommon.Resource , resourceSchemaURL string , scope pcommon.InstrumentationScope , scopeSchemaURL string , dataPoints []datapoints.DataPoint , validationErrors * []error , idx elasticsearch.Index , buf * bytes.Buffer ) (map [string ]string , error )
86
80
encodeProfile (pcommon.Resource , pcommon.InstrumentationScope , pprofile.Profile , func (* bytes.Buffer , string , string ) error ) error
87
81
}
@@ -189,17 +183,6 @@ func (m *encodeModel) encodeLogECSMode(resource pcommon.Resource, record plog.Lo
189
183
return document
190
184
}
191
185
192
- // upsertMetricDataPointValue upserts a datapoint value to documents which is already hashed by resource and index
193
- func (m * encodeModel ) hashDataPoint (dp datapoints.DataPoint ) uint32 {
194
- switch m .mode {
195
- case MappingOTel :
196
- return metricOTelHash (dp , dp .Metric ().Unit ())
197
- default :
198
- // Defaults to ECS for backward compatibility
199
- return metricECSHash (dp .Timestamp (), dp .Attributes ())
200
- }
201
- }
202
-
203
186
func (m * encodeModel ) encodeDataPointsECSMode (resource pcommon.Resource , dataPoints []datapoints.DataPoint , validationErrors * []error , idx elasticsearch.Index , buf * bytes.Buffer ) (map [string ]string , error ) {
204
187
dp0 := dataPoints [0 ]
205
188
var document objmodel.Document
@@ -450,95 +433,3 @@ func encodeLogTimestampECSMode(document *objmodel.Document, record plog.LogRecor
450
433
451
434
document .AddTimestamp ("@timestamp" , record .ObservedTimestamp ())
452
435
}
453
-
454
- // TODO use https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/internal/exp/metrics/identity
455
- func metricECSHash (timestamp pcommon.Timestamp , attributes pcommon.Map ) uint32 {
456
- hasher := fnv .New32a ()
457
-
458
- timestampBuf := make ([]byte , 8 )
459
- binary .LittleEndian .PutUint64 (timestampBuf , uint64 (timestamp ))
460
- hasher .Write (timestampBuf )
461
-
462
- mapHashExcludeReservedAttrs (hasher , attributes )
463
-
464
- return hasher .Sum32 ()
465
- }
466
-
467
- func metricOTelHash (dp datapoints.DataPoint , unit string ) uint32 {
468
- hasher := fnv .New32a ()
469
-
470
- timestampBuf := make ([]byte , 8 )
471
- binary .LittleEndian .PutUint64 (timestampBuf , uint64 (dp .Timestamp ()))
472
- hasher .Write (timestampBuf )
473
-
474
- binary .LittleEndian .PutUint64 (timestampBuf , uint64 (dp .StartTimestamp ()))
475
- hasher .Write (timestampBuf )
476
-
477
- hasher .Write ([]byte (unit ))
478
-
479
- mapHashExcludeReservedAttrs (hasher , dp .Attributes (), elasticsearch .MappingHintsAttrKey )
480
-
481
- return hasher .Sum32 ()
482
- }
483
-
484
- // mapHashExcludeReservedAttrs is mapHash but ignoring some reserved attributes.
485
- // e.g. index is already considered during routing and DS attributes do not need to be considered in hashing
486
- func mapHashExcludeReservedAttrs (hasher hash.Hash , m pcommon.Map , extra ... string ) {
487
- m .Range (func (k string , v pcommon.Value ) bool {
488
- switch k {
489
- case elasticsearch .DataStreamType , elasticsearch .DataStreamDataset , elasticsearch .DataStreamNamespace :
490
- return true
491
- }
492
- if slices .Contains (extra , k ) {
493
- return true
494
- }
495
- hasher .Write ([]byte (k ))
496
- valueHash (hasher , v )
497
-
498
- return true
499
- })
500
- }
501
-
502
- func mapHash (hasher hash.Hash , m pcommon.Map ) {
503
- m .Range (func (k string , v pcommon.Value ) bool {
504
- hasher .Write ([]byte (k ))
505
- valueHash (hasher , v )
506
-
507
- return true
508
- })
509
- }
510
-
511
- func valueHash (h hash.Hash , v pcommon.Value ) {
512
- switch v .Type () {
513
- case pcommon .ValueTypeEmpty :
514
- h .Write ([]byte {0 })
515
- case pcommon .ValueTypeStr :
516
- h .Write ([]byte (v .Str ()))
517
- case pcommon .ValueTypeBool :
518
- if v .Bool () {
519
- h .Write ([]byte {1 })
520
- } else {
521
- h .Write ([]byte {0 })
522
- }
523
- case pcommon .ValueTypeDouble :
524
- buf := make ([]byte , 8 )
525
- binary .LittleEndian .PutUint64 (buf , math .Float64bits (v .Double ()))
526
- h .Write (buf )
527
- case pcommon .ValueTypeInt :
528
- buf := make ([]byte , 8 )
529
- binary .LittleEndian .PutUint64 (buf , uint64 (v .Int ()))
530
- h .Write (buf )
531
- case pcommon .ValueTypeBytes :
532
- h .Write (v .Bytes ().AsRaw ())
533
- case pcommon .ValueTypeMap :
534
- mapHash (h , v .Map ())
535
- case pcommon .ValueTypeSlice :
536
- sliceHash (h , v .Slice ())
537
- }
538
- }
539
-
540
- func sliceHash (h hash.Hash , s pcommon.Slice ) {
541
- for i := 0 ; i < s .Len (); i ++ {
542
- valueHash (h , s .At (i ))
543
- }
544
- }
0 commit comments