Skip to content

Commit

Permalink
remove resource_metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Jan 15, 2025
1 parent 68dfaa0 commit c3e6a70
Show file tree
Hide file tree
Showing 26 changed files with 7 additions and 2,489 deletions.
22 changes: 2 additions & 20 deletions tests/testutils/collector_process_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@
package testutils

import (
"path/filepath"
"strings"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/signalfx/splunk-otel-collector/tests/testutils/telemetry"
"strings"
"testing"
)

func TestCollectorPath(t *testing.T) {
Expand All @@ -41,16 +36,3 @@ func TestConfigPathNotRequiredUponBuildWithArgs(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, collector)
}

func TestCollectorProcessConfigSourced(t *testing.T) {
tc := NewTestcase(t)
defer tc.PrintLogsOnFailure()
defer tc.ShutdownOTLPReceiverSink()

_, shutdown := tc.SplunkOtelCollectorProcess("collector_process_config.yaml")
defer shutdown()

expectedMetrics, err := telemetry.LoadResourceMetrics(filepath.Join(".", "testdata", "expected_host_metrics.yaml"))
require.NoError(t, err)
require.NoError(t, tc.OTLPReceiverSink.AssertAllMetricsReceived(t, *expectedMetrics, 10*time.Second))
}
55 changes: 0 additions & 55 deletions tests/testutils/otlp_receiver_sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ package testutils
import (
"context"
"fmt"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/confignet"
Expand All @@ -34,8 +29,6 @@ import (
mnoop "go.opentelemetry.io/otel/metric/noop"
tnoop "go.opentelemetry.io/otel/trace/noop"
"go.uber.org/zap"

"github.com/signalfx/splunk-otel-collector/tests/testutils/telemetry"
)

// To be used as a builder whose Build() method provides the actual instance capable of starting the OTLP receiver
Expand Down Expand Up @@ -174,51 +167,3 @@ func (otlp *OTLPReceiverSink) SpanCount() int {
}
return otlp.tracesSink.SpanCount()
}

func (otlp *OTLPReceiverSink) Reset() {
if err := otlp.assertBuilt("Reset"); err == nil {
otlp.metricsSink.Reset()
otlp.logsSink.Reset()
otlp.tracesSink.Reset()
}
}

func (otlp *OTLPReceiverSink) AssertAllMetricsReceived(t testing.TB, expectedResourceMetrics telemetry.ResourceMetrics, waitTime time.Duration) error {
if err := otlp.assertBuilt("AssertAllMetricsReceived"); err != nil {
return err
}

if len(expectedResourceMetrics.ResourceMetrics) == 0 {
return fmt.Errorf("empty ResourceMetrics provided")
}

receivedMetrics := telemetry.ResourceMetrics{}

var err error
assert.Eventually(t, func() bool {
if otlp.DataPointCount() == 0 {
if err == nil {
err = fmt.Errorf("no metrics received")
}
return false
}
receivedOTLPMetrics := otlp.AllMetrics()
otlp.Reset()

receivedResourceMetrics, e := telemetry.PDataToResourceMetrics(receivedOTLPMetrics...)
require.NoError(t, e)
require.NotNil(t, receivedResourceMetrics)
receivedMetrics = telemetry.FlattenResourceMetrics(receivedMetrics, receivedResourceMetrics)

var containsOnly bool
containsOnly, err = receivedMetrics.ContainsOnly(expectedResourceMetrics)
return containsOnly
}, waitTime, 10*time.Millisecond, "Failed to receive expected metrics")

// testify won't render exceptionally long errors, so leaving this here for easy debugging
if err != nil {
fmt.Printf("err: %v\n", err)
}

return err
}
48 changes: 0 additions & 48 deletions tests/testutils/otlp_receiver_sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,6 @@ func TestBuildDefaults(t *testing.T) {
assert.NotNil(t, otlp.tracesSink)
}

func TestReceiverMethodsWithoutBuildingDisallowed(t *testing.T) {
otlp := NewOTLPReceiverSink()

err := otlp.Start()
require.Error(t, err)
require.EqualError(t, err, "cannot invoke Start() on an OTLPReceiverSink that hasn't been built")

err = otlp.Shutdown()
require.Error(t, err)
require.EqualError(t, err, "cannot invoke Shutdown() on an OTLPReceiverSink that hasn't been built")

metrics := otlp.AllMetrics()
require.Nil(t, metrics)

dataPointCount := otlp.DataPointCount()
require.Zero(t, dataPointCount)

// doesn't panic
otlp.Reset()

err = otlp.AssertAllMetricsReceived(t, telemetry.ResourceMetrics{}, 0)
require.Error(t, err)
require.EqualError(t, err, "cannot invoke AssertAllMetricsReceived() on an OTLPReceiverSink that hasn't been built")
}

func createOTLPFactoryParameters() (otlpexporter.Config, otelcolexporter.Settings) {
exporterCfg := otlpexporter.Config{
ClientConfig: configgrpc.ClientConfig{
Expand Down Expand Up @@ -159,26 +134,3 @@ func TestOTLPReceiverMetricsAvailableToSink(t *testing.T) {
return otlp.DataPointCount() == expectedCount
}, 5*time.Second, 1*time.Millisecond)
}

func TestAssertAllMetricsReceivedHappyPath(t *testing.T) {
otlp, err := NewOTLPReceiverSink().WithEndpoint("localhost:4317").Build()
require.NoError(t, err)

err = otlp.Start()
defer func() {
require.NoError(t, otlp.Shutdown())
}()
require.NoError(t, err)

exporter := otlpMetricsExporter(t)
defer func() { require.NoError(t, exporter.Shutdown(context.Background())) }()

metrics := telemetry.PDataMetrics()
err = exporter.ConsumeMetrics(context.Background(), metrics)
require.NoError(t, err)

resourceMetrics, err := telemetry.PDataToResourceMetrics(metrics)
resourceMetrics = telemetry.FlattenResourceMetrics(resourceMetrics)
require.NoError(t, err)
require.NoError(t, otlp.AssertAllMetricsReceived(t, resourceMetrics, 100*time.Millisecond))
}
201 changes: 0 additions & 201 deletions tests/testutils/telemetry/common.go

This file was deleted.

Loading

0 comments on commit c3e6a70

Please sign in to comment.