Skip to content

Commit bca145e

Browse files
authored
Merge branch 'main' into dependabot/go_modules/github.com/elastic/elastic-agent-system-metrics-0.9.3
2 parents 99b63fa + fdba118 commit bca145e

File tree

6 files changed

+136
-5
lines changed

6 files changed

+136
-5
lines changed

.agent-versions.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"testVersions": [
33
"8.14.0-SNAPSHOT",
4-
"8.13.3",
5-
"8.13.3-SNAPSHOT",
4+
"8.13.5-SNAPSHOT",
5+
"8.13.4",
66
"8.12.2",
7-
"7.17.21",
8-
"7.17.21-SNAPSHOT"
7+
"7.17.22-SNAPSHOT",
8+
"7.17.21"
99
]
1010
}

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ check:
4848
## check-go: download and run the go linter.
4949
.PHONY: check-go
5050
check-go: ## - Run golangci-lint
51-
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.44.2
51+
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.55.2
5252
@./bin/golangci-lint run -v
5353

5454
## check-no-changes : Check there is no local changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: enhancement
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: Add agent-info.yaml to diagnostics bundle
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
#description:
20+
21+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
22+
component:
23+
24+
# PR URL; optional; the PR number that added the changeset.
25+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
26+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
27+
# Please provide it if you are adding a fragment for a different PR.
28+
pr: https://github.com/elastic/elastic-agent/pull/4725
29+
30+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
31+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
32+
issue: https://github.com/elastic/elastic-agent/issues/4439

internal/pkg/agent/application/coordinator/coordinator.go

+28
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,34 @@ func (c *Coordinator) Run(ctx context.Context) error {
714714
// Called by external goroutines.
715715
func (c *Coordinator) DiagnosticHooks() diagnostics.Hooks {
716716
return diagnostics.Hooks{
717+
{
718+
Name: "agent-info",
719+
Filename: "agent-info.yaml",
720+
Description: "current state of the agent information of the running Elastic Agent",
721+
ContentType: "application/yaml",
722+
Hook: func(_ context.Context) []byte {
723+
output := struct {
724+
AgentID string `yaml:"agent_id"`
725+
Headers map[string]string `yaml:"headers"`
726+
LogLevel string `yaml:"log_level"`
727+
Snapshot bool `yaml:"snapshot"`
728+
Version string `yaml:"version"`
729+
Unprivileged bool `yaml:"unprivileged"`
730+
}{
731+
AgentID: c.agentInfo.AgentID(),
732+
Headers: c.agentInfo.Headers(),
733+
LogLevel: c.agentInfo.LogLevel(),
734+
Snapshot: c.agentInfo.Snapshot(),
735+
Version: c.agentInfo.Version(),
736+
Unprivileged: c.agentInfo.Unprivileged(),
737+
}
738+
o, err := yaml.Marshal(output)
739+
if err != nil {
740+
return []byte(fmt.Sprintf("error: %q", err))
741+
}
742+
return o
743+
},
744+
},
717745
{
718746
Name: "local-config",
719747
Filename: "local-config.yaml",

internal/pkg/agent/application/coordinator/diagnostics_test.go

+70
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
func TestCoordinatorExpectedDiagnosticHooks(t *testing.T) {
3434

3535
expected := []string{
36+
"agent-info",
3637
"local-config",
3738
"pre-config",
3839
"variables",
@@ -128,6 +129,39 @@ fleet:
128129
assert.YAMLEq(t, expectedCfg, string(result), "local-config diagnostic returned unexpected value")
129130
}
130131

132+
func TestDiagnosticAgentInfo(t *testing.T) {
133+
// Create a coordinator with an info.Agent and ensure its included in diagnostics.
134+
135+
coord := &Coordinator{agentInfo: fakeAgentInfo{
136+
agentID: "agent-id",
137+
headers: map[string]string{
138+
"header1": "value1",
139+
"header2": "value2",
140+
},
141+
logLevel: "trace",
142+
snapshot: true,
143+
version: "8.14.0",
144+
unprivileged: true,
145+
}}
146+
147+
expected := `
148+
agent_id: agent-id
149+
headers:
150+
header1: value1
151+
header2: value2
152+
log_level: trace
153+
snapshot: true
154+
version: 8.14.0
155+
unprivileged: true
156+
`
157+
158+
hook, ok := diagnosticHooksMap(coord)["agent-info"]
159+
require.True(t, ok, "diagnostic hooks should have an entry for agent-info")
160+
161+
result := hook.Hook(context.Background())
162+
assert.YAMLEq(t, expected, string(result), "agent-info diagnostic returned unexpected value")
163+
}
164+
131165
func TestDiagnosticPreConfig(t *testing.T) {
132166
// Create a coordinator with a test AST and make sure it's returned
133167
// by the pre-config diagnostic.
@@ -589,3 +623,39 @@ func mapFromRawYAML(t *testing.T, str string) map[string]interface{} {
589623
require.NoError(t, err, "Parsing of YAML test string must succeed")
590624
return result
591625
}
626+
627+
type fakeAgentInfo struct {
628+
agentID string
629+
headers map[string]string
630+
logLevel string
631+
snapshot bool
632+
version string
633+
unprivileged bool
634+
}
635+
636+
func (a fakeAgentInfo) AgentID() string {
637+
return a.agentID
638+
}
639+
640+
func (a fakeAgentInfo) Headers() map[string]string {
641+
return a.headers
642+
}
643+
644+
func (a fakeAgentInfo) LogLevel() string {
645+
return a.logLevel
646+
}
647+
648+
func (a fakeAgentInfo) Snapshot() bool {
649+
return a.snapshot
650+
}
651+
652+
func (a fakeAgentInfo) Version() string {
653+
return a.version
654+
}
655+
656+
func (a fakeAgentInfo) Unprivileged() bool {
657+
return a.unprivileged
658+
}
659+
660+
func (a fakeAgentInfo) ReloadID(ctx context.Context) error { panic("implement me") }
661+
func (a fakeAgentInfo) SetLogLevel(ctx context.Context, level string) error { panic("implement me") }

testing/integration/diagnostics_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const diagnosticsArchiveGlobPattern = "elastic-agent-diagnostics-*.zip"
3131

3232
var diagnosticsFiles = []string{
3333
"package.version",
34+
"agent-info.yaml",
3435
"allocs.pprof.gz",
3536
"block.pprof.gz",
3637
"components-actual.yaml",

0 commit comments

Comments
 (0)