Skip to content

Commit

Permalink
PMM-13392 Strip agent status prefix in json (#3276)
Browse files Browse the repository at this point in the history
* PMM-13392 fix agent status prefix for json

* PMM-13392 fix status_test

* PMM-13392 regenrate the swagger spec
  • Loading branch information
ademidoff authored Nov 8, 2024
1 parent 9fcf353 commit b70db18
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
4 changes: 3 additions & 1 deletion admin/agentlocal/agentlocal.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"net/http"
"net/url"
"strings"
"time"

"github.com/AlekSi/pointer"
Expand Down Expand Up @@ -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,
}
}
Expand Down
4 changes: 2 additions & 2 deletions admin/commands/inventory/list_agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
`)

Expand Down
4 changes: 2 additions & 2 deletions admin/commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (a listResultAgent) HumanReadableAgentType() string {

// NiceAgentStatus returns human-readable agent status.
func (a listResultAgent) NiceAgentStatus() string {
res, _ := strings.CutPrefix(a.Status, "AGENT_STATUS_")
res := a.Status
if res == "" {
res = "unknown" //nolint:goconst
}
Expand Down Expand Up @@ -221,7 +221,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"
}
Expand Down
5 changes: 2 additions & 3 deletions admin/commands/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
`)

Expand All @@ -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() {}
Expand Down
6 changes: 3 additions & 3 deletions admin/commands/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down

0 comments on commit b70db18

Please sign in to comment.