testutil

package
v0.52.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package testutil provides easy ways to generate some random or deterministic data that can be use for tests or benchmarks.

All the publicly shared trace agent model is available.

It avoids the cumbersome step of having to redefine complicated structs in every test case and maintain common methods for quick access to almost all kind of stub data needed. It should NEVER be imported in a program, most likely in one-off projects or fuzz modes or test suites.

Index

Constants

This section is empty.

Variables

View Source
var (
	// OTLPFixedSpanID specifies a fixed test SpanID.
	OTLPFixedSpanID = pcommon.SpanID([8]byte{0x24, 0x0, 0x31, 0xea, 0xd7, 0x50, 0xe5, 0xf3})
	// OTLPFixedTraceID specifies a fixed test TraceID.
	OTLPFixedTraceID = pcommon.TraceID([16]byte{0x72, 0xdf, 0x52, 0xa, 0xf2, 0xbd, 0xe7, 0xa5, 0x24, 0x0, 0x31, 0xea, 0xd7, 0x50, 0xe5, 0xf3})
)
View Source
var YearNS = (time.Hour * 24 * 365).Nanoseconds()

YearNS is the number of nanoseconds in a year

Functions

func BucketWithSpans

func BucketWithSpans(spans []*pb.Span) *pb.ClientStatsBucket

BucketWithSpans returns a stats bucket populated with spans stats

func FindTCPPort

func FindTCPPort() (int, error)

FindTCPPort finds a free TCP port and returns it. If it fails, error will be non-nil.

func FreeTCPPort

func FreeTCPPort(t *testing.T) int

FreeTCPPort returns a free TCP port. Upon encountering an error, it uses t to fail the test and report it.

func GeneratePayload

func GeneratePayload(n int, tc *TraceConfig, sc *SpanConfig) pb.Traces

GeneratePayload generates a new payload. The last span of a generated trace is the "root" of that trace

func GenerateSpan

func GenerateSpan(c *SpanConfig) *pb.Span

GenerateSpan generates a random root span with all fields filled in.

func GenerateTrace

func GenerateTrace(tc *TraceConfig, sc *SpanConfig) pb.Trace

GenerateTrace generates a valid trace using the given config.

func GetTestSpan

func GetTestSpan() *pb.Span

GetTestSpan returns a Span with different fields set

func GetTestTraceChunks

func GetTestTraceChunks(traceN, size int, realisticIDs bool) []*pb.TraceChunk

GetTestTraceChunks returns a []TraceChunk that is composed by “traceN“ number of traces, each one composed by “size“ number of spans.

func GetTestTraces

func GetTestTraces(traceN, size int, realisticIDs bool) pb.Traces

GetTestTraces returns a []Trace that is composed by “traceN“ number of traces, each one composed by “size“ number of spans.

func NewOTLPSpan

func NewOTLPSpan(s *OTLPSpan) ptrace.Span

NewOTLPSpan creates a new OTLP Span with the given options.

func NewOTLPTracesRequest

func NewOTLPTracesRequest(defs []OTLPResourceSpan) ptraceotlp.ExportRequest

NewOTLPTracesRequest creates a new TracesRequest based on the given definitions.

func RandomBucket

func RandomBucket(n int) *pb.ClientStatsBucket

RandomBucket returns a bucket made from n random spans, useful to run benchmarks and tests

func RandomSizedBytes

func RandomSizedBytes(size int) []byte

RandomSizedBytes creates a random byte slice with the specified size.

func RandomSpan

func RandomSpan() *pb.Span

RandomSpan generates a wide-variety of spans, useful to test robustness & performance

func RandomSpanDuration

func RandomSpanDuration() int64

RandomSpanDuration generates a random span duration

func RandomSpanError

func RandomSpanError() int32

RandomSpanError generates a random span error code

func RandomSpanID

func RandomSpanID() uint64

RandomSpanID generates a random span ID

func RandomSpanLink() *pb.SpanLink

RandomSpanLink generates a random spanlink

func RandomSpanLinks() []*pb.SpanLink

RandomSpanLinks generates a random number of random spanlinks

func RandomSpanMeta

func RandomSpanMeta() map[string]string

RandomSpanMeta generates some random span metadata

func RandomSpanMetrics

func RandomSpanMetrics() map[string]float64

RandomSpanMetrics generates some random span metrics

func RandomSpanName

func RandomSpanName() string

RandomSpanName generates a random span name string

func RandomSpanParentID

func RandomSpanParentID() uint64

RandomSpanParentID generates a random span parent ID

func RandomSpanResource

func RandomSpanResource() string

RandomSpanResource generates a random span resource string

func RandomSpanService

func RandomSpanService() string

RandomSpanService generates a random span service string

func RandomSpanStart

func RandomSpanStart() int64

RandomSpanStart generates a span start timestamp

func RandomSpanTraceID

func RandomSpanTraceID() uint64

RandomSpanTraceID generates a random trace ID

func RandomSpanType

func RandomSpanType() string

RandomSpanType generates a random span type

func RandomStringMap

func RandomStringMap() map[string]string

RandomStringMap creates a random map with string keys and values.

func RandomTrace

func RandomTrace(maxLevels, maxSpans int) pb.Trace

RandomTrace generates a random trace with a depth from 1 to maxLevels of spans. Each level has at most maxSpans items.

func RandomTraceChunk

func RandomTraceChunk(maxLevels, maxSpans int) *pb.TraceChunk

