2023-01-05 23:03:58 +01:00
|
|
|
package nomad
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SDConfig represents service discovery config for Nomad.
|
|
|
|
//
|
|
|
|
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#nomad_sd_config
|
|
|
|
type SDConfig struct {
|
2023-01-09 09:07:40 +01:00
|
|
|
Server string `yaml:"server,omitempty"`
|
|
|
|
Token *promauth.Secret `yaml:"token,omitempty"`
|
|
|
|
Namespace string `yaml:"namespace,omitempty"`
|
2023-01-05 23:03:58 +01:00
|
|
|
// RefreshInterval time.Duration `yaml:"refresh_interval"`
|
|
|
|
// refresh_interval is obtained from `-promscrape.nomadSDCheckInterval` command-line option.
|
2023-01-06 03:01:11 +01:00
|
|
|
Scheme string `yaml:"scheme,omitempty"`
|
|
|
|
Services []string `yaml:"services,omitempty"`
|
|
|
|
Tags []string `yaml:"tags,omitempty"`
|
|
|
|
TagSeparator *string `yaml:"tag_separator,omitempty"`
|
|
|
|
AllowStale *bool `yaml:"allow_stale,omitempty"`
|
|
|
|
|
2023-01-05 23:03:58 +01:00
|
|
|
HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"`
|
|
|
|
ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"`
|
|
|
|
ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetLabels returns Nomad 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)
|
|
|
|
}
|
|
|
|
ms := getServiceLabels(cfg)
|
|
|
|
return ms, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// MustStop stops further usage for sdc.
|
|
|
|
func (sdc *SDConfig) MustStop() {
|
|
|
|
v := configMap.Delete(sdc)
|
|
|
|
if v != nil {
|
|
|
|
// v can be nil if GetLabels wasn't called yet.
|
|
|
|
cfg := v.(*apiConfig)
|
|
|
|
cfg.mustStop()
|
|
|
|
}
|
|
|
|
}
|