2020-10-05 13:45:33 +00:00
|
|
|
package openstack
|
|
|
|
|
|
|
|
import (
|
2021-06-25 09:10:20 +00:00
|
|
|
"flag"
|
2020-10-05 13:45:33 +00:00
|
|
|
"fmt"
|
2021-06-25 09:10:20 +00:00
|
|
|
"time"
|
2020-10-05 13:45:33 +00:00
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
|
2022-11-30 05:22:12 +00:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
|
2020-10-05 13:45:33 +00:00
|
|
|
)
|
|
|
|
|
2021-06-25 09:10:20 +00:00
|
|
|
// 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. "+
|
2022-08-14 22:40:20 +00:00
|
|
|
"See https://docs.victoriametrics.com/sd_configs.html#openstack_sd_configs for details")
|
2021-06-25 09:10:20 +00:00
|
|
|
|
2020-10-05 13:45:33 +00:00
|
|
|
// SDConfig is the configuration for OpenStack based service discovery.
|
2020-10-05 15:11:51 +00:00
|
|
|
//
|
|
|
|
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#openstack_sd_config
|
2020-10-05 13:45:33 +00:00
|
|
|
type SDConfig struct {
|
2021-11-05 12:41:14 +00:00
|
|
|
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"`
|
2020-10-05 15:11:51 +00:00
|
|
|
// RefreshInterval time.Duration `yaml:"refresh_interval"`
|
|
|
|
// refresh_interval is obtained from `-promscrape.openstackSDCheckInterval` command-line option.
|
2020-11-13 14:17:03 +00:00
|
|
|
Port int `yaml:"port,omitempty"`
|
|
|
|
AllTenants bool `yaml:"all_tenants,omitempty"`
|
|
|
|
TLSConfig *promauth.TLSConfig `yaml:"tls_config,omitempty"`
|
|
|
|
Availability string `yaml:"availability,omitempty"`
|
2020-10-05 13:45:33 +00:00
|
|
|
}
|
|
|
|
|
2021-02-26 13:53:42 +00:00
|
|
|
// GetLabels returns OpenStack labels according to sdc.
|
2022-11-30 05:22:12 +00:00
|
|
|
func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
|
2020-10-05 13:45:33 +00:00
|
|
|
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("unexpected `role`: %q; must be one of `instance` or `hypervisor`; skipping it", sdc.Role)
|
|
|
|
}
|
|
|
|
}
|
2021-03-01 12:13:56 +00:00
|
|
|
|
|
|
|
// MustStop stops further usage for sdc.
|
|
|
|
func (sdc *SDConfig) MustStop() {
|
|
|
|
configMap.Delete(sdc)
|
|
|
|
}
|