troubleshoot basic envoy stats for an upstream (#16215)

* troubleshoot basic envoy stats for an upstream

* remove envoyID arg
This commit is contained in:
malizz 2023-02-09 12:06:31 -08:00 committed by GitHub
parent 1177cda75b
commit eabc5ce390
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 5 deletions

View File

@ -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

View File

@ -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)