mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
b4ad3a3b4c
- Add a comment describing the purpose of the `role` field inside `apiConfig` struct - Revert changes at lib/promscrape/discovery/dockerswarm/dockerswarm.go , since they reduce code readability. E.g. the reader needs to look up the named string constants in order to get their values.
60 lines
2 KiB
Go
60 lines
2 KiB
Go
package dockerswarm
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils"
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
|
|
)
|
|
|
|
// SDCheckInterval defines interval for dockerswarm targets refresh.
|
|
var SDCheckInterval = flag.Duration("promscrape.dockerswarmSDCheckInterval", 30*time.Second, "Interval for checking for changes in dockerswarm. "+
|
|
"This works only if dockerswarm_sd_configs is configured in '-promscrape.config' file. "+
|
|
"See https://docs.victoriametrics.com/sd_configs.html#dockerswarm_sd_configs for details")
|
|
|
|
// SDConfig represents docker swarm service discovery configuration
|
|
//
|
|
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#dockerswarm_sd_config
|
|
type SDConfig struct {
|
|
Host string `yaml:"host"`
|
|
Role string `yaml:"role"`
|
|
Port int `yaml:"port,omitempty"`
|
|
Filters []Filter `yaml:"filters,omitempty"`
|
|
|
|
HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"`
|
|
ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"`
|
|
ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"`
|
|
// refresh_interval is obtained from `-promscrape.dockerswarmSDCheckInterval` command-line option
|
|
}
|
|
|
|
// Filter is a filter, which can be passed to SDConfig.
|
|
type Filter struct {
|
|
Name string `yaml:"name"`
|
|
Values []string `yaml:"values"`
|
|
}
|
|
|
|
// GetLabels returns dockerswarm 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 "tasks":
|
|
return getTasksLabels(cfg)
|
|
case "services":
|
|
return getServicesLabels(cfg)
|
|
case "nodes":
|
|
return getNodesLabels(cfg)
|
|
default:
|
|
return nil, fmt.Errorf("unexpected `role`: %q; must be one of `tasks`, `services` or `nodes`; skipping it", sdc.Role)
|
|
}
|
|
}
|
|
|
|
// MustStop stops further usage for sdc.
|
|
func (sdc *SDConfig) MustStop() {
|
|
configMap.Delete(sdc)
|
|
}
|