config

package
v0.0.1-releasedebug Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultQuerySize   = 10
	DefaultTimeout     = 10 * time.Second
	DefaultMinDocCount = 1
	DefaultMetricType  = "gauge"
)

Default values

Variables

This section is empty.

Functions

func RegisterConnectionFlags

func RegisterConnectionFlags()

RegisterConnectionFlags defines the command-line flags related to Elasticsearch connection. This should be called *before* pflag.Parse().

Types

type ConnectionConfig

type ConnectionConfig struct {
	Addresses          []string      `yaml:"addresses"`
	Username           string        `yaml:"username,omitempty"` // omitempty useful for YAML
	Password           string        `yaml:"password,omitempty"` // omitempty useful for YAML
	APIKey             string        `yaml:"apiKey,omitempty"`   // Base64 encoded 'id:api_key'
	CloudID            string        `yaml:"cloudId,omitempty"`
	Timeout            time.Duration `yaml:"timeout"`
	HealthCheck        bool          `yaml:"healthCheck"`
	InsecureSkipVerify bool          `yaml:"insecureSkipVerify"`
}

ConnectionConfig holds Elasticsearch connection details.

func LoadConnectionConfig

func LoadConnectionConfig() (*ConnectionConfig, error)

LoadConnectionConfig creates a ConnectionConfig based on flags and environment variables. This must be called *after* pflag.Parse() has been called in main.go.

type LabelConfig

type LabelConfig struct {
	// TermLabel is the Prometheus label for the aggregation term/key.
	// Required only when query.term_field is specified.
	TermLabel string `yaml:"term_label,omitempty"`

	// Static labels are added to every metric produced by this config.
	Static map[string]string `yaml:"static,omitempty"`

	// SourceLabels define mappings from Elasticsearch _source fields to Prometheus labels.
	// Requires corresponding fields to be listed in query.source_fields.
	SourceLabels []SourceLabelConfig `yaml:"source_labels,omitempty"`
}

LabelConfig defines how aggregation results and source data map to Prometheus labels.

type MetricConfig

type MetricConfig struct {
	// Name is the Prometheus metric name (without namespace). Required.
	Name string `yaml:"name"`
	// Help is the Prometheus metric help text. Required.
	Help string `yaml:"help"`
	// Type is the Prometheus metric type. Only "gauge" is currently supported. Defaults to "gauge".
	Type string `yaml:"type,omitempty"`
	// Query defines the Elasticsearch query to execute. Required.
	Query QueryConfig `yaml:"query"`
	// Labels define how to label the resulting Prometheus metric. Required.
	Labels LabelConfig `yaml:"labels"`
}

MetricConfig defines a single Prometheus metric derived from an ES query.

func LoadQueryConfigs

func LoadQueryConfigs(dirPath string) ([]MetricConfig, error)

LoadQueryConfigs loads metric definitions from all YAML files in a directory.

func (*MetricConfig) Validate

func (mc *MetricConfig) Validate() error

Validate checks metric configuration for basic correctness and applies defaults.

type QueryConfig

type QueryConfig struct {
	// Indices are the Elasticsearch indices to target. Required.
	Indices []string `yaml:"indices"`

	// TermField specifies the field for a terms aggregation.
	// If set, the exporter performs a terms aggregation.
	// If empty, the exporter performs a direct search query.
	TermField string `yaml:"term_field,omitempty"`

	// FilterQuery is an optional Elasticsearch query DSL (in JSON string format)
	// used to filter documents *before* aggregation or direct search.
	FilterQuery string `yaml:"filter_query,omitempty"` // e.g., '{"term": {"status": "error"}}'

	// FilterQueryString is an optional Lucene query string syntax filter.
	// Use either filter_query or filter_query_string, not both.
	FilterQueryString string `yaml:"filter_query_string,omitempty"` // e.g., 'status:error AND NOT user:system'

	// Size determines the number of buckets for terms aggregations OR
	// the number of hits for direct search queries. Defaults to 10.
	Size int `yaml:"size"`

	// Missing provides a value to use for documents missing the term_field in aggregations.
	Missing *string `yaml:"missing,omitempty"`

	// MinDocCount filters terms aggregation buckets to only include those with
	// at least this many documents. Defaults to 1.
	MinDocCount *int `yaml:"min_doc_count,omitempty"`

	// SourceFields lists the fields to retrieve from the _source of matching documents.
	// Required if Labels.SourceLabels are defined.
	// For aggregations, this uses a top_hits sub-aggregation.
	// For direct searches, this limits the _source fields returned.
	SourceFields []string `yaml:"source_fields,omitempty"`
}

QueryConfig defines the specifics of an Elasticsearch query.

type SourceLabelConfig

type SourceLabelConfig struct {
	SourceField string `yaml:"field"` // The field name in the Elasticsearch _source document (can use dot notation for nested fields)
	PromLabel   string `yaml:"label"` // The desired Prometheus label name
}

SourceLabelConfig defines how to map an Elasticsearch source field to a Prometheus label.

type TopLevelMetrics

type TopLevelMetrics struct {
	Metrics []MetricConfig `yaml:"metrics"`
}

TopLevelMetrics is used for unmarshalling YAML files containing a list of metrics.

Jump to

Keyboard shortcuts

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