-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add disable providers by default option (#4166)
* add disable providers by default option * don't replace agent config upon enrollment if unnecessary
- Loading branch information
Showing
14 changed files
with
347 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
changelog/fragments/1707070032-providers-default-disable.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Kind can be one of: | ||
# - breaking-change: a change to previously-documented behavior | ||
# - deprecation: functionality that is being removed in a later release | ||
# - bug-fix: fixes a problem in a previous version | ||
# - enhancement: extends functionality but does not break or fix existing behavior | ||
# - feature: new functionality | ||
# - known-issue: problems that we are aware of in a given version | ||
# - security: impacts on the security of a product or a user’s deployment. | ||
# - upgrade: important information for someone upgrading from a prior version | ||
# - other: does not fit into any of the other categories | ||
kind: enhancement | ||
|
||
# Change summary; a 80ish characters long description of the change. | ||
summary: Add agent.providers.initial_default configuration flag to disable providers by default | ||
|
||
# Long description; in case the summary is not enough to describe the change | ||
# this field accommodate a description without length limits. | ||
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment. | ||
#description: | ||
|
||
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc. | ||
component: elastic-agent | ||
|
||
# PR URL; optional; the PR number that added the changeset. | ||
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added. | ||
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number. | ||
# Please provide it if you are adding a fragment for a different PR. | ||
pr: https://github.com/elastic/elastic-agent/pull/4166 | ||
|
||
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of). | ||
# If not present is automatically filled by the tooling with the issue linked to the PR number. | ||
issue: https://github.com/elastic/elastic-agent/issues/4145 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
internal/pkg/agent/application/configuration_embed_changed_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package application | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
// This test exists to notify the cloudbeat team in case the default agent fleet config is changed. | ||
func TestDefaultAgentFleetConfig(t *testing.T) { | ||
cfg := map[string]interface{}{} | ||
|
||
err := yaml.Unmarshal(DefaultAgentFleetConfig, &cfg) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, map[string]interface{}{"fleet": map[interface{}]interface{}{"enabled": true}}, cfg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package storage | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
// This is a temporary solution to avoid replacing the target file if the content of the replacement is contained in the target file. | ||
// It only works for YAML files, since the only use case is for the default agent fleet config. | ||
// Returns true only if the replacement configuration is already contained in the original. | ||
func shouldSkipReplace(original []byte, replacement []byte) bool { | ||
replacementYaml := map[string]interface{}{} | ||
originalYaml := map[string]interface{}{} | ||
|
||
err := yaml.Unmarshal(replacement, &replacementYaml) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
err = yaml.Unmarshal(original, &originalYaml) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
diff := cmp.Diff(replacementYaml, originalYaml) | ||
if strings.HasPrefix(diff, "-") || strings.Contains(diff, "\n-") { | ||
// Lines starting with - represent values in the replacement that are not present in the original | ||
return false | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package storage | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestShouldSkipReplace(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
original []byte | ||
replacement []byte | ||
expected bool | ||
}{ | ||
{ | ||
name: "original and replacement are the same", | ||
original: []byte("fleet:\n enabled: true\n"), | ||
replacement: []byte("fleet:\n enabled: true\n"), | ||
expected: true, | ||
}, | ||
{ | ||
name: "original and replacement are different", | ||
original: []byte("fleet:\n enabled: true\n"), | ||
replacement: []byte("fleet:\n enabled: false\n"), | ||
expected: false, | ||
}, | ||
{ | ||
name: "original is not a valid yaml", | ||
original: []byte("fleet: enabled: true\n"), | ||
expected: false, | ||
}, | ||
{ | ||
name: "replacement is not a valid yaml", | ||
replacement: []byte("fleet: enabled: true\n"), | ||
expected: false, | ||
}, | ||
{ | ||
name: "original and replacement are different just in comments and spaces", | ||
original: []byte("#bla bla bla\nfleet:\n enabled: true\n"), | ||
replacement: []byte("fleet: \n enabled: true\n#oh right bla bla bla\n"), | ||
expected: true, | ||
}, | ||
{ | ||
name: "original contains replacement and more", | ||
original: []byte("#bla bla bla\nfleet:\n enabled: true\nanother: value\nmore:\n stuff: true\n"), | ||
replacement: []byte("fleet:\n enabled: true\n"), | ||
expected: true, | ||
}, | ||
{ | ||
name: "original contains replacement and more, but in different order", | ||
original: []byte("fleet:\n a_key_that_ruins: sad\n enabled: true\n"), | ||
replacement: []byte("fleet:\n enabled: true\n"), | ||
expected: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equal(t, tt.expected, shouldSkipReplace(tt.original, tt.replacement)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.