Skip to content

Commit

Permalink
bugtool: Collect hubble metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Chance Zibolski <chance.zibolski@gmail.com>
  • Loading branch information
chancez authored and tklauser committed Mar 26, 2024
1 parent 7992f75 commit 3d95fbc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Documentation/cmdref/cilium-bugtool.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions bugtool/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ var (
parallelWorkers int
ciliumAgentContainerName string
excludeObjectFiles bool
hubbleMetrics bool
hubbleMetricsPort int
)

func init() {
Expand Down Expand Up @@ -111,6 +113,8 @@ func init() {
BugtoolRootCmd.Flags().IntVar(&parallelWorkers, "parallel-workers", 0, "Maximum number of parallel worker tasks, use 0 for number of CPUs")
BugtoolRootCmd.Flags().StringVarP(&ciliumAgentContainerName, "cilium-agent-container-name", "", "cilium-agent", "Name of the Cilium Agent main container (when k8s-mode is true)")
BugtoolRootCmd.Flags().BoolVar(&excludeObjectFiles, "exclude-object-files", false, "Exclude per-endpoint object files. Template object files will be kept")
BugtoolRootCmd.Flags().BoolVar(&hubbleMetrics, "hubble-metrics", true, "When set, hubble prometheus metrics")
BugtoolRootCmd.Flags().IntVar(&hubbleMetricsPort, "hubble-metrics-port", 9965, "Port to query for hubble metrics")
}

func getVerifyCiliumPods() (k8sPods []string) {
Expand Down Expand Up @@ -221,6 +225,12 @@ func runTool() {
}
}

if hubbleMetrics {
if err := dumpHubbleMetrics(cmdDir); err != nil {
fmt.Fprintf(os.Stderr, "Unable to retrieve hubble prometheus metrics: %s\n", err)
}
}

// Check if there is a user supplied configuration
if config, _ := loadConfigFile(configPath); config != nil {
// All of of the commands run are from the configuration file
Expand Down Expand Up @@ -498,6 +508,12 @@ func getCiliumPods(namespace, label string) ([]string, error) {
return ciliumPods, nil
}

func dumpHubbleMetrics(rootDir string) error {
httpClient := http.DefaultClient
url := fmt.Sprintf("http://localhost:%d/metrics", hubbleMetricsPort)
return downloadToFile(httpClient, url, filepath.Join(rootDir, "hubble-metrics.txt"))
}

func dumpEnvoy(rootDir string, resource string, fileName string) error {
// curl --unix-socket /var/run/cilium/envoy/sockets/admin.sock http:/admin/config_dump\?include_eds > dump.json
c := &http.Client{
Expand Down

0 comments on commit 3d95fbc

Please sign in to comment.