tests

package module
Version: v0.0.0-...-e14f1b9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2021 License: Apache-2.0 Imports: 0 Imported by: 0

README

Splunk OpenTelemetry Collector Integration Tests and Utilities

To assist in vetting and validating the upstream and Splunk Collector distributions of the Collector, this library provides a set of integration tests and associated utilities. The general testing pattern this project is geared toward is:

  1. Building the Collector (make otelcol or make all)
  2. Defining your expected resource metric content as a yaml file (see example)
  3. Spin up your target resources as docker containers.
  4. Stand up an in-memory OTLP metrics receiver and sink capable of detecting if/when desired data are received.
  5. Spin up your Collector as a subprocess or as a container configured to report to this OTLP receiver.

...but if you are interested in something else enhancements and contributions are a great way to ensure this library is more useful overall.

At this time only limited metric content is supported. If you need additional metric functionality or trace/log helpers, please don't hesitate to contribute!

package example_test

import (
	"context"
	"path"
	"testing"
	"time"

	"github.com/stretchr/testify/require"

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

func TestMyExampleComponent(t *testing.T) {
	expectedResourceMetrics, err := testutils.LoadResourceMetrics(
		path.Join(".", "testdata", "my_resource_metrics.yaml"),
	)
	require.NoError(t, err)
	require.NotNil(t, expectedResourceMetrics)

	// combination OTLP Receiver consumertests.MetricsSink
	otlp, err := testutils.NewOTLPMetricsReceiverSink().WithEndpoint("localhost:23456").Build()
	require.NoError(t, err)
	require.NoError(t, otlp.Start())

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

	myContainer := testutils.NewContainer().WithImage("someTarget").Build()
	err = myContainer.Start(context.Background())
	require.NoError(t, err)

	// running collector subprocess that uses the provided config set to export OTLP to our test receiver
	myCollector, err := testutils.NewCollectorProcess().WithConfigPath(path.Join(".", "testdata", "config.yaml")).Build()
	require.NoError(t, err)
	err = myCollector.Start()
	require.NoError(t, err)
	defer func() {
		require.NoError(t, myCollector.Shutdown() )
	}()

	require.NoError(t, otlp.AssertAllMetricsReceived(t, *expectedResourceMetrics, 30*time.Second))
}

Documentation

Overview

Package splunk-otel-collector/tests provides end-to-end integration tests and utilities for verifying the Splunk OpenTelemetry Collector distribution and its components.

Source Files

Directories

Path Synopsis
Package testutils provides utilities for verifying the functionality of and content produced by collector components.
Package testutils provides utilities for verifying the functionality of and content produced by collector components.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL