From 176f2deb20bbe8bd0d2e21732786be1730148092 Mon Sep 17 00:00:00 2001 From: Gustavo Caso Date: Wed, 15 Nov 2023 17:17:13 +0100 Subject: [PATCH] apply feedback --- cmd/agent/gui/agent.go | 2 +- pkg/status/collector/collector.go | 24 +++++++++++------------- pkg/status/status.go | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/cmd/agent/gui/agent.go b/cmd/agent/gui/agent.go index 76b04859be29fc..633ee8231beff6 100644 --- a/cmd/agent/gui/agent.go +++ b/cmd/agent/gui/agent.go @@ -58,7 +58,7 @@ func getStatus(w http.ResponseWriter, r *http.Request) { err error ) if statusType == "collector" { - stats = collector.GetStatus() + stats = collector.GetStatusInfo() } else { verbose := r.URL.Query().Get("verbose") == "true" stats, err = status.GetStatus(verbose) diff --git a/pkg/status/collector/collector.go b/pkg/status/collector/collector.go index 4a56212594a010..6272a6f6648d16 100644 --- a/pkg/status/collector/collector.go +++ b/pkg/status/collector/collector.go @@ -3,7 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. -// Package collector fetch information from different agent chekcs from expvar +// Package collector fetch information needed to render the 'collector' section of the status page. +// This will, in time, be migrated to the collector package/comp. package collector import ( @@ -11,18 +12,17 @@ import ( "expvar" ) -// PopulateStatus populates stats with collector information -func PopulateStatus(stats map[string]interface{}) { - status := GetStatus() - for key, value := range status { - stats[key] = value - } -} - -// GetStatus retrives collector information -func GetStatus() map[string]interface{} { +// GetStatusInfo retrives collector information +func GetStatusInfo() map[string]interface{} { stats := make(map[string]interface{}) + PopulateStatus(stats) + + return stats +} + +// PopulateStatus populates stats with collector information +func PopulateStatus(stats map[string]interface{}) { runnerStatsJSON := []byte(expvar.Get("runner").String()) runnerStats := make(map[string]interface{}) json.Unmarshal(runnerStatsJSON, &runnerStats) //nolint:errcheck @@ -92,6 +92,4 @@ func GetStatus() map[string]interface{} { } else { stats["agent_metadata"] = map[string]string{} } - - return stats } diff --git a/pkg/status/status.go b/pkg/status/status.go index 3ee9cb86cf2cfb..1f42f15c84509b 100644 --- a/pkg/status/status.go +++ b/pkg/status/status.go @@ -125,7 +125,7 @@ func GetAndFormatStatus() ([]byte, error) { // GetCheckStatusJSON gets the status of a single check as JSON func GetCheckStatusJSON(c check.Check, cs *checkstats.Stats) ([]byte, error) { - s := collector.GetStatus() + s := collector.GetStatusInfo() checks := s["runnerStats"].(map[string]interface{})["Checks"].(map[string]interface{}) checks[c.String()] = make(map[checkid.ID]interface{})