Documentation ¶
Index ¶
- Constants
- Variables
- func AddAPIServerConfigToStore(ctx context.Context, store *assets.Store, namespace string, ...) error
- func AddAlertmanagerEndpointsToStore(ctx context.Context, store *assets.Store, namespace string, ...) error
- func AddRemoteReadsToStore(ctx context.Context, store *assets.Store, namespace string, ...) error
- func AddRemoteWritesToStore(ctx context.Context, store *assets.Store, namespace string, ...) error
- func AddScrapeClassesToStore(ctx context.Context, store *assets.Store, namespace string, ...) error
- func ApplyConfigurationFromPrometheus(p *monitoringv1.Prometheus, updateScaleSubresource bool) *monitoringv1ac.PrometheusApplyConfiguration
- func ApplyConfigurationFromPrometheusAgent(p *monitoringv1alpha1.PrometheusAgent, updateScaleSubresource bool) *monitoringv1alpha1ac.PrometheusAgentApplyConfiguration
- func BuildCommonPrometheusArgs(cpf monitoringv1.CommonPrometheusFields, cg *ConfigGenerator) []monitoringv1.Argument
- func BuildCommonVolumes(p monitoringv1.PrometheusInterface, tlsSecrets *operator.ShardedSecret) ([]v1.Volume, []v1.VolumeMount, error)
- func BuildConfigReloader(p monitoringv1.PrometheusInterface, c *Config, initContainer bool, ...) v1.Container
- func BuildPodMetadata(cpf monitoringv1.CommonPrometheusFields, cg *ConfigGenerator) (map[string]string, map[string]string)
- func CompareScrapeTimeoutToScrapeInterval(scrapeTimeout, scrapeInterval monitoringv1.Duration) error
- func ConfigSecretName(p monitoringv1.PrometheusInterface) string
- func ExpectedStatefulSetShardNames(p monitoringv1.PrometheusInterface) []string
- func GetStatupProbePeriodSecondsAndFailureThreshold(cfp monitoringv1.CommonPrometheusFields) (int32, int32)
- func KeyToStatefulSetKey(p monitoringv1.PrometheusInterface, key string, shard int) string
- func MakeConfigurationSecret(p monitoringv1.PrometheusInterface, config Config, data []byte) (*v1.Secret, error)
- func MakeK8sTopologySpreadConstraint(selectorLabels map[string]string, tscs []monitoringv1.TopologySpreadConstraint) []v1.TopologySpreadConstraint
- func NewTLSAssetSecret(p monitoringv1.PrometheusInterface, config Config) *v1.Secret
- func ProbeHandler(probePath string, cpf monitoringv1.CommonPrometheusFields, ...) v1.ProbeHandler
- func ReplicasNumberPtr(p monitoringv1.PrometheusInterface) *int32
- func ShareProcessNamespace(p monitoringv1.PrometheusInterface) *bool
- func StatefulSetKeyToPrometheusKey(key string) (bool, string)
- func SubPathForStorage(s *monitoringv1.StorageSpec) string
- func TLSAssetsSecretName(p monitoringv1.PrometheusInterface) string
- func UsesDefaultQueryLogVolume(queryLogFile string) bool
- func ValidateAlertmanagerEndpoints(am monitoringv1.AlertmanagerEndpoints) error
- func ValidateRemoteWriteSpec(spec monitoringv1.RemoteWriteSpec) error
- func VolumeClaimName(p monitoringv1.PrometheusInterface, cpf monitoringv1.CommonPrometheusFields) string
- func VolumeName(p monitoringv1.PrometheusInterface) string
- func WebConfigSecretName(p monitoringv1.PrometheusInterface) string
- type Collector
- type Config
- type ConfigGenerator
- func (cg *ConfigGenerator) AddHonorLabels(cfg yaml.MapSlice, honorLabels bool) yaml.MapSlice
- func (cg *ConfigGenerator) AddHonorTimestamps(cfg yaml.MapSlice, userHonorTimestamps *bool) yaml.MapSlice
- func (cg *ConfigGenerator) AddLimitsToYAML(cfg yaml.MapSlice, k limitKey, limit *uint64, enforcedLimit *uint64) yaml.MapSlice
- func (cg *ConfigGenerator) AddScrapeProtocols(cfg yaml.MapSlice, scrapeProtocols []monitoringv1.ScrapeProtocol) yaml.MapSlice
- func (cg *ConfigGenerator) AddTrackTimestampsStaleness(cfg yaml.MapSlice, trackTimestampsStaleness *bool) yaml.MapSlice
- func (cg *ConfigGenerator) AppendCommandlineArgument(m []monitoringv1.Argument, argument monitoringv1.Argument) []monitoringv1.Argument
- func (cg *ConfigGenerator) AppendMapItem(m yaml.MapSlice, k string, v interface{}) yaml.MapSlice
- func (cg *ConfigGenerator) EndpointSliceSupported() bool
- func (cg *ConfigGenerator) GenerateAgentConfiguration(ctx context.Context, sMons map[string]*monitoringv1.ServiceMonitor, ...) ([]byte, error)
- func (cg *ConfigGenerator) GenerateServerConfiguration(ctx context.Context, evaluationInterval monitoringv1.Duration, ...) ([]byte, error)
- func (cg *ConfigGenerator) IsCompatible() bool
- func (cg *ConfigGenerator) MergeTLSConfigWithScrapeClass(tlsConfig *monitoringv1.TLSConfig, scrapeClass *monitoringv1.ScrapeClass) *monitoringv1.TLSConfig
- func (cg *ConfigGenerator) Warn(field string)
- func (cg *ConfigGenerator) WithKeyVals(keyvals ...interface{}) *ConfigGenerator
- func (cg *ConfigGenerator) WithMaximumVersion(version string) *ConfigGenerator
- func (cg *ConfigGenerator) WithMinimumVersion(version string) *ConfigGenerator
- type ListAllByNamespaceFn
- type ResourceSelector
- func (rs *ResourceSelector) SelectPodMonitors(ctx context.Context, listFn ListAllByNamespaceFn) (map[string]*monitoringv1.PodMonitor, error)
- func (rs *ResourceSelector) SelectProbes(ctx context.Context, listFn ListAllByNamespaceFn) (map[string]*monitoringv1.Probe, error)
- func (rs *ResourceSelector) SelectScrapeConfigs(ctx context.Context, listFn ListAllByNamespaceFn) (map[string]*monitoringv1alpha1.ScrapeConfig, error)
- func (rs *ResourceSelector) SelectServiceMonitors(ctx context.Context, listFn ListAllByNamespaceFn) (map[string]*monitoringv1.ServiceMonitor, error)
- type StatusReporter
Constants ¶
const ( StorageDir = "/prometheus" ConfDir = "/etc/prometheus/config" ConfOutDir = "/etc/prometheus/config_out" WebConfigDir = "/etc/prometheus/web_config" //TODO: RulesDir should be moved to the server package, since it is not used by the agent. // It is here at the moment because promcfg uses it, and moving as is will cause import cycle error. RulesDir = "/etc/prometheus/rules" ConfigFilename = "prometheus.yaml.gz" ConfigEnvsubstFilename = "prometheus.env.yaml" SSetInputHashName = "prometheus-operator-input-hash" DefaultPortName = "web" DefaultQueryLogDirectory = "/var/log/prometheus" )
Variables ¶
var ( ShardLabelName = "operator.prometheus.io/shard" PrometheusNameLabelName = "operator.prometheus.io/name" PrometheusModeLabeLName = "operator.prometheus.io/mode" PrometheusK8sLabelName = "app.kubernetes.io/name" ProbeTimeoutSeconds int32 = 3 LabelPrometheusName = "prometheus-name" )
Functions ¶
func AddAPIServerConfigToStore ¶ added in v0.67.0
func AddAlertmanagerEndpointsToStore ¶ added in v0.69.1
func AddRemoteReadsToStore ¶ added in v0.67.0
func AddRemoteWritesToStore ¶ added in v0.67.0
func AddScrapeClassesToStore ¶ added in v0.72.0
func ApplyConfigurationFromPrometheus ¶ added in v0.69.1
func ApplyConfigurationFromPrometheus(p *monitoringv1.Prometheus, updateScaleSubresource bool) *monitoringv1ac.PrometheusApplyConfiguration
ApplyConfigurationFromPrometheus updates the Prometheus/PrometheusAgent Status subresource. It can optionally update the scale subresource as well.
func ApplyConfigurationFromPrometheusAgent ¶ added in v0.69.1
func ApplyConfigurationFromPrometheusAgent(p *monitoringv1alpha1.PrometheusAgent, updateScaleSubresource bool) *monitoringv1alpha1ac.PrometheusAgentApplyConfiguration
func BuildCommonPrometheusArgs ¶ added in v0.64.0
func BuildCommonPrometheusArgs(cpf monitoringv1.CommonPrometheusFields, cg *ConfigGenerator) []monitoringv1.Argument
BuildCommonPrometheusArgs builds a slice of arguments that are common between Prometheus Server and Agent.
func BuildCommonVolumes ¶ added in v0.64.0
func BuildCommonVolumes(p monitoringv1.PrometheusInterface, tlsSecrets *operator.ShardedSecret) ([]v1.Volume, []v1.VolumeMount, error)
BuildCommonVolumes returns a set of volumes to be mounted on statefulset spec that are common between Prometheus Server and Agent.
func BuildConfigReloader ¶ added in v0.70.0
func BuildConfigReloader( p monitoringv1.PrometheusInterface, c *Config, initContainer bool, mounts []v1.VolumeMount, watchedDirectories []string, opts ...operator.ReloaderOption, ) v1.Container
func BuildPodMetadata ¶ added in v0.64.0
func BuildPodMetadata(cpf monitoringv1.CommonPrometheusFields, cg *ConfigGenerator) (map[string]string, map[string]string)
func CompareScrapeTimeoutToScrapeInterval ¶ added in v0.64.0
func CompareScrapeTimeoutToScrapeInterval(scrapeTimeout, scrapeInterval monitoringv1.Duration) error
CompareScrapeTimeoutToScrapeInterval validates value of scrapeTimeout based on scrapeInterval.
func ConfigSecretName ¶ added in v0.64.0
func ConfigSecretName(p monitoringv1.PrometheusInterface) string
func ExpectedStatefulSetShardNames ¶ added in v0.64.0
func ExpectedStatefulSetShardNames( p monitoringv1.PrometheusInterface, ) []string
func GetStatupProbePeriodSecondsAndFailureThreshold ¶ added in v0.71.0
func GetStatupProbePeriodSecondsAndFailureThreshold(cfp monitoringv1.CommonPrometheusFields) (int32, int32)
func KeyToStatefulSetKey ¶ added in v0.64.0
func KeyToStatefulSetKey(p monitoringv1.PrometheusInterface, key string, shard int) string
func MakeConfigurationSecret ¶ added in v0.67.0
func MakeConfigurationSecret(p monitoringv1.PrometheusInterface, config Config, data []byte) (*v1.Secret, error)
func MakeK8sTopologySpreadConstraint ¶ added in v0.71.0
func MakeK8sTopologySpreadConstraint(selectorLabels map[string]string, tscs []monitoringv1.TopologySpreadConstraint) []v1.TopologySpreadConstraint
func NewTLSAssetSecret ¶ added in v0.64.0
func NewTLSAssetSecret(p monitoringv1.PrometheusInterface, config Config) *v1.Secret
func ProbeHandler ¶ added in v0.64.0
func ProbeHandler(probePath string, cpf monitoringv1.CommonPrometheusFields, webConfigGenerator *ConfigGenerator) v1.ProbeHandler
func ReplicasNumberPtr ¶ added in v0.67.0
func ReplicasNumberPtr( p monitoringv1.PrometheusInterface, ) *int32
ReplicasNumberPtr returns a ptr to the normalized number of replicas.
func ShareProcessNamespace ¶ added in v0.70.0
func ShareProcessNamespace(p monitoringv1.PrometheusInterface) *bool
func StatefulSetKeyToPrometheusKey ¶ added in v0.64.0
func SubPathForStorage ¶ added in v0.64.0
func SubPathForStorage(s *monitoringv1.StorageSpec) string
TODO: Storage methods should be moved to server package. It is stil here because promcfg still uses it.
func TLSAssetsSecretName ¶ added in v0.64.0
func TLSAssetsSecretName(p monitoringv1.PrometheusInterface) string
func UsesDefaultQueryLogVolume ¶ added in v0.64.0
TODO: QueryLogFile methods should be moved to server package. They are still here because promcfg is using them.
func ValidateAlertmanagerEndpoints ¶ added in v0.69.1
func ValidateAlertmanagerEndpoints(am monitoringv1.AlertmanagerEndpoints) error
func ValidateRemoteWriteSpec ¶ added in v0.64.0
func ValidateRemoteWriteSpec(spec monitoringv1.RemoteWriteSpec) error
ValidateRemoteWriteSpec checks that mutually exclusive configurations are not included in the Prometheus remoteWrite configuration section, while also validating the RemoteWriteSpec child fields. Reference: https://github.com/prometheus/prometheus/blob/main/docs/configuration/configuration.md#remote_write
func VolumeClaimName ¶ added in v0.66.0
func VolumeClaimName(p monitoringv1.PrometheusInterface, cpf monitoringv1.CommonPrometheusFields) string
func VolumeName ¶ added in v0.64.0
func VolumeName(p monitoringv1.PrometheusInterface) string
func WebConfigSecretName ¶ added in v0.49.0
func WebConfigSecretName(p monitoringv1.PrometheusInterface) string
Types ¶
type Collector ¶ added in v0.64.0
type Collector struct {
// contains filtered or unexported fields
}
func NewCollectorForStores ¶ added in v0.64.0
func (*Collector) Collect ¶ added in v0.64.0
func (c *Collector) Collect(ch chan<- prometheus.Metric)
Collect implements the prometheus.Collector interface.
func (*Collector) Describe ¶ added in v0.64.0
func (c *Collector) Describe(ch chan<- *prometheus.Desc)
Describe implements the prometheus.Collector interface.
type Config ¶
type Config struct { LocalHost string ReloaderConfig operator.ContainerConfig PrometheusDefaultBaseImage string ThanosDefaultBaseImage string Annotations operator.Map Labels operator.Map }
Config defines the operator's parameters for the Prometheus controllers. Whenever the value of one of these parameters is changed, it triggers an update of the managed statefulsets.
type ConfigGenerator ¶ added in v0.48.0
type ConfigGenerator struct {
// contains filtered or unexported fields
}
ConfigGenerator knows how to generate a Prometheus configuration which is compatible with a given Prometheus version.
func NewConfigGenerator ¶ added in v0.23.0
func NewConfigGenerator(logger log.Logger, p monitoringv1.PrometheusInterface, endpointSliceSupported bool) (*ConfigGenerator, error)
NewConfigGenerator creates a ConfigGenerator for the provided Prometheus resource.
func (*ConfigGenerator) AddHonorLabels ¶ added in v0.55.0
func (cg *ConfigGenerator) AddHonorLabels(cfg yaml.MapSlice, honorLabels bool) yaml.MapSlice
AddHonorLabels adds the honor_labels field into scrape configurations. if OverrideHonorLabels is true then honor_labels is always false.
func (*ConfigGenerator) AddHonorTimestamps ¶ added in v0.55.0
func (cg *ConfigGenerator) AddHonorTimestamps(cfg yaml.MapSlice, userHonorTimestamps *bool) yaml.MapSlice
AddHonorTimestamps adds the honor_timestamps field into scrape configurations. honor_timestamps is false only when the user specified it or when the global override applies. For backwards compatibility with Prometheus <2.9.0 we don't set honor_timestamps.
func (*ConfigGenerator) AddLimitsToYAML ¶ added in v0.55.0
func (cg *ConfigGenerator) AddLimitsToYAML(cfg yaml.MapSlice, k limitKey, limit *uint64, enforcedLimit *uint64) yaml.MapSlice
AddLimitsToYAML appends the given limit key to the configuration if supported by the Prometheus version.
func (*ConfigGenerator) AddScrapeProtocols ¶ added in v0.72.0
func (cg *ConfigGenerator) AddScrapeProtocols(cfg yaml.MapSlice, scrapeProtocols []monitoringv1.ScrapeProtocol) yaml.MapSlice
AddScrapeProtocols adds the scrape_protocols field into scrape configurations. For backwards compatibility with Prometheus <2.49.0 we don't set scrape_protocols.
func (*ConfigGenerator) AddTrackTimestampsStaleness ¶ added in v0.70.0
func (cg *ConfigGenerator) AddTrackTimestampsStaleness(cfg yaml.MapSlice, trackTimestampsStaleness *bool) yaml.MapSlice
AddTrackTimestampsStaleness adds the track_timestamps_staleness field into scrape configurations. For backwards compatibility with Prometheus <2.48.0 we don't set track_timestamps_staleness.
func (*ConfigGenerator) AppendCommandlineArgument ¶ added in v0.62.0
func (cg *ConfigGenerator) AppendCommandlineArgument(m []monitoringv1.Argument, argument monitoringv1.Argument) []monitoringv1.Argument
AppendCommandlineArgument appends the name/v argument to the given []monitoringv1.Argument and returns the updated slice.
func (*ConfigGenerator) AppendMapItem ¶ added in v0.55.0
func (cg *ConfigGenerator) AppendMapItem(m yaml.MapSlice, k string, v interface{}) yaml.MapSlice
AppendMapItem appends the k/v item to the given yaml.MapSlice and returns the updated slice.
func (*ConfigGenerator) EndpointSliceSupported ¶ added in v0.55.0
func (cg *ConfigGenerator) EndpointSliceSupported() bool
func (*ConfigGenerator) GenerateAgentConfiguration ¶ added in v0.64.0
func (cg *ConfigGenerator) GenerateAgentConfiguration( ctx context.Context, sMons map[string]*monitoringv1.ServiceMonitor, pMons map[string]*monitoringv1.PodMonitor, probes map[string]*monitoringv1.Probe, sCons map[string]*monitoringv1alpha1.ScrapeConfig, store *assets.Store, additionalScrapeConfigs []byte, ) ([]byte, error)
GenerateAgentConfiguration creates a serialized YAML representation of a Prometheus Agent configuration using the provided resources.
func (*ConfigGenerator) GenerateServerConfiguration ¶ added in v0.64.0
func (cg *ConfigGenerator) GenerateServerConfiguration( ctx context.Context, evaluationInterval monitoringv1.Duration, queryLogFile string, ruleSelector *metav1.LabelSelector, exemplars *monitoringv1.Exemplars, tsdb monitoringv1.TSDBSpec, alerting *monitoringv1.AlertingSpec, remoteRead []monitoringv1.RemoteReadSpec, sMons map[string]*monitoringv1.ServiceMonitor, pMons map[string]*monitoringv1.PodMonitor, probes map[string]*monitoringv1.Probe, sCons map[string]*monitoringv1alpha1.ScrapeConfig, store *assets.Store, additionalScrapeConfigs []byte, additionalAlertRelabelConfigs []byte, additionalAlertManagerConfigs []byte, ruleConfigMapNames []string, ) ([]byte, error)
GenerateServerConfiguration creates a serialized YAML representation of a Prometheus Server configuration using the provided resources.
func (*ConfigGenerator) IsCompatible ¶ added in v0.62.0
func (cg *ConfigGenerator) IsCompatible() bool
IsCompatible return true or false depending if the version being used is compatible.
func (*ConfigGenerator) MergeTLSConfigWithScrapeClass ¶ added in v0.72.0
func (cg *ConfigGenerator) MergeTLSConfigWithScrapeClass(tlsConfig *monitoringv1.TLSConfig, scrapeClass *monitoringv1.ScrapeClass) *monitoringv1.TLSConfig
func (*ConfigGenerator) Warn ¶ added in v0.62.0
func (cg *ConfigGenerator) Warn(field string)
Warn logs a warning.
func (*ConfigGenerator) WithKeyVals ¶ added in v0.55.0
func (cg *ConfigGenerator) WithKeyVals(keyvals ...interface{}) *ConfigGenerator
WithKeyVals returns a new ConfigGenerator with the same characteristics as the current object, expect that the keyvals are appended to the existing logger.
func (*ConfigGenerator) WithMaximumVersion ¶ added in v0.55.0
func (cg *ConfigGenerator) WithMaximumVersion(version string) *ConfigGenerator
WithMaximumVersion returns a new ConfigGenerator that does nothing (except logging a warning message) if the Prometheus version is greater than or equal to the given version. The method panics if version isn't a valid SemVer value.
func (*ConfigGenerator) WithMinimumVersion ¶ added in v0.55.0
func (cg *ConfigGenerator) WithMinimumVersion(version string) *ConfigGenerator
WithMinimumVersion returns a new ConfigGenerator that does nothing (except logging a warning message) if the Prometheus version is lesser than the given version. The method panics if version isn't a valid SemVer value.
type ListAllByNamespaceFn ¶ added in v0.65.1
type ResourceSelector ¶ added in v0.64.0
type ResourceSelector struct {
// contains filtered or unexported fields
}
func NewResourceSelector ¶ added in v0.64.0
func NewResourceSelector(l log.Logger, p monitoringv1.PrometheusInterface, store *assets.Store, namespaceInformers cache.SharedIndexInformer, metrics *operator.Metrics, eventRecorder record.EventRecorder) *ResourceSelector
func (*ResourceSelector) SelectPodMonitors ¶ added in v0.64.0
func (rs *ResourceSelector) SelectPodMonitors(ctx context.Context, listFn ListAllByNamespaceFn) (map[string]*monitoringv1.PodMonitor, error)
SelectPodMonitors selects PodMonitors based on the selectors in the Prometheus CR and filters them returning only those with a valid configuration. This function also populates authentication stores and performs validations against scrape intervals and relabel configs.
func (*ResourceSelector) SelectProbes ¶ added in v0.64.0
func (rs *ResourceSelector) SelectProbes(ctx context.Context, listFn ListAllByNamespaceFn) (map[string]*monitoringv1.Probe, error)
SelectProbes selects Probes based on the selectors in the Prometheus CR and filters them returning only those with a valid configuration. This function also populates authentication stores and performs validations against scrape intervals, relabel configs and Probe URLs.
func (*ResourceSelector) SelectScrapeConfigs ¶ added in v0.65.0
func (rs *ResourceSelector) SelectScrapeConfigs(ctx context.Context, listFn ListAllByNamespaceFn) (map[string]*monitoringv1alpha1.ScrapeConfig, error)
SelectScrapeConfigs selects ScrapeConfigs based on the selectors in the Prometheus CR and filters them returning only those with a valid configuration.
func (*ResourceSelector) SelectServiceMonitors ¶ added in v0.64.0
func (rs *ResourceSelector) SelectServiceMonitors(ctx context.Context, listFn ListAllByNamespaceFn) (map[string]*monitoringv1.ServiceMonitor, error)
SelectServiceMonitors selects ServiceMonitors based on the selectors in the Prometheus CR and filters them returning only those with a valid configuration. This function also populates authentication stores and performs validations against scrape intervals and relabel configs.
type StatusReporter ¶ added in v0.66.0
type StatusReporter struct { Kclient kubernetes.Interface Reconciliations *operator.ReconciliationTracker SsetInfs *informers.ForResource Rr *operator.ResourceReconciler }
func (*StatusReporter) Process ¶ added in v0.66.0
func (sr *StatusReporter) Process(ctx context.Context, p monitoringv1.PrometheusInterface, key string) (*monitoringv1.PrometheusStatus, error)
Process will determine the Status of a Prometheus resource (server or agent) depending on its current state in the cluster.