scrape

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package scrape is the agent's own scrape loop with per-node budgets, staleness, and coverage status.

Index

Constants

View Source
const (
	ReasonTargetBudget = "target_budget"
	ReasonInvalid      = "invalid_target"
	ReasonUnreachable  = "unreachable"
	ReasonTimeout      = "timeout"
	ReasonTLS          = "tls"
	ReasonUnauthorized = "unauthorized"
	ReasonHTTPStatus   = "http_status"
	ReasonParse        = "parse"
	ReasonBodyLimit    = "body_limit"
	ReasonCredentials  = "credentials"
	ReasonError        = "error"
)

Reasons classify the last failure or drop of a target for coverage reporting.

View Source
const (
	ServiceAccountTokenFile = "/var/run/secrets/kubernetes.io/serviceaccount/token" //nolint:gosec // a file path, not a credential
	ServiceAccountCAFile    = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
)

Default in-pod credential paths used for kubelet scraping.

View Source
const (
	AnnotationScrape = "prometheus.io/scrape"
	AnnotationPort   = "prometheus.io/port"
	AnnotationPath   = "prometheus.io/path"
	AnnotationScheme = "prometheus.io/scheme"
)

Pod annotations for scrape discovery.

Variables

This section is empty.

Functions

This section is empty.

Types

type Budgets

type Budgets struct {
	MaxTargets          int
	MaxSeriesPerTarget  int
	MaxSeries           int
	MaxSamplesPerSecond int
}

Budgets bound the scrape work of one node. Zero means unlimited.

type Health

type Health string

Health of a target.

const (
	HealthUnknown Health = "unknown"
	HealthUp      Health = "up"
	HealthDown    Health = "down"
	HealthDropped Health = "dropped"
)

type KubeletOptions

type KubeletOptions struct {
	Node string
	// TokenFile and CAFile default to the pod ServiceAccount mount.
	TokenFile          string
	CAFile             string
	InsecureSkipVerify bool
}

KubeletOptions configures KubeletTargets.

type Manager

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

Manager runs one loop per accepted target.

func NewManager

func NewManager(o Options) *Manager

NewManager returns a Manager with defaults applied.

func (*Manager) ActiveSeries

func (m *Manager) ActiveSeries() int

ActiveSeries is the number of scraped series currently held against the node budget.

func (*Manager) Status

func (m *Manager) Status() []TargetStatus

Status returns every known target, dropped ones included, ordered by key.

func (*Manager) Stop

func (m *Manager) Stop()

Stop ends every loop, writing staleness markers.

func (*Manager) Sync

func (m *Manager) Sync(targets []Target)

Sync replaces the target set, admitting targets in order up to MaxTargets and staling removed ones.

type Options

type Options struct {
	Appendable      storage.Appendable
	Budgets         Budgets
	DefaultInterval time.Duration
	DefaultTimeout  time.Duration
	MaxBodyBytes    int64
	Logger          *slog.Logger
}

Options configures a Manager.

type Pod

type Pod struct {
	Namespace   string
	Name        string
	UID         string
	Node        string
	IP          string
	Phase       string
	Annotations map[string]string
	Ports       []PodPort
}

Pod is the subset of a pod needed for annotation discovery.

type PodPort

type PodPort struct {
	Container string
	Port      int
	Protocol  string
}

PodPort is one declared container port.

type TLSConfig

type TLSConfig struct {
	CAFile             string
	InsecureSkipVerify bool
	ServerName         string
}

TLSConfig configures server verification.

type Target

type Target struct {
	URL             string
	Labels          map[string]string
	BearerTokenFile string
	TLS             TLSConfig
	Interval        time.Duration
	Timeout         time.Duration
}

Target is one scrape endpoint; job and instance labels default to "scrape" and the URL host.

func KubeletTargets

func KubeletTargets(nodeIP string, port int, o KubeletOptions) []Target

KubeletTargets returns the kubelet /metrics and /metrics/cadvisor targets for a node.

func PodTargets

func PodTargets(pods []Pod) []Target

PodTargets returns targets for running annotated pods, one per declared TCP port without a port annotation.

func (Target) Key

func (t Target) Key() string

Key identifies a target by URL and labels.

type TargetStatus

type TargetStatus struct {
	Key            string
	URL            string
	Labels         map[string]string
	Health         Health
	Reason         string
	LastError      string
	LastScrape     time.Time
	LastDuration   time.Duration
	Samples        int
	Series         int
	SeriesDropped  uint64
	SamplesDropped uint64
	AppendErrors   uint64
}

TargetStatus reports one target for coverage.

Jump to

Keyboard shortcuts

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