RandomTraceChunk generates a random trace chunk with a depth from 1 to maxLevels of spans. Each level has at most maxSpans items.

func StatsPayloadSample added in v0.40.0

func StatsPayloadSample() *pb.ClientStatsPayload

StatsPayloadSample returns a populated client stats payload

func TestSpan

func TestSpan() *pb.Span

TestSpan returns a fix span with hardcoded info, useful for reproducible tests

func TraceChunkWithSpan

func TraceChunkWithSpan(span *pb.Span) *pb.TraceChunk

TraceChunkWithSpan wraps a `span` with pb.TraceChunk

func TraceChunkWithSpanAndPriority

func TraceChunkWithSpanAndPriority(span *pb.Span, priority int32) *pb.TraceChunk

TraceChunkWithSpanAndPriority wraps a `span` and `priority` with pb.TraceChunk

func TraceChunkWithSpans

func TraceChunkWithSpans(spans []*pb.Span) *pb.TraceChunk

TraceChunkWithSpans wraps `spans` with pb.TraceChunk

func TraceChunkWithSpansAndPriority

func TraceChunkWithSpansAndPriority(spans []*pb.Span, priority int32) *pb.TraceChunk

TraceChunkWithSpansAndPriority wraps `spans` and `priority` with pb.TraceChunk

func TracerPayloadWithChunk

func TracerPayloadWithChunk(chunk *pb.TraceChunk) *pb.TracerPayload

TracerPayloadWithChunk wraps `chunk` with pb.TraceChunk

func TracerPayloadWithChunks

func TracerPayloadWithChunks(chunks []*pb.TraceChunk) *pb.TracerPayload

TracerPayloadWithChunks wraps `chunks` with pb.TraceChunk

Types

type OTLPResourceSpan

type OTLPResourceSpan struct {
	LibName    string
	LibVersion string
	Attributes map[string]interface{}
	Spans      []*OTLPSpan
}

OTLPResourceSpan specifies the configuration for generating an OTLP ResourceSpan.

type OTLPSpan

type OTLPSpan struct {
	TraceID    [16]byte
	SpanID     [8]byte
	TraceState string
	ParentID   [8]byte
	Name       string
	Kind       ptrace.SpanKind
	Start, End uint64
	Attributes map[string]interface{}
	Events     []OTLPSpanEvent
	Links      []OTLPSpanLink
	StatusMsg  string
	StatusCode ptrace.StatusCode
}

OTLPSpan defines an OTLP test span.

type OTLPSpanEvent

type OTLPSpanEvent struct {
	Timestamp  uint64                 `json:"time_unix_nano"`
	Name       string                 `json:"name"`
	Attributes map[string]interface{} `json:"attributes"`
	Dropped    uint32                 `json:"dropped_attributes_count"`
}

OTLPSpanEvent defines an OTLP test span event.

type OTLPSpanLink struct {
	TraceID    string                 `json:"trace_id"`
	SpanID     string                 `json:"span_id"`
	TraceState string                 `json:"trace_state"`
	Attributes map[string]interface{} `json:"attributes"`
	Dropped    uint32                 `json:"dropped_attributes_count"`
}

OTLPSpanLink defines an OTLP test span link.

type SpanConfig

type SpanConfig struct {
	// MinTags specifies the minimum number of tags this span should have.
	MinTags int
	// MaxTags specifies the maximum number of tags this span should have.
	MaxTags int
}

SpanConfig defines the configuration for generating spans.

type TestBackoffTimer

type TestBackoffTimer struct {
	// contains filtered or unexported fields
}

TestBackoffTimer is a backoff timer that ticks on-demand.

func NewTestBackoffTimer

func NewTestBackoffTimer() *TestBackoffTimer

NewTestBackoffTimer creates a new instance of a TestBackoffTimer.

func (*TestBackoffTimer) Close

func (t *TestBackoffTimer) Close()

Close closes the ticking channel of this backoff timer.

func (*TestBackoffTimer) CurrentDelay

func (t *TestBackoffTimer) CurrentDelay() time.Duration

CurrentDelay in a TestBackoffTimer always returns 0.

func (*TestBackoffTimer) NumRetries

func (t *TestBackoffTimer) NumRetries() int

NumRetries in a TestBackoffTimer always returns 0.

func (*TestBackoffTimer) ReceiveTick

func (t *TestBackoffTimer) ReceiveTick() <-chan time.Time

ReceiveTick returns the channel where ticks are sent.

func (*TestBackoffTimer) Reset

func (t *TestBackoffTimer) Reset()

Reset in a TestBackoffTimer is a no-op.

func (*TestBackoffTimer) ScheduleRetry

func (t *TestBackoffTimer) ScheduleRetry(err error) (int, time.Duration)

ScheduleRetry on a TestBackoffTimer is a no-op.

func (*TestBackoffTimer) Stop

func (t *TestBackoffTimer) Stop()

Stop in a TestBackoffTimer is a no-op.

func (*TestBackoffTimer) TriggerTick

func (t *TestBackoffTimer) TriggerTick()

TriggerTick immediately sends a tick with the current timestamp through the ticking channel.

type TraceConfig

type TraceConfig struct {
	// MinSpans specifies the minimum number of spans per trace.
	MinSpans int
	// MaxSpans specifies the maximum number of spans per trace.
	MaxSpans int
	// Keep reports whether this trace should be marked as sampling priority
	// "User Keep"
	Keep bool
}

TraceConfig specifies trace generating configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL