Skip to content

Commit

Permalink
api: adds headers and multitenant url for VMAgent
Browse files Browse the repository at this point in the history
now VMAgent supports custom headers per remote write storage
and it's possible to switch it to multitenant mode, where vmagent allows to ingest data by the same url as vminsert with tenant identificator
  • Loading branch information
f41gh7 committed Jul 25, 2022
1 parent 0553b60 commit e056721
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 490 deletions.
12 changes: 12 additions & 0 deletions api/v1beta1/vmagent_types.go
Expand Up @@ -397,6 +397,11 @@ type VMAgentRemoteWriteSettings struct {
// Optional labels in the form 'name=value' to add to all the metrics before sending them
// +optional
Labels map[string]string `json:"label,omitempty"`
// Configures vmagent in multi-tenant mode with direct cluster support
// docs https://docs.victoriametrics.com/vmagent.html#multitenancy
// it's global setting and affects all remote storage configurations
// +optional
UseMultiTenantMode bool `json:"useMultiTenantMode,omitempty"`
}

// VMAgentRemoteWriteSpec defines the remote storage configuration for VmAgent
Expand Down Expand Up @@ -428,6 +433,13 @@ type VMAgentRemoteWriteSpec struct {
// +optional
// +kubebuilder:validation:Pattern:="[0-9]+(ms|s|m|h)"
SendTimeout *string `json:"sendTimeout,omitempty"`
// Headers allow configuring custom http headers
// Must be in form of semicolon separated header with value
// e.g.
// headerName: headerValue
// vmagent supports since 1.79.0 version
// +optional
Headers []string `json:"headers,omitempty"`
}

// VmAgentStatus defines the observed state of VmAgent
Expand Down
3 changes: 2 additions & 1 deletion api/v1beta1/vmservicescrape_types.go
Expand Up @@ -203,8 +203,9 @@ type VMScrapeParams struct {
// must be in of semicolon separated header with it's value
// eg:
// headerName: headerValue
// vmagent supports since 1.79.0 version
// +optional
Headers []string `json:"headers"`
Headers []string `json:"headers,omitempty"`
}

// ProxyAuth represent proxy auth config
Expand Down
12 changes: 12 additions & 0 deletions api/victoriametrics/v1beta1/vmagent_types.go
Expand Up @@ -397,6 +397,11 @@ type VMAgentRemoteWriteSettings struct {
// Optional labels in the form 'name=value' to add to all the metrics before sending them
// +optional
Labels map[string]string `json:"label,omitempty"`
// Configures vmagent in multi-tenant mode with direct cluster support
// docs https://docs.victoriametrics.com/vmagent.html#multitenancy
// it's global setting and affects all remote storage configurations
// +optional
UseMultiTenantMode bool `json:"useMultiTenantMode,omitempty"`
}

// VMAgentRemoteWriteSpec defines the remote storage configuration for VmAgent
Expand Down Expand Up @@ -428,6 +433,13 @@ type VMAgentRemoteWriteSpec struct {
// +optional
// +kubebuilder:validation:Pattern:="[0-9]+(ms|s|m|h)"
SendTimeout *string `json:"sendTimeout,omitempty"`
// Headers allow configuring custom http headers
// Must be in form of semicolon separated header with value
// e.g.
// headerName: headerValue
// vmagent supports since 1.79.0 version
// +optional
Headers []string `json:"headers,omitempty"`
}

// VmAgentStatus defines the observed state of VmAgent
Expand Down
3 changes: 2 additions & 1 deletion api/victoriametrics/v1beta1/vmservicescrape_types.go
Expand Up @@ -203,8 +203,9 @@ type VMScrapeParams struct {
// must be in of semicolon separated header with it's value
// eg:
// headerName: headerValue
// vmagent supports since 1.79.0 version
// +optional
Headers []string `json:"headers"`
Headers []string `json:"headers,omitempty"`
}

// ProxyAuth represent proxy auth config
Expand Down
14 changes: 14 additions & 0 deletions controllers/factory/vmagent.go
Expand Up @@ -911,6 +911,9 @@ func BuildRemoteWrites(cr *victoriametricsv1beta1.VMAgent, ssCache *scrapesSecre
remoteTargets := cr.Spec.RemoteWrite

url := remoteFlag{flagSetting: "-remoteWrite.url=", isNotNull: true}
if cr.Spec.RemoteWriteSettings != nil && cr.Spec.RemoteWriteSettings.UseMultiTenantMode {
url = remoteFlag{flagSetting: "-remoteWrite.multitenantURL=", isNotNull: true}
}
authUser := remoteFlag{flagSetting: "-remoteWrite.basicAuth.username="}
authPassword := remoteFlag{flagSetting: "-remoteWrite.basicAuth.password="}
bearerToken := remoteFlag{flagSetting: "-remoteWrite.bearerToken="}
Expand All @@ -926,6 +929,7 @@ func BuildRemoteWrites(cr *victoriametricsv1beta1.VMAgent, ssCache *scrapesSecre
oauth2ClientSecretFile := remoteFlag{flagSetting: "-remoteWrite.oauth2.clientSecretFile="}
oauth2Scopes := remoteFlag{flagSetting: "-remoteWrite.oauth2.scopes="}
oauth2TokenUrl := remoteFlag{flagSetting: "-remoteWrite.oauth2.tokenUrl="}
headers := remoteFlag{flagSetting: "-remoteWrite.headers="}

pathPrefix := path.Join(tlsAssetsDir, cr.Namespace)

Expand Down Expand Up @@ -1017,6 +1021,15 @@ func BuildRemoteWrites(cr *victoriametricsv1beta1.VMAgent, ssCache *scrapesSecre
}
sendTimeout.flagSetting += fmt.Sprintf("%s,", value)

value = ""
if len(rws.Headers) > 0 {
headers.isNotNull = true
for _, headerValue := range rws.Headers {
value += headerValue + "^^"
}
value = strings.TrimSuffix(value, "^^")
}
headers.flagSetting += fmt.Sprintf("'%s',", value)
value = ""
var oaturl, oascopes, oaclientID, oaSecretKey, oaSecretKeyFile string
if rws.OAuth2 != nil {
Expand Down Expand Up @@ -1056,6 +1069,7 @@ func BuildRemoteWrites(cr *victoriametricsv1beta1.VMAgent, ssCache *scrapesSecre
remoteArgs = append(remoteArgs, url, authUser, authPassword, bearerToken, urlRelabelConfig, tlsInsecure, sendTimeout)
remoteArgs = append(remoteArgs, tlsServerName, tlsKeys, tlsCerts, tlsCAs)
remoteArgs = append(remoteArgs, oauth2ClientID, oauth2ClientSecret, oauth2ClientSecretFile, oauth2Scopes, oauth2TokenUrl)
remoteArgs = append(remoteArgs, headers)

for _, remoteArgType := range remoteArgs {
if remoteArgType.isNotNull {
Expand Down

0 comments on commit e056721

Please sign in to comment.