Skip to content

Commit

Permalink
🐛 Fix: egctl stats invalid format
Browse files Browse the repository at this point in the history
Signed-off-by: bitliu <[email protected]>
  • Loading branch information
Xunzhuo committed Oct 23, 2023
1 parent ede2655 commit c47d616
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions internal/cmd/egctl/envoy_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
)

const (
summaryOutput = "statsd"
prometheusOutput = "prom"
)

Expand Down Expand Up @@ -103,6 +102,12 @@ func newEnvoyStatsCmd() *cobra.Command {
}

switch outputFormat {
case jsonOutput:
statsBytes, err := json.Marshal(stats)
if err != nil {
return err
}
_, _ = fmt.Fprint(c.OutOrStdout(), string(statsBytes))
// convert the json output to yaml
case yamlOutput:
var out []byte
Expand All @@ -124,7 +129,7 @@ func newEnvoyStatsCmd() *cobra.Command {
return nil
},
}
statsConfigCmd.PersistentFlags().StringVarP(&outputFormat, "output", "o", summaryOutput, "Output format: one of json|yaml|prom")
statsConfigCmd.PersistentFlags().StringVarP(&outputFormat, "output", "o", prometheusOutput, "Output format: one of json|yaml|prom")
statsConfigCmd.PersistentFlags().StringVarP(&statsType, "type", "t", "server", "Where to grab the stats: one of server|clusters")
statsConfigCmd.PersistentFlags().StringArrayVarP(&labelSelectors, "labels", "l", nil, "Labels to select the envoy proxy pod.")
statsConfigCmd.PersistentFlags().StringVarP(&podNamespace, "namespace", "n", "envoy-gateway-system", "Namespace where envoy proxy pod are installed.")
Expand Down
6 changes: 4 additions & 2 deletions internal/cmd/egctl/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (

func statsCommand() *cobra.Command {
c := &cobra.Command{
Use: "stats",
Long: "Retrieve stats from envoy proxy.",
Use: "stats",
Long: "Retrieve Prometheus Stats from envoy proxy.",
Short: "Retrieve stats from envoy proxy.",
Aliases: []string{"proxy"},
}

c.AddCommand(newEnvoyStatsCmd())
Expand Down

0 comments on commit c47d616

Please sign in to comment.