2020-05-04 17:48:02 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SDConfig represents service discovery config for Consul.
|
|
|
|
//
|
|
|
|
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#consul_sd_config
|
|
|
|
type SDConfig struct {
|
2020-11-13 14:17:03 +00:00
|
|
|
Server string `yaml:"server,omitempty"`
|
2020-05-05 04:48:08 +00:00
|
|
|
Token *string `yaml:"token"`
|
2020-05-04 17:48:02 +00:00
|
|
|
Datacenter string `yaml:"datacenter"`
|
2020-11-13 14:17:03 +00:00
|
|
|
Scheme string `yaml:"scheme,omitempty"`
|
2020-05-04 17:48:02 +00:00
|
|
|
Username string `yaml:"username"`
|
|
|
|
Password string `yaml:"password"`
|
2020-11-13 14:17:03 +00:00
|
|
|
TLSConfig *promauth.TLSConfig `yaml:"tls_config,omitempty"`
|
|
|
|
Services []string `yaml:"services,omitempty"`
|
|
|
|
Tags []string `yaml:"tags,omitempty"`
|
|
|
|
NodeMeta map[string]string `yaml:"node_meta,omitempty"`
|
|
|
|
TagSeparator *string `yaml:"tag_separator,omitempty"`
|
|
|
|
AllowStale bool `yaml:"allow_stale,omitempty"`
|
2020-05-04 17:48:02 +00:00
|
|
|
// RefreshInterval time.Duration `yaml:"refresh_interval"`
|
|
|
|
// refresh_interval is obtained from `-promscrape.consulSDCheckInterval` command-line option.
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLabels returns Consul labels according to sdc.
|
|
|
|
func GetLabels(sdc *SDConfig, baseDir string) ([]map[string]string, error) {
|
|
|
|
cfg, err := getAPIConfig(sdc, baseDir)
|
|
|
|
if err != nil {
|
2020-06-30 19:58:18 +00:00
|
|
|
return nil, fmt.Errorf("cannot get API config: %w", err)
|
2020-05-04 17:48:02 +00:00
|
|
|
}
|
2020-12-03 17:50:50 +00:00
|
|
|
ms := getServiceNodesLabels(cfg)
|
2020-05-04 17:48:02 +00:00
|
|
|
return ms, nil
|
|
|
|
}
|