Skip to content

Commit 017ecc3

Browse files
fix: clean up spacing for diagnose and status output, move status to end of output (#159)
### Description Clean up spacing for diagnose and status output, move status to end of output. Ex: ``` $ ./observe-agent status Error getting agent metrics: Get "http://localhost:8888/metrics": dial tcp 127.0.0.1:8888: connect: connection refused ================ Agent ================ Host Info ================ HostID: ... Hostname: ... BootTime: 2025-02-25T22:47:39-06:00 Uptime: 206h22m21s OS: darwin Platform: darwin PlatformFamily: Standalone Workstation PlatformVersion: 15.3.1 KernelArch: arm64 KernelVersion: 24.3.0 Agent Health ================ Status: NotRunning ``` or ``` $ ./observe-agent status ================ Agent ================ Host Info ================ HostID: ... Hostname: ... BootTime: 2025-02-25T22:47:39-06:00 Uptime: 206h25m34s OS: darwin Platform: darwin PlatformFamily: Standalone Workstation PlatformVersion: 15.3.1 KernelArch: arm64 KernelVersion: 24.3.0 Agent Metrics ================ ExporterQueueSize: 0 CPUSeconds: 0.15447955s MemoryUsed: 82.5625MB TotalSysMemory: 27.891853MB Uptime: 7.477466s AvgServerResponseTime: 0ms AvgClientResponseTime: 0ms Logs Stats ================ ReceiverAcceptedCount: 0 ReceiverRefusedCount: 0 ExporterSentCount: 0 ExporterSendFailedCount: 0 Metrics Stats ================ ReceiverAcceptedCount: 0 ReceiverRefusedCount: 0 ExporterSentCount: 0 ExporterSendFailedCount: 0 Traces Stats ================ ReceiverAcceptedCount: 0 ReceiverRefusedCount: 0 ExporterSentCount: 0 ExporterSendFailedCount: 0 Agent Health ================ Status: Running TotalRefusedCount: 0 TotalSendFailedCount: 0 ``` ### Checklist - [ ] Created tests which fail without the change (if possible) - [ ] Extended the README / documentation, if necessary
1 parent 8e7bf08 commit 017ecc3

File tree

7 files changed

+41
-34
lines changed

7 files changed

+41
-34
lines changed

.github/workflows/tests-integration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
with:
4343
distribution: goreleaser-pro
4444
version: 2.7.0
45-
args: release --prepare --clean --snapshot --verbose --parallelism 8
45+
args: release --prepare --clean --snapshot --verbose --parallelism 6
4646
env:
4747
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
4848
- name: Save docker as .tar #Save docker images to tar
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Running auth check against {{ .URL }}
22

3-
{{- if .Passed -}}
3+
{{- if .Passed }}
44
Request to test URL responded with response code {{ .ResponseCode }}
5-
{{- else if eq .ResponseCode 401 -}}
5+
{{- else if eq .ResponseCode 401 }}
66
⚠️ Request to test URL failed with error {{ .Error }}.
77

88
Remediation
99
Please check that the token is present in the `observe-agent.yaml` config file and that the token is valid.
10-
{{- else -}}
10+
{{- else }}
1111
⚠️ Request to test URL failed with error {{ .Error }} and response code {{ .ResponseCode }}.
1212
{{- end -}}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Running check on observe-agent config file {{ .ConfigFile }}
22

3-
{{- if .IsValid -}}
3+
{{- if .IsValid }}
44
Config file is valid.
5-
{{- else if .ParseSucceeded -}}
5+
{{- else if .ParseSucceeded }}
66
⚠️ Config file validation failed with error {{ .Error }}
7-
{{- else -}}
7+
{{- else }}
88
⚠️ Config file could not be parsed as YAML
99
{{ .Error }}
1010
{{- end -}}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{{- if .Passed -}}
22
OTEL configuration is valid.
33
{{- else -}}
4-
⚠️ OTEL configuration validation failed with error {{ .Error }}
4+
⚠️ OTEL configuration validation failed with error:
5+
{{ .Error }}
56
{{- end -}}

internal/commands/status/status.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"html/template"
99
"os"
1010

11+
"github.com/observeinc/observe-agent/internal/connections"
1112
"github.com/observeinc/observe-agent/internal/root"
1213
"github.com/spf13/cobra"
1314
)
@@ -31,24 +32,16 @@ var statusCmd = &cobra.Command{
3132

3233
func init() {
3334
root.RootCmd.AddCommand(statusCmd)
34-
35-
// Here you will define your flags and configuration settings.
36-
37-
// Cobra supports Persistent Flags which will work for this command
38-
// and all subcommands, e.g.:
39-
// statusCmd.PersistentFlags().String("foo", "", "A help for foo")
40-
41-
// Cobra supports local flags which will only run when this command
42-
// is called directly, e.g.:
43-
// statusCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
4435
}
4536

4637
func getStatusFromTemplate() error {
4738
data, err := GetStatusData()
4839
if err != nil {
4940
return err
5041
}
51-
t := template.Must(template.New(statusTemplate).ParseFS(statusTemplateFS, statusTemplate))
42+
t := template.Must(template.New(statusTemplate).
43+
Funcs(connections.GetTemplateFuncMap()).
44+
ParseFS(statusTemplateFS, statusTemplate))
5245
if err := t.ExecuteTemplate(os.Stdout, statusTemplate, data); err != nil {
5346
return err
5447
}

internal/commands/status/status.tmpl

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
================
2-
Agent
2+
Agent
33
================
44

5-
Status: {{ .Status }}
6-
7-
Host Info
8-
================
5+
Host Info
6+
================
97
HostID: {{ .HostID }}
108
Hostname: {{ .Hostname }}
119
BootTime: {{ .BootTime }}
12-
Uptime: {{ .UpTime }}
10+
Uptime: {{ .UpTime }}
1311
OS: {{ .OS }}
1412
Platform: {{ .Platform }}
1513
PlatformFamily: {{ .PlatformFamily }}
1614
PlatformVersion: {{ .PlatformVersion }}
1715
KernelArch: {{ .KernelArch }}
1816
KernelVersion: {{ .KernelVersion }}
17+
{{- if eq .Status "Running" }}
1918

20-
{{if eq .Status "Running"}}
21-
Agent Metrics
19+
Agent Metrics
2220
================
2321
ExporterQueueSize: {{ .AgentMetrics.ExporterQueueSize }}
2422
CPUSeconds: {{ .AgentMetrics.CPUSeconds }}s
@@ -27,25 +25,33 @@ Agent
2725
Uptime: {{ .AgentMetrics.Uptime }}s
2826
AvgServerResponseTime: {{ .AgentMetrics.AvgServerResponseTime }}ms
2927
AvgClientResponseTime: {{ .AgentMetrics.AvgClientResponseTime }}ms
30-
28+
3129
Logs Stats
32-
===============
30+
================
3331
ReceiverAcceptedCount: {{ .AgentMetrics.LogsStats.ReceiverAcceptedCount }}
3432
ReceiverRefusedCount: {{ .AgentMetrics.LogsStats.ReceiverRefusedCount }}
3533
ExporterSentCount: {{ .AgentMetrics.LogsStats.ExporterSentCount }}
3634
ExporterSendFailedCount: {{ .AgentMetrics.LogsStats.ExporterSendFailedCount }}
37-
35+
3836
Metrics Stats
39-
===============
37+
================
4038
ReceiverAcceptedCount: {{ .AgentMetrics.MetricsStats.ReceiverAcceptedCount }}
4139
ReceiverRefusedCount: {{ .AgentMetrics.MetricsStats.ReceiverRefusedCount }}
4240
ExporterSentCount: {{ .AgentMetrics.MetricsStats.ExporterSentCount }}
4341
ExporterSendFailedCount: {{ .AgentMetrics.MetricsStats.ExporterSendFailedCount }}
44-
42+
4543
Traces Stats
46-
===============
44+
================
4745
ReceiverAcceptedCount: {{ .AgentMetrics.TracesStats.ReceiverAcceptedCount }}
4846
ReceiverRefusedCount: {{ .AgentMetrics.TracesStats.ReceiverRefusedCount }}
4947
ExporterSentCount: {{ .AgentMetrics.TracesStats.ExporterSentCount }}
5048
ExporterSendFailedCount: {{ .AgentMetrics.TracesStats.ExporterSendFailedCount }}
51-
{{end -}}
49+
{{- end }}
50+
51+
Agent Health
52+
================
53+
Status: {{ .Status }}
54+
{{- if eq .Status "Running" }}
55+
TotalRefusedCount: {{ add .AgentMetrics.LogsStats.ReceiverRefusedCount .AgentMetrics.MetricsStats.ReceiverRefusedCount .AgentMetrics.TracesStats.ReceiverRefusedCount }}
56+
TotalSendFailedCount: {{ add .AgentMetrics.LogsStats.ExporterSendFailedCount .AgentMetrics.MetricsStats.ExporterSendFailedCount .AgentMetrics.TracesStats.ExporterSendFailedCount }}
57+
{{- end }}

internal/connections/templatefuncs.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ func GetTemplateFuncMap() template.FuncMap {
1414
"inlineArrayStr": TplInlineArray[string],
1515
"valToYaml": TmplValueToYaml,
1616
"objToYaml": TplToYaml,
17+
"add": func(values ...int) int {
18+
sum := 0
19+
for _, i := range values {
20+
sum += i
21+
}
22+
return sum
23+
},
1724
}
1825
}
1926

0 commit comments

Comments
 (0)