mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-20 23:46:23 +01:00
d5a599badc
- Make sure that invalid/missing TLS CA file or TLS client certificate files at vmagent startup don't prevent from processing the corresponding scrape targets after the file becomes correct, without the need to restart vmagent. Previously scrape targets with invalid TLS CA file or TLS client certificate files were permanently dropped after the first attempt to initialize them, and they didn't appear until the next vmagent reload or the next change in other places of the loaded scrape configs. - Make sure that TLS CA is properly re-loaded from file after it changes without the need to restart vmagent. Previously the old TLS CA was used until vmagent restart. - Properly handle errors during http request creation for the second attempt to send data to remote system at vmagent and vmalert. Previously failed request creation could result in nil pointer dereferencing, since the returned request is nil on error. - Add more context to the logged error during AWS sigv4 request signing before sending the data to -remoteWrite.url at vmagent. Previously it could miss details on the source of the request. - Do not create a new HTTP client per second when generating OAuth2 token needed to put in Authorization header of every http request issued by vmagent during service discovery or target scraping. Re-use the HTTP client instead until the corresponding scrape config changes. - Cache error at lib/promauth.Config.GetAuthHeader() in the same way as the auth header is cached, e.g. the error is cached for a second now. This should reduce load on CPU and OAuth2 server when auth header cannot be obtained because of temporary error. - Share tls.Config.GetClientCertificate function among multiple scrape targets with the same tls_config. Cache the loaded certificate and the error for one second. This should significantly reduce CPU load when scraping big number of targets with the same tls_config. - Allow loading TLS certificates from HTTP and HTTPs urls by specifying these urls at `tls_config->cert_file` and `tls_config->key_file`. - Improve test coverage at lib/promauth - Skip unreachable or invalid files specified at `scrape_config_files` during vmagent startup, since these files may become valid later. Previously vmagent was exitting in this case. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4959
66 lines
2.8 KiB
Go
66 lines
2.8 KiB
Go
package openstack
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
|
|
)
|
|
|
|
// SDCheckInterval defines interval for targets refresh.
|
|
var SDCheckInterval = flag.Duration("promscrape.openstackSDCheckInterval", 30*time.Second, "Interval for checking for changes in openstack API server. "+
|
|
"This works only if openstack_sd_configs is configured in '-promscrape.config' file. "+
|
|
"See https://docs.victoriametrics.com/sd_configs.html#openstack_sd_configs for details")
|
|
|
|
// SDConfig is the configuration for OpenStack based service discovery.
|
|
//
|
|
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#openstack_sd_config
|
|
type SDConfig struct {
|
|
IdentityEndpoint string `yaml:"identity_endpoint,omitempty"`
|
|
Username string `yaml:"username,omitempty"`
|
|
UserID string `yaml:"userid,omitempty"`
|
|
Password *promauth.Secret `yaml:"password,omitempty"`
|
|
ProjectName string `yaml:"project_name,omitempty"`
|
|
ProjectID string `yaml:"project_id,omitempty"`
|
|
DomainName string `yaml:"domain_name,omitempty"`
|
|
DomainID string `yaml:"domain_id,omitempty"`
|
|
ApplicationCredentialName string `yaml:"application_credential_name,omitempty"`
|
|
ApplicationCredentialID string `yaml:"application_credential_id,omitempty"`
|
|
ApplicationCredentialSecret *promauth.Secret `yaml:"application_credential_secret,omitempty"`
|
|
Role string `yaml:"role"`
|
|
Region string `yaml:"region"`
|
|
// RefreshInterval time.Duration `yaml:"refresh_interval"`
|
|
// refresh_interval is obtained from `-promscrape.openstackSDCheckInterval` command-line option.
|
|
Port int `yaml:"port,omitempty"`
|
|
AllTenants bool `yaml:"all_tenants,omitempty"`
|
|
TLSConfig *promauth.TLSConfig `yaml:"tls_config,omitempty"`
|
|
Availability string `yaml:"availability,omitempty"`
|
|
}
|
|
|
|
// GetLabels returns OpenStack labels according to sdc.
|
|
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
|
|
cfg, err := getAPIConfig(sdc, baseDir)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot get API config: %w", err)
|
|
}
|
|
switch sdc.Role {
|
|
case "hypervisor":
|
|
return getHypervisorLabels(cfg)
|
|
case "instance":
|
|
return getInstancesLabels(cfg)
|
|
default:
|
|
return nil, fmt.Errorf("skipping unexpected role=%q; must be one of `instance` or `hypervisor`", sdc.Role)
|
|
}
|
|
}
|
|
|
|
// MustStop stops further usage for sdc.
|
|
func (sdc *SDConfig) MustStop() {
|
|
v := configMap.Delete(sdc)
|
|
if v != nil {
|
|
cfg := v.(*apiConfig)
|
|
cfg.client.CloseIdleConnections()
|
|
}
|
|
}
|