Help us shape the future of Go! Take the 2026 Go Developer Survey

sampler

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer

type Consumer interface {
	Consume(s *Sample, custom interface{})
	Close()
}

Consumer receives a resulting Sample

type Producer

type Producer interface {
	Produce(ctx context.Context, sampleID uint64) (interface{}, error)
}

Producer is responsible for producing a single sample the function should return an error if it fails, custom can be used to send domain specific data to the collector.

type ProducerConsumer

type ProducerConsumer interface {
	Producer
	Consumer
}

type ProducerFunc

type ProducerFunc func(context.Context, uint64) (customData interface{}, err error)

func (ProducerFunc) Produce

func (f ProducerFunc) Produce(ctx context.Context, sampleID uint64) (interface{}, error)

type Runner

type Runner interface {
	Run(stop context.Context) (done context.Context)
}

Runner will run the sampler asynchronously, it returns a context immediately that the caller can wait on. the done context is cancelled when:

  • all the goroutines have completed
  • all samples have been collected

func NewWithProducerConsumer

func NewWithProducerConsumer(interval time.Duration, pc ProducerConsumer) Runner

type Sample

type Sample struct {
	// ID represents the number that uniquely identifies a given sample
	// from the following ordered sequence
	//  1, 2, 3 ... n
	ID         uint64
	StartedAt  time.Time
	FinishedAt time.Time
	// Err is set if the sample had an error (it failed), otherwise nil
	Err error
}

Sample holds information related to a sample

func (Sample) String

func (s Sample) String() string

type SortedByID

type SortedByID []*Sample

func (SortedByID) Len

func (s SortedByID) Len() int

func (SortedByID) Less

func (s SortedByID) Less(i, j int) bool

func (SortedByID) Swap

func (s SortedByID) Swap(i, j int)

type SortedByStartedAt

type SortedByStartedAt []*Sample

func (SortedByStartedAt) Len

func (s SortedByStartedAt) Len() int

func (SortedByStartedAt) Less

func (s SortedByStartedAt) Less(i, j int) bool

func (SortedByStartedAt) Swap

func (s SortedByStartedAt) Swap(i, j int)

Jump to

Keyboard shortcuts

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