From 836cccdbd8cc76767ec83f524aeb980291b23b75 Mon Sep 17 00:00:00 2001 From: Hui Wang Date: Fri, 27 Oct 2023 13:31:55 +0800 Subject: [PATCH] =?UTF-8?q?do=20not=20print=20redundant=20error=20logs=20w?= =?UTF-8?q?hen=20failed=20to=20scrape=20consul=20or=20no=E2=80=A6=20(#5239?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * do not print redundant error logs when failed to scrape consul or nomad target prometheus performs the same because it uses consul lib which just drops the error(https://github.com/hashicorp/consul/blob/1806bcb38c3de97885ac48e7d8801a5a13e91d6b/api/api.go#L1134) --- docs/CHANGELOG.md | 1 + lib/promscrape/discovery/consul/api.go | 3 +++ lib/promscrape/discovery/nomad/api.go | 3 +++ 3 files changed, 7 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8e51f5c182..630824da6c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -12,6 +12,7 @@ The following `tip` changes can be tested by building VictoriaMetrics components ## v1.93.x long-time support release (LTS) * BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): properly drop samples if `-streamAggr.dropInput` command-line flag is set and `-remoteWrite.streamAggr.config` contains an empty file. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5207). +* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): do not print redundant error logs when failed to scrape consul or nomad target. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5239). ## [v1.93.6](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.93.6) diff --git a/lib/promscrape/discovery/consul/api.go b/lib/promscrape/discovery/consul/api.go index 8d815a39f9..aea1f15b10 100644 --- a/lib/promscrape/discovery/consul/api.go +++ b/lib/promscrape/discovery/consul/api.go @@ -173,6 +173,9 @@ func getBlockingAPIResponse(ctx context.Context, client *discoveryutils.Client, path += "&index=" + strconv.FormatInt(index, 10) path += "&wait=" + fmt.Sprintf("%ds", int(maxWaitTime().Seconds())) getMeta := func(resp *http.Response) { + if resp.StatusCode != http.StatusOK { + return + } ind := resp.Header.Get("X-Consul-Index") if len(ind) == 0 { logger.Errorf("cannot find X-Consul-Index header in response from %q", path) diff --git a/lib/promscrape/discovery/nomad/api.go b/lib/promscrape/discovery/nomad/api.go index 339a5dc0e0..a34eb1a072 100644 --- a/lib/promscrape/discovery/nomad/api.go +++ b/lib/promscrape/discovery/nomad/api.go @@ -121,6 +121,9 @@ func getBlockingAPIResponse(ctx context.Context, client *discoveryutils.Client, path += "&index=" + strconv.FormatInt(index, 10) path += "&wait=" + fmt.Sprintf("%ds", int(maxWaitTime().Seconds())) getMeta := func(resp *http.Response) { + if resp.StatusCode != http.StatusOK { + return + } ind := resp.Header.Get("X-Nomad-Index") if len(ind) == 0 { logger.Errorf("cannot find X-Nomad-Index header in response from %q", path)