lib/promscrape: follow-up for 8537533beb

- 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.
This commit is contained in:
Aliaksandr Valialkin 2023-01-11 22:54:16 -08:00
parent 8537533beb
commit b4ad3a3b4c
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1
2 changed files with 5 additions and 9 deletions

View File

@ -17,6 +17,8 @@ type apiConfig struct {
port int
// role is the type of objects to discover.
//
// filtersQueryArg is applied only to the given role - the rest of objects are queried without filters.
role string
// filtersQueryArg contains escaped `filters` query arg to add to each request to Docker Swarm API.

View File

@ -15,12 +15,6 @@ var SDCheckInterval = flag.Duration("promscrape.dockerswarmSDCheckInterval", 30*
"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")
const (
roleTasks = "tasks"
roleServices = "services"
roleNodes = "nodes"
)
// SDConfig represents docker swarm service discovery configuration
//
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#dockerswarm_sd_config
@ -49,11 +43,11 @@ func (sdc *SDConfig) GetLabels(baseDir string) ([]*promutils.Labels, error) {
return nil, fmt.Errorf("cannot get API config: %w", err)
}
switch sdc.Role {
case roleTasks:
case "tasks":
return getTasksLabels(cfg)
case roleServices:
case "services":
return getServicesLabels(cfg)
case roleNodes:
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)