From d8c61b3d30ab2877b24151a0a4e2a468e8a2d7db 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 | 11 +++-------- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/cmd/agent/gui/agent.go b/cmd/agent/gui/agent.go index e3ff2089bd179..3f2cb5e975d62 100644 --- a/cmd/agent/gui/agent.go +++ b/cmd/agent/gui/agent.go @@ -59,7 +59,7 @@ func getStatus(w http.ResponseWriter, r *http.Request, invAgent inventoryagent.C err error ) if statusType == "collector" { - stats = collector.GetStatus() + stats = collector.GetStatusInfo() } else { verbose := r.URL.Query().Get("verbose") == "true" stats, err = status.GetStatus(verbose, invAgent) diff --git a/pkg/status/collector/collector.go b/pkg/status/collector/collector.go index 4a56212594a01..6272a6f6648d1 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 83db5929c2ea1..ea110dae7e2e1 100644 --- a/pkg/status/status.go +++ b/pkg/status/status.go @@ -126,19 +126,14 @@ func GetAndFormatStatus(invAgent inventoryagent.Component) ([]byte, error) { // GetCheckStatusJSON gets the status of a single check as JSON func GetCheckStatusJSON(c check.Check, cs *checkstats.Stats) ([]byte, error) { -<<<<<<< HEAD - stats := make(map[string]interface{}) - stats = getRunnerStats(stats) - checks := stats["runnerStats"].(map[string]interface{})["Checks"].(map[string]interface{}) -======= - s := collector.GetStatus() + s := collector.GetStatusInfo() checks := s["runnerStats"].(map[string]interface{})["Checks"].(map[string]interface{}) ->>>>>>> ff866964ad (use collector package to just collect check information) + checks[c.String()] = make(map[checkid.ID]interface{}) checks[c.String()].(map[checkid.ID]interface{})[c.ID()] = cs - statusJSON, err := json.Marshal(stats) + statusJSON, err := json.Marshal(s) if err != nil { return nil, err }