From ba862ab6ada34b2d8b26959d5832a159b0113c0f Mon Sep 17 00:00:00 2001 From: malizz Date: Thu, 9 Feb 2023 12:06:31 -0800 Subject: [PATCH] troubleshoot basic envoy stats for an upstream (#16215) * troubleshoot basic envoy stats for an upstream * remove envoyID arg --- troubleshoot/proxy/stats.go | 41 +++++++++++++++++++++++- troubleshoot/proxy/troubleshoot_proxy.go | 9 +++--- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/troubleshoot/proxy/stats.go b/troubleshoot/proxy/stats.go index 1b00765f00..0fdb0e43ee 100644 --- a/troubleshoot/proxy/stats.go +++ b/troubleshoot/proxy/stats.go @@ -3,8 +3,8 @@ package troubleshoot import ( "encoding/json" "fmt" - envoy_admin_v3 "github.com/envoyproxy/go-control-plane/envoy/admin/v3" + "github.com/hashicorp/consul/troubleshoot/validate" ) type statsJson struct { @@ -16,6 +16,45 @@ type simpleMetric struct { Name string `json:"name,omitempty"` } +func (t *Troubleshoot) troubleshootStats() (validate.Messages, error) { + + statMessages := validate.Messages{} + + rejectionStats, err := t.getEnvoyStats("update_rejected") + if err != nil { + return nil, fmt.Errorf("could not get config rejection stats from envoy admin API: %w", err) + } + + totalConfigRejections := 0 + for _, rs := range rejectionStats { + if rs.Value != 0 { + totalConfigRejections += int(rs.Value) + } + } + + statMessages = append(statMessages, validate.Message{ + Success: true, + Message: fmt.Sprintf("Envoy has %v rejected configurations", totalConfigRejections), + }) + + connectionFailureStats, err := t.getEnvoyStats("upstream_cx_connect_fail") + if err != nil { + return nil, fmt.Errorf("could not get connection failure stats from envoy admin API: %w", err) + } + + totalCxFailures := 0 + for _, cfs := range connectionFailureStats { + if cfs.Value != 0 { + totalCxFailures += int(cfs.Value) + } + } + statMessages = append(statMessages, validate.Message{ + Success: true, + Message: fmt.Sprintf("Envoy has detected %v connection failure(s).", totalCxFailures), + }) + return statMessages, nil +} + func (t *Troubleshoot) getEnvoyStats(filter string) ([]*envoy_admin_v3.SimpleMetric, error) { var resultErr error diff --git a/troubleshoot/proxy/troubleshoot_proxy.go b/troubleshoot/proxy/troubleshoot_proxy.go index 4b74012c9d..ff74aff0d4 100644 --- a/troubleshoot/proxy/troubleshoot_proxy.go +++ b/troubleshoot/proxy/troubleshoot_proxy.go @@ -85,10 +85,11 @@ func (t *Troubleshoot) RunAllTests(upstreamEnvoyID, upstreamIP string) (validate } // getStats usage example - // rejectionStats, err := t.getEnvoyStats("update_rejected") - // if err != nil { - // resultErr = multierror.Append(resultErr, err) - // } + messages, err = t.troubleshootStats() + if err != nil { + return nil, fmt.Errorf("unable to get stats: %w", err) + } + allTestMessages = append(allTestMessages, messages...) // Validate listeners, routes, clusters, endpoints. messages = Validate(indexedResources, upstreamEnvoyID, upstreamIP, true, t.envoyClusters)