From 090cad2e7ded7a6930b845020c25f6bbd0f67042 Mon Sep 17 00:00:00 2001 From: Alex Demidoff Date: Thu, 31 Oct 2024 17:47:39 +0300 Subject: [PATCH 1/3] PMM-13392 fix agent status prefix for json --- admin/agentlocal/agentlocal.go | 4 +++- admin/commands/inventory/list_agents.go | 4 ++-- admin/commands/list.go | 4 ++-- admin/commands/status.go | 5 ++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/admin/agentlocal/agentlocal.go b/admin/agentlocal/agentlocal.go index 4a6d38cf19..8c066b92c6 100644 --- a/admin/agentlocal/agentlocal.go +++ b/admin/agentlocal/agentlocal.go @@ -21,6 +21,7 @@ import ( "fmt" "net/http" "net/url" + "strings" "time" "github.com/AlekSi/pointer" @@ -137,10 +138,11 @@ func GetStatus(requestNetworkInfo NetworkInfo) (*Status, error) { agents := make([]AgentStatus, len(p.AgentsInfo)) for i, a := range p.AgentsInfo { + status, _ := strings.CutPrefix(pointer.GetString(a.Status), "AGENT_STATUS_") agents[i] = AgentStatus{ AgentID: a.AgentID, AgentType: pointer.GetString(a.AgentType), - Status: pointer.GetString(a.Status), + Status: status, Port: a.ListenPort, } } diff --git a/admin/commands/inventory/list_agents.go b/admin/commands/inventory/list_agents.go index e0886c22f8..dca5ef5950 100644 --- a/admin/commands/inventory/list_agents.go +++ b/admin/commands/inventory/list_agents.go @@ -31,9 +31,9 @@ import ( var listAgentsResultT = commands.ParseTemplate(` Agents list. -{{ printf "%-27s" "Agent type" }} {{ printf "%-15s" "Status" }} {{ printf "%-47s" "Agent ID" }} {{ printf "%-47s" "PMM-Agent ID" }} {{ printf "%-47s" "Service ID" }} {{ printf "%-47s" "Port" }} +{{ printf "%-29s" "Agent type" }} {{ printf "%-15s" "Status" }} {{ printf "%-39s" "Agent ID" }} {{ printf "%-39s" "PMM-Agent ID" }} {{ printf "%-38s" "Service ID" }} {{ printf "%-20s" "Port" }} {{ range .Agents }} -{{- printf "%-27s" .HumanReadableAgentType }} {{ printf "%-15s" .NiceAgentStatus }} {{ .AgentID }} {{ .PMMAgentID }} {{ .ServiceID }} {{ .Port }} +{{- printf "%-29s" .HumanReadableAgentType }} {{ printf "%-15s" .NiceAgentStatus }} {{ printf "%-38s" .AgentID }} {{ printf "%-38s" .PMMAgentID }} {{ printf "%-38s" .ServiceID }} {{ .Port }} {{ end }} `) diff --git a/admin/commands/list.go b/admin/commands/list.go index e274d17da7..9f5b63b021 100644 --- a/admin/commands/list.go +++ b/admin/commands/list.go @@ -61,7 +61,7 @@ func (a listResultAgent) HumanReadableAgentType() string { } func (a listResultAgent) NiceAgentStatus() string { - res, _ := strings.CutPrefix(a.Status, "AGENT_STATUS_") + res := a.Status if res == "" { res = "unknown" //nolint:goconst } @@ -219,7 +219,7 @@ func servicesList(servicesRes *services.ListServicesOK) []listResultService { func agentsList(agentsRes *agents.ListAgentsOK, nodeID string) []listResultAgent { //nolint:cyclop getStatus := func(s *string) string { - res := pointer.GetString(s) + res, _ := strings.CutPrefix(pointer.GetString(s), "AGENT_STATUS_") if res == "" { res = "unknown" } diff --git a/admin/commands/status.go b/admin/commands/status.go index 119e1cba5b..bb6cc294ef 100644 --- a/admin/commands/status.go +++ b/admin/commands/status.go @@ -46,7 +46,7 @@ PMM Client: pmm-admin version: {{ .PMMVersion }} pmm-agent version: {{ .PMMAgentStatus.AgentVersion }} Agents: -{{ range .PMMAgentStatus.Agents }} {{ .AgentID }} {{ .AgentType | $.HumanReadableAgentType }} {{ .Status | $.NiceAgentStatus }} {{ .Port }} +{{ range .PMMAgentStatus.Agents }} {{ .AgentID }} {{ printf "%-29s" (.AgentType | $.HumanReadableAgentType) }} {{ printf "%-15s" (.Status | $.NiceAgentStatus) }} {{ .Port }} {{ end }} `) @@ -60,8 +60,7 @@ func (res *statusResult) HumanReadableAgentType(agentType string) string { } func (res *statusResult) NiceAgentStatus(status string) string { - s, _ := strings.CutPrefix(status, "AGENT_STATUS_") - return cases.Title(language.English).String(strings.ToLower(s)) + return cases.Title(language.English).String(strings.ToLower(status)) } func (res *statusResult) Result() {} From d79ffc0e064108088b99b1923476c5cedfd81926 Mon Sep 17 00:00:00 2001 From: Alex Demidoff Date: Thu, 31 Oct 2024 17:57:06 +0300 Subject: [PATCH 2/3] PMM-13392 fix status_test --- admin/commands/status_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/admin/commands/status_test.go b/admin/commands/status_test.go index f953fd677d..78f9deba0a 100644 --- a/admin/commands/status_test.go +++ b/admin/commands/status_test.go @@ -65,9 +65,9 @@ PMM Client: pmm-admin version: unknown pmm-agent version: 2.5.1 Agents: - 1afe233f-b319-4645-be6c-a1e05d4a545b node_exporter Running 3310 - 2c7c0e04-6eef-411d-bcce-51e138e771cc postgresql_pgstatements_agent Running 0 - 4824ac2b-3f1f-4e9b-90d1-3f56b891bb8b postgres_exporter Running 5432 + 1afe233f-b319-4645-be6c-a1e05d4a545b node_exporter Running 3310 + 2c7c0e04-6eef-411d-bcce-51e138e771cc postgresql_pgstatements_agent Running 0 + 4824ac2b-3f1f-4e9b-90d1-3f56b891bb8b postgres_exporter Running 5432 `) + "\n" assert.Equal(t, expected, res.String()) } From 51b83dbe14d18ef02971d34ca8f17c5f9b8c9b01 Mon Sep 17 00:00:00 2001 From: Alex Demidoff Date: Fri, 8 Nov 2024 17:52:37 +0300 Subject: [PATCH 3/3] PMM-13392 regenrate the swagger spec --- api/swagger/swagger-dev.json | 3 ++- api/swagger/swagger.json | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/api/swagger/swagger-dev.json b/api/swagger/swagger-dev.json index 267c48147b..209f528470 100644 --- a/api/swagger/swagger-dev.json +++ b/api/swagger/swagger-dev.json @@ -5185,7 +5185,8 @@ "AGENT_TYPE_QAN_POSTGRESQL_PGSTATMONITOR_AGENT", "AGENT_TYPE_EXTERNAL_EXPORTER", "AGENT_TYPE_RDS_EXPORTER", - "AGENT_TYPE_AZURE_DATABASE_EXPORTER" + "AGENT_TYPE_AZURE_DATABASE_EXPORTER", + "AGENT_TYPE_NOMAD_AGENT" ], "type": "string", "default": "AGENT_TYPE_UNSPECIFIED", diff --git a/api/swagger/swagger.json b/api/swagger/swagger.json index 2d5d164b06..6e35d2a7a3 100644 --- a/api/swagger/swagger.json +++ b/api/swagger/swagger.json @@ -4227,7 +4227,8 @@ "AGENT_TYPE_QAN_POSTGRESQL_PGSTATMONITOR_AGENT", "AGENT_TYPE_EXTERNAL_EXPORTER", "AGENT_TYPE_RDS_EXPORTER", - "AGENT_TYPE_AZURE_DATABASE_EXPORTER" + "AGENT_TYPE_AZURE_DATABASE_EXPORTER", + "AGENT_TYPE_NOMAD_AGENT" ], "type": "string", "default": "AGENT_TYPE_UNSPECIFIED",