Repository navigation
fix(inputs.vsphere): Fix missing vSAN overall_health metric - #19126
Conversation
The cluster health summary was always read from vCenter's cache, which is frequently empty until the vSAN health service recomputes it. An empty overallHealth value produced a fieldless metric that was silently dropped, so overall_health rarely appeared. Add a vsan_health_fetch_from_cache option (default false) to control whether the summary is read from the cache or freshly evaluated, and log at debug when an unexpected health value is skipped instead of dropping it silently.
|
@srebhan one open question on the default: |
There was a problem hiding this comment.
Thanks for the fix @skartikey!
From my understanding, if fetchFromCache is true, vCenter will return nothing until the metric is recomputed. Is this correct? If so, can't we detect this and force a recomputation? E.g. by setting fetchFromCache := false for the next cycle? I'm asking because I feel like the option doesn't buy much for a user because he cannot know what to set here...
|
@srebhan You're right, the option isn't something a user can sensibly set. Reworked it to self-heal: read the summary from the cache first and, if |
Read the vSAN cluster health summary from vCenter's cache first and force a fresh evaluation when the cached overallHealth is empty or unmapped, instead of exposing a vsan_health_fetch_from_cache option users cannot reliably set.
srebhan
left a comment
There was a problem hiding this comment.
Thanks @skartikey! In general the code works but I would prefer making it more explicit...
| // vCenter's cached health summary is often empty until it recomputes, so | ||
| // read the cache first and fall back to forcing a fresh evaluation on miss. | ||
| val, found := 0, false | ||
| for _, fetchFromCache := range []bool{true, false} { | ||
| resp, err := vsanmethods.VsanQueryVcClusterHealthSummary(ctx, vsanClient, | ||
| &vsantypes.VsanQueryVcClusterHealthSummary{ | ||
| This: healthSystemRef, | ||
| Cluster: &clusterRef.ref, | ||
| Fields: []string{"overallHealth", "overallHealthDescription"}, | ||
| FetchFromCache: &fetchFromCache, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if val, found = healthMap[resp.Returnval.OverallHealth]; found { | ||
| break | ||
| } | ||
| } | ||
| if !found { | ||
| e.parent.Log.Debugf("[vSAN] Skipping health summary for cluster %s: no valid overall health", clusterRef.name) | ||
| return nil | ||
| } | ||
| fields := map[string]interface{}{"overall_health": val} |
There was a problem hiding this comment.
Isn't this a bit hard to read? I would prefer
| // vCenter's cached health summary is often empty until it recomputes, so | |
| // read the cache first and fall back to forcing a fresh evaluation on miss. | |
| val, found := 0, false | |
| for _, fetchFromCache := range []bool{true, false} { | |
| resp, err := vsanmethods.VsanQueryVcClusterHealthSummary(ctx, vsanClient, | |
| &vsantypes.VsanQueryVcClusterHealthSummary{ | |
| This: healthSystemRef, | |
| Cluster: &clusterRef.ref, | |
| Fields: []string{"overallHealth", "overallHealthDescription"}, | |
| FetchFromCache: &fetchFromCache, | |
| }) | |
| if err != nil { | |
| return err | |
| } | |
| if val, found = healthMap[resp.Returnval.OverallHealth]; found { | |
| break | |
| } | |
| } | |
| if !found { | |
| e.parent.Log.Debugf("[vSAN] Skipping health summary for cluster %s: no valid overall health", clusterRef.name) | |
| return nil | |
| } | |
| fields := map[string]interface{}{"overall_health": val} | |
| // Read vCenter's cached health summary first | |
| summary := &vsantypes.VsanQueryVcClusterHealthSummary{ | |
| This: healthSystemRef, | |
| Cluster: &clusterRef.ref, | |
| Fields: []string{"overallHealth", "overallHealthDescription"}, | |
| FetchFromCache: new(true), | |
| } | |
| cached, err := vsanmethods.VsanQueryVcClusterHealthSummary(ctx, vsanClient, summary) | |
| if err != nil { | |
| return fmt.Errorf("reading cached health value failed: %w", err) | |
| } | |
| if val, found = healthMap[cached.Returnval.OverallHealth]; found { | |
| fields := map[string]interface{}{"overall_health": val} | |
| } else { | |
| // vCenter's cached health summary is empty so it requires a recompute by | |
| // forcing caching to off | |
| summary.FetchFromCache = new(false) | |
| uncached, err := vsanmethods.VsanQueryVcClusterHealthSummary(ctx, vsanClient, summary) | |
| if err != nil { | |
| return fmt.Errorf("reading uncached health value failed: %w", err) | |
| } | |
| val, found = healthMap[uncached.Returnval.OverallHealth] | |
| if !found { | |
| e.parent.Log.Debugf("[vSAN] Skipping health summary for cluster %s due to invalid value %q", clusterRef.name, uncached.Returnval.OverallHealth) | |
| return nil | |
| } | |
| fields := map[string]interface{}{"overall_health": val} | |
| } | |
| } |
We should also clarify if we really want to return nil or an error in case we get an invalid value...
There was a problem hiding this comment.
Made the changes.
on returning nil, Kept it as return nil + debug log on purpose. After the forced (uncached) recompute, an empty or unmapped overallHealth is almost always transient (recompute still settling) or a health enum a newer vSphere added that we don't map yet, not a misconfiguration. Routing it through acc.AddError would log at ERROR every gather interval for a benign/transient state, so debug-skip is the right severity. If you'd rather have it loud I can return a wrapped error instead, let me know.
Replace the cache-toggle loop with an explicit cached read followed by a forced recompute on miss, using new(true)/new(false) for the flag and distinct wrapped errors for each query.
|
Download PR build artifacts for linux_amd64.tar.gz, darwin_arm64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
(cherry picked from commit 54e5cd3)
telegraf 1.39.1 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre>## v1.39.1 [2026-06-29] ### Bugfixes - [#19077](influxdata/telegraf#19077) `build` Create tarballs correctly - [#19070](influxdata/telegraf#19070) `inputs.opcua` Close session on stop to prevent reload leak - [#19159](influxdata/telegraf#19159) `inputs.opcua` Skip client certificate on unsecured None channel - [#19076](influxdata/telegraf#19076) `inputs.openweathermap` Remove calls to deprecated v2.5 group API - [#19167](influxdata/telegraf#19167) `inputs.smartctl` Parse stdout only to avoid corrupting JSON - [#19093](influxdata/telegraf#19093) `inputs.tail` Prevent panic when closing tailers under load - [#19067](influxdata/telegraf#19067) `inputs.temp` Use non-blocking read for hwmon temperatures - [#19126](influxdata/telegraf#19126) `inputs.vsphere` Fix missing vSAN overall_health metric - [#19074](influxdata/telegraf#19074) `processors.parser` Handle metrics without inner timestamp correctly - [#19129](influxdata/telegraf#19129) `migrations` Add migration for inputs.aerospike - [#19121](influxdata/telegraf#19121) `migrations` Add migration for inputs.kafka_consumer connection_strategy option - [#19122](influxdata/telegraf#19122) `migrations` Add migration for inputs.openstack server_diagnotics option - [#19133](influxdata/telegraf#19133) `migrations` Add migration for inputs.openweathermap query_style option - [#19117](influxdata/telegraf#19117) `migrations` Add migration for inputs.tail from_beginning option - [#19128](influxdata/telegraf#19128) `migrations` Add migration for outputs.amon ### Dependency Updates - [#19138](influxdata/telegraf#19138) `deps` Bump actions/checkout from 6 to 7 - [#19065](influxdata/telegraf#19065) `deps` Bump cloud.google.com/go/storage from 1.62.2 to 1.62.3 - [#19058](influxdata/telegraf#19058) `deps` Bump github.com/Azure/azure-sdk-for-go/sdk/azcore from 1.21.1 to 1.22.0 - [#19106](influxdata/telegraf#19106) `deps` Bump github.com/Azure/azure-sdk-for-go/sdk/azidentity from 1.13.1 to 1.14.0 - [#19059](influxdata/telegraf#19059) `deps` Bump github.com/IBM/sarama from 1.50.1 to 1.50.2 - [#19110](influxdata/telegraf#19110) `deps` Bump github.com/IBM/sarama from 1.50.2 to 1.50.3 - [#19102](influxdata/telegraf#19102) `deps` Bump github.com/SAP/go-hdb from 1.16.11 to 1.16.12 - [#19057](influxdata/telegraf#19057) `deps` Bump github.com/aws/smithy-go from 1.27.0 to 1.27.2 - [#19060](influxdata/telegraf#19060) `deps` Bump github.com/gopacket/gopacket from 1.6.0 to 1.6.1 - [#19142](influxdata/telegraf#19142) `deps` Bump github.com/gopcua/opcua from 0.8.0 to 0.9.0 - [#19064](influxdata/telegraf#19064) `deps` Bump github.com/jedib0t/go-pretty/v6 from 6.7.10 to 6.8.0 - [#19108](influxdata/telegraf#19108) `deps` Bump github.com/jedib0t/go-pretty/v6 from 6.8.0 to 6.8.1 - [#19150](influxdata/telegraf#19150) `deps` Bump github.com/moby/moby/api from 1.54.2 to 1.55.0 - [#19149](influxdata/telegraf#19149) `deps` Bump github.com/moby/moby/client from 0.4.1 to 0.5.0 - [#19053](influxdata/telegraf#19053) `deps` Bump github.com/pion/dtls/v3 from 3.1.3 to 3.1.4 - [#19115](influxdata/telegraf#19115) `deps` Bump github.com/prometheus-community/pro-bing from 0.8.0 to 0.9.0 - [#19147](influxdata/telegraf#19147) `deps` Bump github.com/prometheus/common from 0.68.1 to 0.69.0 - [#19141](influxdata/telegraf#19141) `deps` Bump github.com/rabbitmq/amqp091-go from 1.11.0 to 1.12.0 - [#19170](influxdata/telegraf#19170) `deps` Bump github.com/rclone/rclone from 1.69.3 to 1.74.1-0.20260628215305-6bbc28cf02dc - [#19109](influxdata/telegraf#19109) `deps` Bump github.com/redis/go-redis/v9 from 9.20.0 to 9.20.1 - [#19148](influxdata/telegraf#19148) `deps` Bump github.com/redis/go-redis/v9 from 9.20.1 to 9.21.0 - [#19152](influxdata/telegraf#19152) `deps` Bump github.com/testcontainers/testcontainers-go/modules/azure from 0.42.0 to 0.43.0 - [#19143](influxdata/telegraf#19143) `deps` Bump github.com/testcontainers/testcontainers-go/modules/kafka from 0.42.0 to 0.43.0 - [#19144](influxdata/telegraf#19144) `deps` Bump github.com/testcontainers/testcontainers-go/modules/vault from 0.42.0 to 0.43.0 - [#19111](influxdata/telegraf#19111) `deps` Bump go.opentelemetry.io/collector/pdata from 1.59.0 to 1.60.0 - [#19054](influxdata/telegraf#19054) `deps` Bump go.step.sm/crypto from 0.81.1 to 0.82.0 - [#19104](influxdata/telegraf#19104) `deps` Bump go.step.sm/crypto from 0.82.0 to 0.83.0 - [#19061](influxdata/telegraf#19061) `deps` Bump golang.org/x/crypto from 0.52.0 to 0.53.0 - [#19055](influxdata/telegraf#19055) `deps` Bump golang.org/x/mod from 0.36.0 to 0.37.0 - [#19056](influxdata/telegraf#19056) `deps` Bump golang.org/x/sync from 0.20.0 to 0.21.0 - [#19066](influxdata/telegraf#19066) `deps` Bump golang.org/x/sys from 0.45.0 to 0.46.0 - [#19063](influxdata/telegraf#19063) `deps` Bump golang.org/x/term from 0.43.0 to 0.44.0 - [#19062](influxdata/telegraf#19062) `deps` Bump golang.org/x/text from 0.37.0 to 0.38.0 - [#19107](influxdata/telegraf#19107) `deps` Bump golang.org/x/tools from 0.45.0 to 0.46.0 - [#19101](influxdata/telegraf#19101) `deps` Bump google.golang.org/api from 0.283.0 to 0.284.0 - [#19145](influxdata/telegraf#19145) `deps` Bump google.golang.org/api from 0.284.0 to 0.286.0 - [#19103](influxdata/telegraf#19103) `deps` Bump k8s.io/api from 0.36.1 to 0.36.2 - [#19113](influxdata/telegraf#19113) `deps` Bump k8s.io/client-go from 0.36.1 to 0.36.2 - [#19052](influxdata/telegraf#19052) `deps` Bump modernc.org/sqlite from 1.51.0 to 1.52.0 - [#19151](influxdata/telegraf#19151) `deps` Bump modernc.org/sqlite from 1.52.0 to 1.53.0 - [#19105](influxdata/telegraf#19105) `deps` Bump software.sslmate.com/src/go-pkcs12 from 0.7.1 to 0.7.2 - [#19139](influxdata/telegraf#19139) `deps` Bump super-linter/super-linter from 8.6.0 to 8.7.0 - [#19051](influxdata/telegraf#19051) `deps` Bump the aws-sdk-go-v2 group across 1 directory with 11 updates - [#19140](influxdata/telegraf#19140) `deps` Bump the aws-sdk-go-v2 group with 2 updates - [#19100](influxdata/telegraf#19100) `deps` Bump the aws-sdk-go-v2 group with 6 updates ### Packages Arch | Platform | Package | SHA256 ---| --- | --- | --- arm64 | CentOS | [telegraf-1.39.1-1.aarch64.rpm](https://dl.influxdata.com/telegraf/releases/telegraf-1.39.1-1.aarch64.rpm) | 0227b00b6295c326f07e3c8e5d463ec045c63526cf6c9cbc13a45dc837700063 armel | CentOS | [telegraf-1.39.1-1.armel.rpm](https://dl.influxdata.com/telegraf/releases/telegraf-1.39.1-1.armel.rpm) | 6712998ae341138c118eacdea1044964a9a29e8fb283c5e4b3bf7d99af5a6352 armv6hl | CentOS | [telegraf-1.39.1-1.armv6hl.rpm](https://dl.influxdata.com/telegraf/releases/telegraf-1.39.1-1.armv6hl.rpm) | 2d406f71c983f6639d7e5ead7b00b52466245624fccc37bfaa89603462c37a4d i386 | CentOS | [telegraf-1.39.1-1.i386.rpm](https://dl.influxdata.com/telegraf/releases/telegraf-1.39.1-1.i386.rpm) | 7d769ca55c362fc9b841d8a644fd3c129c732c6c2db7c8d556748fb4a137b269 unknown | CentOS | [telegraf-1.39.1-1.loongarch64.rpm](https://dl.influxdata.com/telegraf/releases/telegraf-1.39.1-1.loongarch64.rpm) | e9a9f8591286b41c6d61af28fd6ff8bd050a1b1bdd54b52cca6e862ee7eab2dc ppc64le | CentOS | [telegraf-1.39.1-1.ppc64le.rpm](https://dl.influxdata.com/telegraf/releases/telegraf-1.39.1-1.ppc64le.rpm) | 846a6480d333bb3dd0bdb11c6bbe674a839136e488cde7510dff978edf77a988 riscv64 | CentOS | [telegraf-1.39.1-1.riscv64.rpm](https://dl.influxdata.com/telegraf/releases/telegraf-1.39.1-1.riscv64.rpm) | 9653bb7adca7919c8b9b94d8f322c26c71635face57e12ed4a8276a78f0a2f11 s390x | CentOS | [telegraf-1.39.1-1.s390x.rpm](https://dl.influxdata.com/telegraf/releases/telegraf-1.39.1-1.s390x.rpm) | 5df8a1dd1ac77ea253cc2ca99ff1fbf6aed995da09362af3ae213fbbad5a4438 amd64 | CentOS | [telegraf-1.39.1-1.x86_64.rpm](https://dl.influxdata.com/telegraf/releases/telegraf-1.39.1-1.x86_64.rpm) | 8775538460f86e1ae86a47eb92a92932d1b8949c888d0171df4d8b0534145e73 amd64 | macOS | [telegraf-1.39.1_darwin_amd64.dmg](https://dl.influxdata.com/telegraf/releases/telegraf-1.39.1_darwin_amd64.dmg) | 3b61fcb0abac52d8f915ff900b2c504f2a99fd9dc58a2589f533d611f6d6ff4d amd64 | macOS | [telegraf-1.39.1_darwin_amd64.tar.gz](https://dl.influxdata.com/telegraf/releases/telegraf-1.39.1_darwin_amd64.tar.gz) | 653c8a4b5afe66b0a6223952853de9f4d9ad4387b62858248fcad1ff4021e060 arm64 | macOS | [telegraf-1.39.1_darwin_arm64.dmg](https://dl.influxdata.com/telegraf/releases/telegraf-1.39.1_darwin_arm64.dmg) | 7af3ca693daae87e4503a3c0 See merge request: Harmonybrew/homebrew-core!13084
Summary
The cluster health summary was always read from vCenter's cache, which is frequently empty until the vSAN health service recomputes it. An empty overallHealth value produced a fieldless metric that Telegraf silently drops, so overall_health rarely appeared.
This now reads the summary from the cache first and, when the cached overallHealth is empty or unmapped, forces a fresh evaluation (fetchFromCache=false) before giving up. The common path stays on the cheap cached read, a value is returned when the cache is cold, and forcing a recompute warms vCenter's cache for the next cycle. When no valid health value is returned even after the forced evaluation, it logs at debug instead of emitting a fieldless metric that gets dropped silently.
Checklist
Related issues
resolves #19099