Skip to content

Commit

Permalink
Use existing hash function
Browse files Browse the repository at this point in the history
  • Loading branch information
SHaaD94 committed Mar 20, 2024
1 parent 740ec99 commit deca155
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 85 deletions.
6 changes: 3 additions & 3 deletions exporter/kafkaexporter/marshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func TestOTLPMetricsJsonMarshaling(t *testing.T) {
m.Gauge().DataPoints().At(0).SetDoubleValue(1.0)

r1 := pcommon.NewResource()
r1.Attributes().PutStr("service.name", "my_service_name")
r1.Attributes().PutStr("service.instance.id", "kek_x_2")
r1.Attributes().PutStr("service.name", "my_service_name")
r1.CopyTo(metric.ResourceMetrics().AppendEmpty().Resource())

standardMarshaler := metricsMarshalers()["otlp_json"]
Expand All @@ -111,8 +111,8 @@ func TestOTLPMetricsJsonMarshaling(t *testing.T) {
require.NoError(t, err, "Must have marshaled the data without error")
require.Len(t, msgs, 2, "Expected number of messages in the message")

require.Equal(t, sarama.ByteEncoder("90e74a8334a89993bd3f6ad05f9ca02438032a78d4399fb6fecf6c94fcdb13ef"), msgs[0].Key)
require.Equal(t, sarama.ByteEncoder("55e1113a2eace57b91ef58911d811c28e936365f03ac068e8ce23090d9ea748f"), msgs[1].Key)
require.Equal(t, sarama.ByteEncoder{0x62, 0x7f, 0x20, 0x34, 0x85, 0x49, 0x55, 0x2e, 0xfa, 0x93, 0xae, 0xd7, 0xde, 0x91, 0xd7, 0x16}, msgs[0].Key)
require.Equal(t, sarama.ByteEncoder{0x75, 0x6b, 0xb4, 0xd6, 0xff, 0xeb, 0x92, 0x22, 0xa, 0x68, 0x65, 0x48, 0xe0, 0xd3, 0x94, 0x44}, msgs[1].Key)
}

func TestOTLPTracesJsonMarshaling(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions exporter/kafkaexporter/pdata_marshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ package kafkaexporter // import "github.com/open-telemetry/opentelemetry-collect

import (
"github.com/IBM/sarama"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/resourceutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/traceutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/batchpersignal"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"
Expand Down Expand Up @@ -67,7 +67,7 @@ func (p pdataMetricsMarshaler) Marshal(ld pmetric.Metrics, topic string) ([]*sar

for i := 0; i < metrics.Len(); i++ {
resourceMetrics := metrics.At(i)
hash := resourceutil.CalculateResourceAttributesHash(resourceMetrics.Resource())
var hash = pdatautil.MapHash(resourceMetrics.Resource().Attributes())

newMetrics := pmetric.NewMetrics()
resourceMetrics.MoveTo(newMetrics.ResourceMetrics().AppendEmpty())
Expand All @@ -79,7 +79,7 @@ func (p pdataMetricsMarshaler) Marshal(ld pmetric.Metrics, topic string) ([]*sar
msgs = append(msgs, &sarama.ProducerMessage{
Topic: topic,
Value: sarama.ByteEncoder(bts),
Key: sarama.ByteEncoder(hash),
Key: sarama.ByteEncoder(hash[:]),
})
}
} else {
Expand Down
32 changes: 0 additions & 32 deletions internal/coreinternal/resourceutil/resourceutil.go

This file was deleted.

47 changes: 0 additions & 47 deletions internal/coreinternal/resourceutil/resourceutil_test.go

This file was deleted.

0 comments on commit deca155

Please sign in to comment.