Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions api/operator/v1beta1/vmagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ type VMAgentSpec struct {
// Works in combination with NamespaceSelector.
// +optional
ScrapeConfigSelector *metav1.LabelSelector `json:"scrapeConfigSelector,omitempty"`
// ScrapeClasses defines the list of scrape classes to expose to scraping objects such as
// PodScrapes, ServiceScrapes, Probes and ScrapeConfigs.
// +listType=map
// +listMapKey=name
// +optional
ScrapeClasses []ScrapeClass `json:"scrapeClasses,omitempty"`
// ScrapeConfigNamespaceSelector defines Namespaces to be selected for VMScrapeConfig discovery.
// Works in combination with Selector.
// NamespaceSelector nil - only objects at VMAgent namespace.
Expand Down Expand Up @@ -383,6 +389,34 @@ func (cr *VMAgent) Validate() error {
return fmt.Errorf("enableKubernetesAPISelectors cannot be used with daemonSetMode")
}
}
scrapeClassNames := make(map[string]struct{})
defaultScrapeClass := false
for _, sc := range cr.Spec.ScrapeClasses {
if _, ok := scrapeClassNames[sc.Name]; ok {
return fmt.Errorf("duplicate scrape class name %q", sc.Name)
}
if ptr.Deref(sc.Default, false) {
if defaultScrapeClass {
return fmt.Errorf("multiple default scrape classes defined")
}
defaultScrapeClass = true
}
if sc.TLSConfig != nil {
if err := sc.TLSConfig.Validate(); err != nil {
return fmt.Errorf("bad tlsConfig for scrape class %q: %w", sc.Name, err)
}
}
if len(sc.Relabelings) > 0 {
if err := checkRelabelConfigs(sc.Relabelings); err != nil {
return fmt.Errorf("bad relabelings for scrape class %q: %w", sc.Name, err)
}
}
if len(sc.MetricRelabelings) > 0 {
if err := checkRelabelConfigs(sc.MetricRelabelings); err != nil {
return fmt.Errorf("bad metricRelabelings for scrape class %q: %w", sc.Name, err)
}
}
}
return nil
}

Expand Down Expand Up @@ -446,6 +480,50 @@ type VMAgentRemoteWriteSettings struct {
UseMultiTenantMode bool `json:"useMultiTenantMode,omitempty"`
}

type ScrapeClass struct {
// name of the scrape class.
//
// +kubebuilder:validation:MinLength=1
// +required
Name string `json:"name"`

// default defines that the scrape applies to all scrape objects that
// don't configure an explicit scrape class name.
//
// Only one scrape class can be set as the default.
//
// +optional
Default *bool `json:"default,omitempty"`

// tlsConfig defines the TLS settings to use for the scrape. When the
// scrape objects define their own CA, certificate and/or key, they take
// precedence over the corresponding scrape class fields.
//
// For now only the `caFile`, `certFile` and `keyFile` fields are supported.
//
// +optional
TLSConfig *TLSConfig `json:"tlsConfig,omitempty"`

// authorization section for the ScrapeClass.
// It will only apply if the scrape resource doesn't specify any Authorization.
// +optional
Authorization *Authorization `json:"authorization,omitempty"`

// Relabelings defines the relabeling rules to apply to all scrape targets.
// +optional
Relabelings []*RelabelConfig `json:"relabelings,omitempty"`

// MetricRelabelings defines the relabeling rules to apply to all samples before ingestion.
// +optional
MetricRelabelings []*RelabelConfig `json:"metricRelabelings,omitempty"`

// AttachMetadata defines additional metadata to the discovered targets.
// When the scrape object defines its own configuration, it takes
// precedence over the scrape class configuration.
// +optional
AttachMetadata *AttachMetadata `json:"attachMetadata,omitempty"`
}

// AWS defines AWS cloud auth specific params
type AWS struct {
// EC2Endpoint is an optional AWS EC2 API endpoint to use for the corresponding -remoteWrite.url if -remoteWrite.aws.useSigv4 is set
Expand Down
3 changes: 3 additions & 0 deletions api/operator/v1beta1/vmservicescrape_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ type VMServiceScrapeSpec struct {
// AttachMetadata configures metadata attaching from service discovery
// +optional
AttachMetadata AttachMetadata `json:"attach_metadata,omitempty"`
// ScrapeClass defined scrape class to apply
// +optional
ScrapeClassName *string `json:"scrapeClass,omitempty"`
}

// UnmarshalJSON implements json.Unmarshaler interface
Expand Down
69 changes: 69 additions & 0 deletions api/operator/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading