Documentation ¶
Overview ¶
Package customresourcestate contains JSON/YAML configuration structs and factories for generating custom resource state metrics from a config file.
Index ¶
- func FromConfig(decoder ConfigDecoder, discovererInstance *discovery.CRDiscoverer) (func() ([]customresource.RegistryFactory, error), error)
- func NewCustomResourceMetrics(resource Resource) (customresource.RegistryFactory, error)
- type ConfigDecoder
- type Generator
- type GroupVersionKind
- type Labels
- type Metric
- type MetricGauge
- type MetricInfo
- type MetricMeta
- type MetricStateSet
- type Metrics
- type MetricsSpec
- type Resource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromConfig ¶
func FromConfig(decoder ConfigDecoder, discovererInstance *discovery.CRDiscoverer) (func() ([]customresource.RegistryFactory, error), error)
FromConfig decodes a configuration source into a slice of `customresource.RegistryFactory` that are ready to use.
func NewCustomResourceMetrics ¶ added in v2.6.0
func NewCustomResourceMetrics(resource Resource) (customresource.RegistryFactory, error)
NewCustomResourceMetrics creates a customresource.RegistryFactory from a configuration object.
Types ¶
type ConfigDecoder ¶
type ConfigDecoder interface {
Decode(v interface{}) (err error)
}
ConfigDecoder is for use with FromConfig.
type Generator ¶
type Generator struct { // Each targets a value or values from the resource. Each Metric `yaml:"each" json:"each"` // Labels are added to all metrics. Labels from Each will overwrite these if using the same key. Labels `yaml:",inline" json:",inline"` // json will inline because it is already tagged // Name of the metric. Subject to prefixing based on the configuration of the Resource. Name string `yaml:"name" json:"name"` // Help text for the metric. Help string `yaml:"help" json:"help"` // ErrorLogV defines the verbosity threshold for errors logged for this metric. Must be non-zero to override the resource setting. ErrorLogV klog.Level `yaml:"errorLogV" json:"errorLogV"` }
Generator describes a unique metric name.
type GroupVersionKind ¶
type GroupVersionKind struct { Group string `yaml:"group" json:"group"` Version string `yaml:"version" json:"version"` Kind string `yaml:"kind" json:"kind"` }
GroupVersionKind is the Kubernetes group, version, and kind of a resource.
func (GroupVersionKind) String ¶ added in v2.9.0
func (gvk GroupVersionKind) String() string
type Labels ¶
type Labels struct { // CommonLabels are added to all metrics. CommonLabels map[string]string `yaml:"commonLabels" json:"commonLabels"` // LabelsFromPath adds additional labels where the value is taken from a field in the resource. LabelsFromPath map[string][]string `yaml:"labelsFromPath" json:"labelsFromPath"` }
Labels is common configuration of labels to add to metrics.
type Metric ¶ added in v2.6.0
type Metric struct { // Gauge defines a gauge metric. // +optional Gauge *MetricGauge `yaml:"gauge" json:"gauge"` // StateSet defines a state set metric. // +optional StateSet *MetricStateSet `yaml:"stateSet" json:"stateSet"` // Info defines an info metric. // +optional Info *MetricInfo `yaml:"info" json:"info"` // Type defines the type of the metric. // +unionDiscriminator Type metric.Type `yaml:"type" json:"type"` }
Metric defines a metric to expose. +union
type MetricGauge ¶ added in v2.6.0
type MetricGauge struct { // LabelFromKey adds a label with the given name if Path is an object. The label value will be the object key. LabelFromKey string `yaml:"labelFromKey" json:"labelFromKey"` MetricMeta `yaml:",inline" json:",inline"` // ValueFrom is the path to a numeric field under Path that will be the metric value. ValueFrom []string `yaml:"valueFrom" json:"valueFrom"` // NilIsZero indicates that if a value is nil it will be treated as zero value. NilIsZero bool `yaml:"nilIsZero" json:"nilIsZero"` }
MetricGauge targets a Path that may be a single value, array, or object. Arrays and objects will generate a metric per element. Ref: https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#gauge
type MetricInfo ¶ added in v2.6.0
type MetricInfo struct { // LabelFromKey adds a label with the given name if Path is an object. The label value will be the object key. LabelFromKey string `yaml:"labelFromKey" json:"labelFromKey"` MetricMeta `yaml:",inline" json:",inline"` }
MetricInfo is a metric which is used to expose textual information. Ref: https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#info
type MetricMeta ¶ added in v2.6.0
type MetricMeta struct { // LabelsFromPath adds additional labels where the value of the label is taken from a field under Path. LabelsFromPath map[string][]string `yaml:"labelsFromPath" json:"labelsFromPath"` // Path is the path to to generate metric(s) for. Path []string `yaml:"path" json:"path"` }
MetricMeta are variables which may used for any metric type.
type MetricStateSet ¶ added in v2.6.0
type MetricStateSet struct { MetricMeta `yaml:",inline" json:",inline"` // List is the list of values to expose a value for. List []string `yaml:"list" json:"list"` // LabelName is the key of the label which is used for each entry in List to expose the value. LabelName string `yaml:"labelName" json:"labelName"` // ValueFrom is the subpath to compare the list to. ValueFrom []string `yaml:"valueFrom" json:"valueFrom"` }
MetricStateSet is a metric which represent a series of related boolean values, also called a bitset. Ref: https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#stateset
type Metrics ¶
type Metrics struct {
Spec MetricsSpec `yaml:"spec" json:"spec"`
}
Metrics is the top level configuration object.
type MetricsSpec ¶
type MetricsSpec struct { // Resources is the list of custom resources to be monitored. A resource with the same GroupVersionKind may appear // multiple times (e.g., to customize the namespace or subsystem,) but will incur additional overhead. Resources []Resource `yaml:"resources" json:"resources"` }
MetricsSpec is the configuration describing the custom resource state metrics to generate.
type Resource ¶
type Resource struct { // Labels are added to all metrics. If the same key is used in a metric, the value from the metric will overwrite the value here. Labels `yaml:",inline" json:",inline"` // MetricNamePrefix defines a prefix for all metrics of the resource. // If set to "", no prefix will be added. // Example: If set to "foo", MetricNamePrefix will be "foo_<metric>". MetricNamePrefix *string `yaml:"metricNamePrefix" json:"metricNamePrefix"` // GroupVersionKind of the custom resource to be monitored. GroupVersionKind GroupVersionKind `yaml:"groupVersionKind" json:"groupVersionKind"` // ResourcePlural sets the plural name of the resource. Defaults to the plural version of the Kind according to flect.Pluralize. ResourcePlural string `yaml:"resourcePlural" json:"resourcePlural"` // Metrics are the custom resource fields to be collected. Metrics []Generator `yaml:"metrics" json:"metrics"` // ErrorLogV defines the verbosity threshold for errors logged for this resource. ErrorLogV klog.Level `yaml:"errorLogV" json:"errorLogV"` }
Resource configures a custom resource for metric generation.
func (Resource) GetMetricNamePrefix ¶ added in v2.6.0
GetMetricNamePrefix returns the prefix to use for metrics.
func (Resource) GetResourceName ¶
GetResourceName returns the lowercase, plural form of the resource Kind. This is ResourcePlural if it is set.