-
Notifications
You must be signed in to change notification settings - Fork 200
scrapeconfig: support more discovery mechanisms #1838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AndrewChubatiuk
wants to merge
3
commits into
master
Choose a base branch
from
support-more-sd-configs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,31 @@ import ( | |
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| ) | ||
|
|
||
| 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. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have checks to ensure this? |
||
| // | ||
| // +optional | ||
| Default *bool `json:"default,omitempty"` | ||
|
|
||
| EndpointAuth `json:",inline"` | ||
| EndpointRelabelings `json:",inline"` | ||
|
|
||
| // 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"` | ||
| } | ||
|
|
||
| // AttachMetadata configures metadata attachment | ||
| type AttachMetadata struct { | ||
| // Node instructs vmagent or vmsingle to add node specific metadata from service discovery | ||
|
|
@@ -47,7 +72,7 @@ type VMScrapeParams struct { | |
| // ProxyClientConfig configures proxy auth settings for scraping | ||
| // See feature description https://docs.victoriametrics.com/victoriametrics/vmagent/#scraping-targets-via-a-proxy | ||
| // +optional | ||
| ProxyClientConfig *ProxyAuth `json:"proxy_client_config,omitempty"` | ||
| ProxyClientConfig *ProxyClientConfig `json:"proxy_client_config,omitempty"` | ||
| // Headers allows sending custom headers to scrape targets | ||
| // must be in of semicolon separated header with it's value | ||
| // eg: | ||
|
|
@@ -57,16 +82,55 @@ type VMScrapeParams struct { | |
| Headers []string `json:"headers,omitempty"` | ||
| } | ||
|
|
||
| // ProxyAuth represent proxy auth config | ||
| // Only VictoriaMetrics scrapers supports it. | ||
| // See https://github.com/VictoriaMetrics/VictoriaMetrics/commit/a6a71ef861444eb11fe8ec6d2387f0fc0c4aea87 | ||
| type ProxyAuth struct { | ||
| BasicAuth *BasicAuth `json:"basic_auth,omitempty"` | ||
| BearerToken *corev1.SecretKeySelector `json:"bearer_token,omitempty"` | ||
| BearerTokenFile string `json:"bearer_token_file,omitempty"` | ||
| // ProxyClientConfig represent proxy client config | ||
| type ProxyClientConfig struct { | ||
| // OAuth2 defines auth configuration | ||
| // +optional | ||
| OAuth2 *OAuth2 `json:"oauth2,omitempty"` | ||
| // BasicAuth allows proxy to authenticate over basic authentication | ||
| // +optional | ||
| BasicAuth *BasicAuth `json:"basic_auth,omitempty"` | ||
| // Secret to mount to read bearer token for scraping targets proxy auth. The secret | ||
| // needs to be in the same namespace as the scrape object and accessible by | ||
| // the victoria-metrics operator. | ||
| // +optional | ||
| // +nullable | ||
| BearerToken *corev1.SecretKeySelector `json:"bearer_token,omitempty"` | ||
| // BearerTokenFile defines file to read bearer token from for proxy auth. | ||
| // +optional | ||
| BearerTokenFile string `json:"bearer_token_file,omitempty"` | ||
| // TLSConfig configuration to use when scraping the endpoint | ||
| // +optional | ||
| // +kubebuilder:validation:Schemaless | ||
| // +kubebuilder:pruning:PreserveUnknownFields | ||
| TLSConfig *TLSConfig `json:"tls_config,omitempty"` | ||
| // Authorization with http header Authorization | ||
| // +optional | ||
| Authorization *Authorization `json:"authorization,omitempty"` | ||
| } | ||
|
|
||
| func (c *ProxyClientConfig) validateArbitraryFSAccess() error { | ||
| if c == nil { | ||
| return nil | ||
| } | ||
| var props []string | ||
| if c.BearerTokenFile != "" { | ||
| props = append(props, "bearer_token_file") | ||
| } | ||
| if c.BasicAuth != nil && c.BasicAuth.PasswordFile != "" { | ||
| props = append(props, "basic_auth.passwordFile") | ||
| } | ||
| if c.OAuth2 != nil && c.OAuth2.ClientSecretFile != "" { | ||
| props = append(props, "oauth2.clientSecretFile") | ||
| } | ||
| if c.Authorization != nil && c.Authorization.CredentialsFile != "" { | ||
| props = append(props, "authorization.credentialsFile") | ||
| } | ||
| props = c.TLSConfig.appendForbiddenProperties(props) | ||
| if len(props) > 0 { | ||
| return fmt.Errorf("%s are prohibited", strings.Join(props, ", ")) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // OAuth2 defines OAuth2 configuration | ||
|
|
@@ -245,7 +309,7 @@ func (rc *RelabelConfig) IsEmpty() bool { | |
| return reflect.DeepEqual(*rc, RelabelConfig{}) | ||
| } | ||
|
|
||
| // ScrapeTargetParams defines common configuration params for all scrape endpoint targets | ||
| // EndpointScrapeParams defines common configuration params for all scrape endpoint targets | ||
| type EndpointScrapeParams struct { | ||
| // HTTP path to scrape for metrics. | ||
| // +optional | ||
|
|
@@ -292,6 +356,19 @@ type EndpointScrapeParams struct { | |
| // VMScrapeParams defines VictoriaMetrics specific scrape parameters | ||
| // +optional | ||
| VMScrapeParams *VMScrapeParams `json:"vm_scrape_params,omitempty"` | ||
| EndpointAuth `json:",inline"` | ||
| } | ||
|
|
||
| func (p *EndpointScrapeParams) ValidateArbitraryFSAccess() error { | ||
| if err := p.validateArbitraryFSAccess(); err != nil { | ||
| return fmt.Errorf("endpoint auth contains prohibited properties for arbitrary filesystem access mode: %w", err) | ||
| } | ||
| if p.VMScrapeParams != nil { | ||
| if err := p.VMScrapeParams.ProxyClientConfig.validateArbitraryFSAccess(); err != nil { | ||
| return fmt.Errorf("endpoint proxy auth contains prohibited properties for arbitrary filesystem access mode: %w", err) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // EndpointAuth defines target endpoint authorization options for scrapping | ||
|
|
@@ -319,6 +396,41 @@ type EndpointAuth struct { | |
| Authorization *Authorization `json:"authorization,omitempty"` | ||
| } | ||
|
|
||
| func (a *EndpointAuth) validateArbitraryFSAccess() error { | ||
| var props []string | ||
| if a.BearerTokenFile != "" { | ||
| props = append(props, "bearerTokenFile") | ||
| } | ||
| if a.BasicAuth != nil && a.BasicAuth.PasswordFile != "" { | ||
| props = append(props, "basicAuth.passwordFile") | ||
| } | ||
| if a.OAuth2 != nil && a.OAuth2.ClientSecretFile != "" { | ||
| props = append(props, "oauth2.clientSecretFile") | ||
| } | ||
| if a.Authorization != nil && a.Authorization.CredentialsFile != "" { | ||
| props = append(props, "authorization.credentialsFile") | ||
| } | ||
| if a.TLSConfig != nil { | ||
| tls := a.TLSConfig | ||
| if err := tls.Validate(); err != nil { | ||
| return err | ||
| } | ||
| if tls.CAFile != "" { | ||
| props = append(props, "tlsConfig.caFile") | ||
| } | ||
| if tls.CertFile != "" { | ||
| props = append(props, "tlsConfig.certFile") | ||
| } | ||
| if tls.KeyFile != "" { | ||
| props = append(props, "tlsConfig.keyFile") | ||
| } | ||
| } | ||
| if len(props) > 0 { | ||
| return fmt.Errorf("%s are prohibited", strings.Join(props, ", ")) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // EndpointRelabelings defines service discovery and metrics relabeling configuration for endpoints | ||
| type EndpointRelabelings struct { | ||
| // MetricRelabelConfigs to apply to samples after scrapping. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't that be covered by
requiredalready?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't know, moved this struct as is from vmagent_types.go