Repository: VictoriaMetrics/VictoriaMetrics
Pull request #3586 (2023-01-03 10:59:40)

lib/promscrape/discovery/dockerswarm: fix query encoding of filters
Fixes  #3579

codecov[bot]: # [Codecov](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/3586?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics) Report
Base: **57.40**% // Head: **57.40**% // Decreases project coverage by **`-0.00%`** :warning:
> Coverage data is based on head [(`8f7f996`)](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/3586?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics) compared to base [(`8fe21ec`)](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/commit/8fe21ec7076abad0b3e83f1406332b6760dc2c16?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics).
> Patch coverage: 100.00% of modified lines in pull request are covered.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #3586      +/-   ##
==========================================
- Coverage   57.40%   57.40%   -0.01%     
==========================================
  Files         290      290              
  Lines       50314    50308       -6     
==========================================
- Hits        28883    28878       -5     
+ Misses      19594    19593       -1     
  Partials     1837     1837              
```


| [Impacted Files](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/3586?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics) | Coverage Δ | |
|---|---|---|
| [lib/promscrape/discovery/dockerswarm/api.go](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/3586/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics#diff-bGliL3Byb21zY3JhcGUvZGlzY292ZXJ5L2RvY2tlcnN3YXJtL2FwaS5nbw==) | `20.40% <100.00%> (-8.69%)` | :arrow_down: |
| [lib/bloomfilter/filter.go](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/3586/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics#diff-bGliL2Jsb29tZmlsdGVyL2ZpbHRlci5nbw==) | `98.00% <0.00%> (-2.00%)` | :arrow_down: |
| [app/vmselect/promql/aggr\_incremental.go](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/3586/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics#diff-YXBwL3Ztc2VsZWN0L3Byb21xbC9hZ2dyX2luY3JlbWVudGFsLmdv) | `85.28% <0.00%> (-1.21%)` | :arrow_down: |
| [app/vmselect/promql/transform.go](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/3586/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics#diff-YXBwL3Ztc2VsZWN0L3Byb21xbC90cmFuc2Zvcm0uZ28=) | `88.18% <0.00%> (+0.15%)` | :arrow_up: |
| [lib/mergeset/table.go](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/3586/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics#diff-bGliL21lcmdlc2V0L3RhYmxlLmdv) | `64.41% <0.00%> (+0.24%)` | :arrow_up: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/VictoriaMetrics/VictoriaMetrics/pull/3586?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VictoriaMetrics).


Patch:
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 2e0bbb241..844814b13 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -29,6 +29,7 @@ The following tip changes can be tested by building VictoriaMetrics components f
 * BUGFIX: properly parse floating-point numbers without integer or fractional parts such as `.123` and `20.` during [data import](https://docs.victoriametrics.com/#how-to-import-time-series-data). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3544).
 * BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): properly parse durations with uppercase suffixes such as `10S`, `5MS`, `1W`, etc. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3589).
 * BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): fix a panic during target discovery when `vmagent` runs with `-promscrape.dropOriginalLabels` command-line flag. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3580). The bug has been introduced in [v1.85.0](https://docs.victoriametrics.com/CHANGELOG.html#v1850).
+* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): [dockerswarm_sd_configs](https://docs.victoriametrics.com/sd_configs.html#dockerswarm_sd_configs): properly encode `filters` field. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3579)
 
 
 ## [v1.85.3](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.85.3)
diff --git a/lib/promscrape/discovery/dockerswarm/api.go b/lib/promscrape/discovery/dockerswarm/api.go
index d0bb79cef..35d2ab974 100644
--- a/lib/promscrape/discovery/dockerswarm/api.go
+++ b/lib/promscrape/discovery/dockerswarm/api.go
@@ -63,20 +63,16 @@ func (cfg *apiConfig) getAPIResponse(path string) ([]byte, error) {
 	return cfg.client.GetAPIResponse(path)
 }
 
+// Encodes filters as `map[string][]string` and then marshals it to JSON.
+// Reference: https://docs.docker.com/engine/api/v1.41/#tag/Task
 func getFiltersQueryArg(filters []Filter) string {
 	if len(filters) == 0 {
 		return ""
 	}
-	m := make(map[string]map[string]bool)
+
+	m := make(map[string][]string)
 	for _, f := range filters {
-		x := m[f.Name]
-		if x == nil {
-			x = make(map[string]bool)
-			m[f.Name] = x
-		}
-		for _, value := range f.Values {
-			x[value] = true
-		}
+		m[f.Name] = f.Values
 	}
 	buf, err := json.Marshal(m)
 	if err != nil {


Test patch:
diff --git a/lib/promscrape/discovery/dockerswarm/api_test.go b/lib/promscrape/discovery/dockerswarm/api_test.go
index fc8888ee5..114ec43a4 100644
--- a/lib/promscrape/discovery/dockerswarm/api_test.go
+++ b/lib/promscrape/discovery/dockerswarm/api_test.go
@@ -22,5 +22,11 @@ func TestGetFiltersQueryArg(t *testing.T) {
 			Name:   "xxx",
 			Values: []string{"aa"},
 		},
-	}, "%7B%22name%22%3A%7B%22bar%22%3Atrue%2C%22foo%22%3Atrue%7D%2C%22xxx%22%3A%7B%22aa%22%3Atrue%7D%7D")
+	}, "%7B%22name%22%3A%5B%22foo%22%2C%22bar%22%5D%2C%22xxx%22%3A%5B%22aa%22%5D%7D")
+	f([]Filter{
+		{
+			Name:   "desired-state",
+			Values: []string{"running", "shutdown"},
+		},
+	}, "%7B%22desired-state%22%3A%5B%22running%22%2C%22shutdown%22%5D%7D")
 }