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 6e398d12ef
commit cd7324a052
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

@ -14,12 +14,6 @@ var SDCheckInterval = flag.Duration("promscrape.dockerswarmSDCheckInterval", 30*
"This works only if dockerswarm_sd_configs is configured in '-promscrape.config' file. "+
"See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#dockerswarm_sd_config 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
@ -48,11 +42,11 @@ func (sdc *SDConfig) GetLabels(baseDir string) ([]map[string]string, 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)