mirror of https://github.com/status-im/consul.git
troubleshoot basic envoy stats for an upstream (#16215)
* troubleshoot basic envoy stats for an upstream * remove envoyID arg
This commit is contained in:
parent
dae88b16e8
commit
ba862ab6ad
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue