From cbeb7d50e88931b9f46255e0a46682cb3c2f6d18 Mon Sep 17 00:00:00 2001 From: Dmytro Kozlov Date: Tue, 24 Sep 2024 12:18:24 +0200 Subject: [PATCH] lib/promscrape: show only unhealthy targets if `show_only_unhealthy` filter is enabled (#6960) ### Describe Your Changes It is better to show only unhealthy targets instead of all of them when `show_only_unhealthy` filter is enabled. Related issue: https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3536 ### Checklist The following checks are **mandatory**: - [x] My change adheres [VictoriaMetrics contributing guidelines](https://docs.victoriametrics.com/contributing/). --------- Co-authored-by: Roman Khavronenko --- docs/changelog/CHANGELOG.md | 1 + lib/promscrape/targetstatus.go | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/changelog/CHANGELOG.md b/docs/changelog/CHANGELOG.md index a0595d63b..444023394 100644 --- a/docs/changelog/CHANGELOG.md +++ b/docs/changelog/CHANGELOG.md @@ -28,6 +28,7 @@ See also [LTS releases](https://docs.victoriametrics.com/lts-releases/). * FEATURE: [vmui](https://docs.victoriametrics.com/#vmui): change request method for `/query_range` and `/query` calls from `GET` to `POST`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6288). * FEATURE: [dashboards](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/dashboards) for VM single-node, cluster, vmalert, vmagent, VictoriaLogs: add `Go scheduling latency` panel to show the 99th quantile of Go goroutines scheduling. This panel should help identifying insufficient CPU resources for the service. It is especially useful if CPU gets throttled, which now should be visible on this panel. * FEATURE: [alerts](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/deployment/docker/alerts-health.yml): add alerting rule to track the Go scheduling latency for goroutines. It should notify users if VM component doesn't have enough CPU to run or gets throttled. +* FEATURE: [vmagent](https://docs.victoriametrics.com/vmagent/) and [Single-node VictoriaMetrics](https://docs.victoriametrics.com/): hide jobs that contain only healthy targets when `show_only_unhealthy` filter is enabled. Before, jobs without unhealthy targets were still displayed on the page. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3536). * BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent/) fix service discovery of Azure Virtual Machines for response contains `nextLink` in `Host:Port` format. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6912). * BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent/): properly consume messages [from kafka](https://docs.victoriametrics.com/vmagent/#kafka-integration). Previously vmagent could skip some messages during start-up. diff --git a/lib/promscrape/targetstatus.go b/lib/promscrape/targetstatus.go index 742c7e305..148e07c61 100644 --- a/lib/promscrape/targetstatus.go +++ b/lib/promscrape/targetstatus.go @@ -475,6 +475,9 @@ func (tsm *targetStatusMap) getTargetsStatusByJob(filter *requestFilter) *target } targetsStatuses = append(targetsStatuses, ts) } + if filter.showOnlyUnhealthy && len(targetsStatuses) == 0 { + continue + } jts = append(jts, &jobTargetsStatuses{ jobName: jobName, upCount: ups, @@ -488,7 +491,7 @@ func (tsm *targetStatusMap) getTargetsStatusByJob(filter *requestFilter) *target emptyJobs := getEmptyJobs(jts, jobNames) var err error jts, err = filterTargets(jts, filter.endpointSearch, filter.labelSearch) - if len(filter.endpointSearch) > 0 || len(filter.labelSearch) > 0 { + if len(filter.endpointSearch) > 0 || len(filter.labelSearch) > 0 || filter.showOnlyUnhealthy { // Do not show empty jobs if target filters are set. emptyJobs = nil }