Skip to content

Commit

Permalink
fix embed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hughesjj committed Feb 26, 2024
1 parent 1ad36d7 commit 578c15a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions internal/receiver/discoveryreceiver/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func (e *evaluator) correlateResourceAttributes(from, to pcommon.Map, corr corre
// log failure and continue with existing config sans observer
e.logger.Debug(fmt.Sprintf("failed adding %q to %s", observerID, discovery.ReceiverConfigAttr), zap.String("receiver.type", receiverType), zap.String("receiver.name", receiverName), zap.Error(err))
} else {
// TODO hughesjj somewhere here
e.logger.Debug("Adding watch_observer to embedded receiver config receiver attrs", zap.String("observer", corr.observerID.String()), zap.String("receiver.type", receiverType), zap.String("receiver.name", receiverName))
e.correlations.UpdateAttrs(corr.receiverID, map[string]string{
updatedWithObserverAttr: updatedConfig,
Expand Down
16 changes: 8 additions & 8 deletions internal/receiver/discoveryreceiver/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.uber.org/zap/zaptest"

"github.com/signalfx/splunk-otel-collector/internal/common/discovery"
)

func setup(t *testing.T) (*evaluator, component.ID, observer.EndpointID) {
Expand Down Expand Up @@ -110,6 +108,7 @@ func TestEvaluateInvalidMatch(t *testing.T) {
}

func TestCorrelateResourceAttrs(t *testing.T) {
sampleType := component.MustNewID("SPLUNK_unit_test_receiver")
for _, embed := range []bool{false, true} {
t.Run(fmt.Sprintf("embed-%v", embed), func(t *testing.T) {
eval, _, endpointID := setup(t)
Expand All @@ -119,7 +118,7 @@ func TestCorrelateResourceAttrs(t *testing.T) {
observerID := component.MustNewIDWithName("type", "name")
eval.correlations.UpdateEndpoint(endpoint, addedState, observerID)

corr := eval.correlations.GetOrCreate(discovery.NoType, endpointID)
corr := eval.correlations.GetOrCreate(sampleType, endpointID)

from := pcommon.NewMap()
from.FromRaw(
Expand All @@ -130,7 +129,7 @@ func TestCorrelateResourceAttrs(t *testing.T) {

to := pcommon.NewMap()

require.Empty(t, eval.correlations.Attrs(discovery.NoType))
require.Empty(t, eval.correlations.Attrs(sampleType))
eval.correlateResourceAttributes(from, to, corr)

expectedResourceAttrs := map[string]any{
Expand All @@ -146,7 +145,7 @@ func TestCorrelateResourceAttrs(t *testing.T) {

require.Equal(t, expectedResourceAttrs, to.AsRaw())

attrs := eval.correlations.Attrs(discovery.NoType)
attrs := eval.correlations.Attrs(sampleType)

expectedAttrs := map[string]string{}
if embed {
Expand All @@ -159,6 +158,7 @@ func TestCorrelateResourceAttrs(t *testing.T) {
}

func TestCorrelateResourceAttrsWithExistingConfig(t *testing.T) {
sampleType := component.MustNewID("SPLUNK_unit_test_receiver")
for _, embed := range []bool{false, true} {
t.Run(fmt.Sprintf("embed-%v", embed), func(t *testing.T) {
eval, _, endpointID := setup(t)
Expand All @@ -168,7 +168,7 @@ func TestCorrelateResourceAttrsWithExistingConfig(t *testing.T) {
observerID := component.NewIDWithName("type", "name")
eval.correlations.UpdateEndpoint(endpoint, addedState, observerID)

corr := eval.correlations.GetOrCreate(discovery.NoType, endpointID)
corr := eval.correlations.GetOrCreate(sampleType, endpointID)

encodedConfig := base64.StdEncoding.EncodeToString([]byte("config: some config\nrule: some rule\n"))

Expand All @@ -182,7 +182,7 @@ func TestCorrelateResourceAttrsWithExistingConfig(t *testing.T) {

to := pcommon.NewMap()

require.Empty(t, eval.correlations.Attrs(discovery.NoType))
require.Empty(t, eval.correlations.Attrs(sampleType))
eval.correlateResourceAttributes(from, to, corr)

var receiverConfig string
Expand All @@ -201,7 +201,7 @@ func TestCorrelateResourceAttrsWithExistingConfig(t *testing.T) {

require.Equal(t, expectedResourceAttrs, to.AsRaw())

attrs := eval.correlations.Attrs(discovery.NoType)
attrs := eval.correlations.Attrs(sampleType)
expectedAttrs := map[string]string{}

if embed {
Expand Down

0 comments on commit 578c15a

Please sign in to comment.