From cd7324a05252e80f89937f7e390a1675dc17f9f7 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Wed, 11 Jan 2023 22:54:16 -0800 Subject: [PATCH] lib/promscrape: follow-up for 8537533beb92a72c110b3c13e84fba2b25580637 - 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. --- lib/promscrape/discovery/dockerswarm/api.go | 2 ++ lib/promscrape/discovery/dockerswarm/dockerswarm.go | 12 +++--------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/promscrape/discovery/dockerswarm/api.go b/lib/promscrape/discovery/dockerswarm/api.go index ef33775ba..ebd8e07ed 100644 --- a/lib/promscrape/discovery/dockerswarm/api.go +++ b/lib/promscrape/discovery/dockerswarm/api.go @@ -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. diff --git a/lib/promscrape/discovery/dockerswarm/dockerswarm.go b/lib/promscrape/discovery/dockerswarm/dockerswarm.go index 77345a307..133d9b2e0 100644 --- a/lib/promscrape/discovery/dockerswarm/dockerswarm.go +++ b/lib/promscrape/discovery/dockerswarm/dockerswarm.go @@ -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)