generator

package module
v0.4.0 Latest Latest
Warning

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

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

README

xk6-opentelemetry logo xk6-opentelemetry

The xk6-opentelemetry project is a k6 extension that enables k6 users to generate random OpenTelemetry signals (metrics, logs, traces) for testing purposes.

Check the examples directory which contains some scripts to get started.

Features

  • Generate
    • ExportLogsServiceRequest
    • ExportMetricsServiceRequest (Types: gauge, sum, histogram)
    • ExportTraceServiceRequest
  • Set resource attributes

Development

As the testing environment and scripts rely on sending messages to Kafka, the extension xk6-kafka needs to be integrated as well when creating the k6 binary.

Create the binary:

git clone git@github.com:thmshmm/xk6-opentelemetry.git && cd xk6-opentelemetry
xk6 build --with xk6-opentelemetry=. --with github.com/mostafa/xk6-kafka

or use Task:

task build-k6

Testing

Local environment

Start a local test environment including Kafka (Redpanda) and an instance of the OpenTelemetry Collector using Docker Compose. The OTel Collector is configured to read messages using the Kafka receiver and write all messages to STDOUT of the container.

Start:

task testing-up

Stop:

task testing-down

Examples

Execute:

./k6 run examples/<SCRIPT>.js

Run all examples:

task run-examples

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportLogsServiceRequest

func ExportLogsServiceRequest(
	resourceAttrs []*commonpb.KeyValue,
	config LogConfig,
) *collogspb.ExportLogsServiceRequest

func ExportMetricsServiceRequest

func ExportMetricsServiceRequest(
	resourceAttrs []*commonpb.KeyValue,
	config MetricConfig,
) *colmetricspb.ExportMetricsServiceRequest

func ExportTraceServiceRequest

func ExportTraceServiceRequest(
	resourceAttrs []*commonpb.KeyValue,
	config TraceConfig,
) *coltracepb.ExportTraceServiceRequest

func ResourceLogs

func ResourceLogs(resourceAttrs []*commonpb.KeyValue, config LogConfig) *logspb.ResourceLogs

func ResourceMetrics

func ResourceMetrics(resourceAttrs []*commonpb.KeyValue, config MetricConfig) *metricspb.ResourceMetrics

func ResourceSpans

func ResourceSpans(resourceAttrs []*commonpb.KeyValue, config TraceConfig) *tracepb.ResourceSpans

func ToAnyValue

func ToAnyValue(attr interface{}) *commonpb.AnyValue

func ToAttributes

func ToAttributes(attrs map[string]interface{}) []*commonpb.KeyValue

Types

type GaugeData

type GaugeData struct {
	Value int64 `json:"value"`
}

type Generator

type Generator struct {
	*IDGenerator
	// contains filtered or unexported fields
}

func NewGenerator

func NewGenerator() *Generator

NewGenerator creates a Generator instance which can create supported OpenTelemetry signals.

func (*Generator) ExportLogsServiceRequest

func (g *Generator) ExportLogsServiceRequest(config LogConfig) []byte

func (*Generator) ExportMetricsServiceRequest

func (g *Generator) ExportMetricsServiceRequest(config MetricConfig) []byte

func (*Generator) ExportTraceServiceRequest

func (g *Generator) ExportTraceServiceRequest(config TraceConfig) []byte

func (*Generator) SetStaticResourceAttributes

func (g *Generator) SetStaticResourceAttributes(attrs map[string]interface{})

func (*Generator) TimeNowUnixNano

func (g *Generator) TimeNowUnixNano() int64

type HistogramData

type HistogramData struct {
	AggregationTemporality string    `json:"aggregationTemporality"`
	Count                  uint64    `json:"count"`
	Sum                    float64   `json:"sum"`
	Min                    float64   `json:"min"`
	Max                    float64   `json:"max"`
	ExplicitBounds         []float64 `json:"explicitBounds"`
	BucketCounts           []uint64  `json:"bucketCounts"`
}

type IDGenerator

type IDGenerator struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*IDGenerator) NewSpanID

func (idGen *IDGenerator) NewSpanID() string

func (*IDGenerator) NewTraceID

func (idGen *IDGenerator) NewTraceID() string

type LogConfig

type LogConfig struct {
	Attributes map[string]interface{} `js:"attributes"`
	Data       LogData                `js:"data"`
}

type LogData

type LogData struct {
	Body     string `js:"body"`
	Severity int32  `js:"severity"`
}

type MetricConfig

type MetricConfig struct {
	Type       string                 `js:"type"`
	Name       string                 `js:"name"`
	Unit       string                 `js:"unit"`
	Attributes map[string]interface{} `js:"attributes"`
	Data       map[string]interface{} `js:"data"`
}

type ModuleInstance

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

func (*ModuleInstance) Exports

func (mi *ModuleInstance) Exports() modules.Exports

Exports implements the modules.Instance interface and returns the exported types for the JS module.

type RootModule

type RootModule struct{}

func New

func New() *RootModule

New returns a pointer to a new RootModule instance.

func (*RootModule) NewModuleInstance

func (*RootModule) NewModuleInstance(_ modules.VU) modules.Instance

NewModuleInstance implements the modules.Module interface returning a new instance for each VU.

type SpanData

type SpanData struct {
	TraceID           string                 `js:"traceId"`
	SpanID            string                 `js:"spanId"`
	ParentSpanID      string                 `js:"parentSpanId"`
	Name              string                 `js:"name"`
	Attributes        map[string]interface{} `js:"attributes"`
	Kind              string                 `js:"kind"`
	StartTimeUnixNano uint64                 `js:"startTimeUnixNano"`
	EndTimeUnixNano   uint64                 `js:"endTimeUnixNano"`
}

type SumData

type SumData struct {
	Value                  int64  `json:"value"`
	IsMonotonic            bool   `json:"isMonotonic"`
	AggregationTemporality string `json:"aggregationTemporality"`
}

type TraceConfig

type TraceConfig struct {
	Data []SpanData `js:"data"`
}

Jump to

Keyboard shortcuts

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