scraperhelper

package
v0.99.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 18 Imported by: 89

Documentation

Overview

Package scraperhelper provides utilities for scrapers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewScraperControllerReceiver

func NewScraperControllerReceiver(
	cfg *ControllerConfig,
	set receiver.CreateSettings,
	nextConsumer consumer.Metrics,
	options ...ScraperControllerOption,
) (component.Component, error)

NewScraperControllerReceiver creates a Receiver with the configured options, that can control multiple scrapers.

Types

type ControllerConfig added in v0.95.0

type ControllerConfig struct {
	// CollectionInterval sets how frequently the scraper
	// should be called and used as the context timeout
	// to ensure that scrapers don't exceed the interval.
	CollectionInterval time.Duration `mapstructure:"collection_interval"`
	// InitialDelay sets the initial start delay for the scraper,
	// any non positive value is assumed to be immediately.
	InitialDelay time.Duration `mapstructure:"initial_delay"`
	// Timeout is an optional value used to set scraper's context deadline.
	Timeout time.Duration `mapstructure:"timeout"`
}

ControllerConfig defines common settings for a scraper controller configuration. Scraper controller receivers can embed this struct, instead of receiver.Settings, and extend it with more fields if needed.

func NewDefaultControllerConfig added in v0.95.0

func NewDefaultControllerConfig() ControllerConfig

NewDefaultControllerConfig returns default scraper controller settings with a collection interval of one minute.

func (*ControllerConfig) Validate added in v0.95.0

func (set *ControllerConfig) Validate() (errs error)

type ObsReport added in v0.86.0

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

ObsReport is a helper to add observability to a scraper.

func NewObsReport added in v0.86.0

func NewObsReport(cfg ObsReportSettings) (*ObsReport, error)

NewObsReport creates a new ObsReport.

func (*ObsReport) EndMetricsOp added in v0.86.0

func (s *ObsReport) EndMetricsOp(
	scraperCtx context.Context,
	numScrapedMetrics int,
	err error,
)

EndMetricsOp completes the scrape operation that was started with StartMetricsOp.

func (*ObsReport) StartMetricsOp added in v0.86.0

func (s *ObsReport) StartMetricsOp(ctx context.Context) context.Context

StartMetricsOp is called when a scrape operation is started. The returned context should be used in other calls to the obsreport functions dealing with the same scrape operation.

type ObsReportSettings added in v0.86.0

type ObsReportSettings struct {
	ReceiverID             component.ID
	Scraper                component.ID
	ReceiverCreateSettings receiver.CreateSettings
}

ObsReportSettings are settings for creating an ObsReport.

type ScrapeFunc

type ScrapeFunc func(context.Context) (pmetric.Metrics, error)

ScrapeFunc scrapes metrics.

func (ScrapeFunc) Scrape

func (sf ScrapeFunc) Scrape(ctx context.Context) (pmetric.Metrics, error)

type Scraper

type Scraper interface {
	component.Component

	// ID returns the scraper id.
	ID() component.ID
	Scrape(context.Context) (pmetric.Metrics, error)
}

Scraper is the base interface for scrapers.

func NewScraper

func NewScraper(name string, scrape ScrapeFunc, options ...ScraperOption) (Scraper, error)

NewScraper creates a Scraper that calls Scrape at the specified collection interval, reports observability information, and passes the scraped metrics to the next consumer.

type ScraperControllerOption

type ScraperControllerOption func(*controller)

ScraperControllerOption apply changes to internal options.

func AddScraper

func AddScraper(scraper Scraper) ScraperControllerOption

AddScraper configures the provided scrape function to be called with the specified options, and at the specified collection interval.

Observability information will be reported, and the scraped metrics will be passed to the next consumer.

func WithTickerChannel

func WithTickerChannel(tickerCh <-chan time.Time) ScraperControllerOption

WithTickerChannel allows you to override the scraper controller's ticker channel to specify when scrape is called. This is only expected to be used by tests.

type ScraperOption

type ScraperOption func(*baseScraper)

ScraperOption apply changes to internal options.

func WithShutdown

func WithShutdown(shutdown component.ShutdownFunc) ScraperOption

WithShutdown sets the function that will be called on shutdown.

func WithStart

func WithStart(start component.StartFunc) ScraperOption

WithStart sets the function that will be called on startup.

Jump to

Keyboard shortcuts

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