Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ linters:
deny:
- pkg: github.com/elastic/beats/v7/x-pack
desc: Apache 2.0 licensed code cannot depend on Elastic licensed code (x-pack/).
- pkg: github.com/elastic/elastic-agent-client
desc: Apache 2.0 licensed code cannot depend on Elastic licensed code (elastic-agent-client).
main:
list-mode: lax
deny:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# REQUIRED
# 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: bug-fix

# REQUIRED for all kinds
# Change summary; a 80ish characters long description of the change.
summary: Remove use of github.com/elastic/elastic-agent-client from OSS Beats.

# REQUIRED for breaking-change, deprecation, known-issue
# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
# description:

# REQUIRED for breaking-change, deprecation, known-issue
# impact:

# REQUIRED for breaking-change, deprecation, known-issue
# action:

# REQUIRED for all kinds
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
component: "all"

# AUTOMATED
# OPTIONAL to manually add other PR URLs
# PR URL: A link the PR 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/beats/pull/48353

# AUTOMATED
# OPTIONAL to manually add other issue URLs
# 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/owner/repo/1234
5 changes: 2 additions & 3 deletions libbeat/beat/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/elastic/beats/v7/libbeat/instrumentation"
"github.com/elastic/beats/v7/libbeat/management"
"github.com/elastic/beats/v7/libbeat/version"
"github.com/elastic/elastic-agent-client/v7/pkg/proto"
"github.com/elastic/elastic-agent-libs/config"
"github.com/elastic/elastic-agent-libs/keystore"
"github.com/elastic/elastic-agent-libs/paths"
Expand Down Expand Up @@ -102,9 +101,9 @@ func (beat *Beat) userAgentMode() useragent.AgentManagementMode {

info := beat.Manager.AgentInfo()
switch info.ManagedMode {
case proto.AgentManagedMode_MANAGED:
case management.AgentManagedMode_MANAGED:
return useragent.AgentManagementModeManaged
case proto.AgentManagedMode_STANDALONE:
case management.AgentManagedMode_STANDALONE:
return useragent.AgentManagementModeUnmanaged
}
// this is probably not reachable
Expand Down
29 changes: 14 additions & 15 deletions libbeat/beat/beat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,30 @@ import (

"github.com/stretchr/testify/require"

"github.com/elastic/beats/v7/libbeat/management"
"github.com/elastic/beats/v7/libbeat/management/status"
"github.com/elastic/elastic-agent-client/v7/pkg/client"
"github.com/elastic/elastic-agent-client/v7/pkg/proto"
"github.com/elastic/elastic-agent-libs/config"
)

type testManager struct {
isUnpriv bool
mgmtMode proto.AgentManagedMode
mgmtMode management.AgentManagedMode
isEnabled bool
}

func (tm testManager) UpdateStatus(_ status.Status, _ string) {}
func (tm testManager) Enabled() bool { return tm.isEnabled }
func (tm testManager) Start() error { return nil }
func (tm testManager) Stop() {}
func (tm testManager) AgentInfo() client.AgentInfo {
return client.AgentInfo{Unprivileged: tm.isUnpriv, ManagedMode: tm.mgmtMode}
func (tm testManager) AgentInfo() management.AgentInfo {
return management.AgentInfo{Unprivileged: tm.isUnpriv, ManagedMode: tm.mgmtMode}
}
func (tm testManager) SetStopCallback(_ func()) {}
func (tm testManager) CheckRawConfig(_ *config.C) error { return nil }
func (tm testManager) RegisterAction(_ client.Action) {}
func (tm testManager) UnregisterAction(_ client.Action) {}
func (tm testManager) SetPayload(_ map[string]interface{}) {}
func (tm testManager) RegisterDiagnosticHook(_ string, _ string, _ string, _ string, _ client.DiagnosticHook) {
func (tm testManager) SetStopCallback(_ func()) {}
func (tm testManager) CheckRawConfig(_ *config.C) error { return nil }
func (tm testManager) RegisterAction(_ management.Action) {}
func (tm testManager) UnregisterAction(_ management.Action) {}
func (tm testManager) SetPayload(_ map[string]interface{}) {}
func (tm testManager) RegisterDiagnosticHook(_ string, _ string, _ string, _ string, _ management.DiagnosticHook) {
}

func TestUserAgentString(t *testing.T) {
Expand All @@ -60,25 +59,25 @@ func TestUserAgentString(t *testing.T) {
{
name: "managed-unprivileged",
beat: &Beat{Info: Info{Beat: "testbeat"},
Manager: testManager{isEnabled: true, isUnpriv: true, mgmtMode: proto.AgentManagedMode_MANAGED}},
Manager: testManager{isEnabled: true, isUnpriv: true, mgmtMode: management.AgentManagedMode_MANAGED}},
expectedComments: []string{"Managed", "Unprivileged"},
},
{
name: "managed-privileged",
beat: &Beat{Info: Info{Beat: "testbeat"},
Manager: testManager{isEnabled: true, isUnpriv: false, mgmtMode: proto.AgentManagedMode_MANAGED}},
Manager: testManager{isEnabled: true, isUnpriv: false, mgmtMode: management.AgentManagedMode_MANAGED}},
expectedComments: []string{"Managed"},
},
{
name: "unmanaged-privileged",
beat: &Beat{Info: Info{Beat: "testbeat"},
Manager: testManager{isEnabled: true, isUnpriv: false, mgmtMode: proto.AgentManagedMode_STANDALONE}},
Manager: testManager{isEnabled: true, isUnpriv: false, mgmtMode: management.AgentManagedMode_STANDALONE}},
expectedComments: []string{"Unmanaged"},
},
{
name: "unmanaged-unprivileged",
beat: &Beat{Info: Info{Beat: "testbeat"},
Manager: testManager{isEnabled: true, isUnpriv: true, mgmtMode: proto.AgentManagedMode_STANDALONE}},
Manager: testManager{isEnabled: true, isUnpriv: true, mgmtMode: management.AgentManagedMode_STANDALONE}},
expectedComments: []string{"Unmanaged", "Unprivileged"},
},
{
Expand Down
13 changes: 6 additions & 7 deletions libbeat/cmd/instance/beat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/elastic/beats/v7/libbeat/management/status"
"github.com/elastic/beats/v7/libbeat/outputs"
"github.com/elastic/beats/v7/libbeat/publisher/queue/memqueue"
"github.com/elastic/elastic-agent-client/v7/pkg/client"
"github.com/elastic/elastic-agent-libs/config"
"github.com/elastic/elastic-agent-libs/logp"
"github.com/elastic/elastic-agent-libs/logp/logptest"
Expand Down Expand Up @@ -499,18 +498,18 @@ type mockManager struct {
enabled bool
}

func (m mockManager) AgentInfo() client.AgentInfo { return client.AgentInfo{} }
func (m mockManager) CheckRawConfig(cfg *config.C) error { return nil }
func (m mockManager) Enabled() bool { return m.enabled }
func (m mockManager) RegisterAction(action client.Action) {}
func (m mockManager) RegisterDiagnosticHook(name, description, filename, contentType string, hook client.DiagnosticHook) {
func (m mockManager) AgentInfo() management.AgentInfo { return management.AgentInfo{} }
func (m mockManager) CheckRawConfig(cfg *config.C) error { return nil }
func (m mockManager) Enabled() bool { return m.enabled }
func (m mockManager) RegisterAction(action management.Action) {}
func (m mockManager) RegisterDiagnosticHook(name, description, filename, contentType string, hook management.DiagnosticHook) {
}
func (m mockManager) SetPayload(payload map[string]any) {}
func (m mockManager) SetStopCallback(f func()) {}
func (m mockManager) Start() error { return nil }
func (m mockManager) Status() status.Status { return status.Status(-42) }
func (m mockManager) Stop() {}
func (m mockManager) UnregisterAction(action client.Action) {}
func (m mockManager) UnregisterAction(action management.Action) {}
func (m mockManager) UpdateStatus(status status.Status, msg string) {}

func TestManager(t *testing.T) {
Expand Down
27 changes: 0 additions & 27 deletions libbeat/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"sync"
"sync/atomic"

"github.com/elastic/elastic-agent-client/v7/pkg/proto"
conf "github.com/elastic/elastic-agent-libs/config"
)

Expand All @@ -43,32 +42,6 @@ type fflags struct {
logRunAsFilestream atomic.Bool
}

// NewConfigFromProto converts the given *proto.Features object to
// a *config.C object.
func NewConfigFromProto(f *proto.Features) (*conf.C, error) {
if f == nil {
return nil, nil
}

var beatCfg struct {
Features *proto.Features `config:"features"`
}

beatCfg.Features = f

c, err := conf.NewConfigFrom(&beatCfg)
if err != nil {
return nil, fmt.Errorf("unable to parse feature flags message into beat configuration: %w", err)
}

_, err = c.Remove("features.source", -1)
if err != nil {
return nil, fmt.Errorf("unable to convert feature flags message to beat configuration: %w", err)
}

return c, nil
}

// UpdateFromConfig updates the feature flags configuration. If c is nil UpdateFromConfig is no-op.
func UpdateFromConfig(c *conf.C) error {
if c == nil {
Expand Down
56 changes: 0 additions & 56 deletions libbeat/features/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,67 +20,11 @@ package features
import (
"testing"

"google.golang.org/protobuf/types/known/structpb"

"github.com/elastic/elastic-agent-client/v7/pkg/proto"
"github.com/elastic/elastic-agent-libs/config"

"github.com/stretchr/testify/require"
)

func TestNewConfigFromProto(t *testing.T) {
source, err := structpb.NewStruct(map[string]interface{}{
"fqdn": map[string]interface{}{
"enabled": false,
},
})
require.NoError(t, err)

tests := map[string]struct {
protoFeatures *proto.Features
expected *config.C
}{
"nil": {
protoFeatures: nil,
expected: nil,
},
"fqdn_enabled": {
protoFeatures: &proto.Features{Fqdn: &proto.FQDNFeature{Enabled: true}},
expected: config.MustNewConfigFrom(`
features:
fqdn:
enabled: true
`),
},
"fqdn_disabled": {
protoFeatures: &proto.Features{Fqdn: &proto.FQDNFeature{Enabled: false}},
expected: config.MustNewConfigFrom(`
features:
fqdn:
enabled: false
`),
},
"with_source": {
protoFeatures: &proto.Features{Fqdn: &proto.FQDNFeature{Enabled: true}, Source: source},
expected: config.MustNewConfigFrom(`
features:
fqdn:
enabled: true
`),
},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {
c, err := NewConfigFromProto(test.protoFeatures)
require.NoError(t, err)

require.Equal(t, test.expected, c)
})
}

}

func TestFQDN(t *testing.T) {
tcs := []struct {
name string
Expand Down
25 changes: 12 additions & 13 deletions libbeat/management/management.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/elastic/beats/v7/libbeat/common/reload"
"github.com/elastic/beats/v7/libbeat/management/status"
"github.com/elastic/elastic-agent-client/v7/pkg/client"
"github.com/elastic/elastic-agent-libs/config"
"github.com/elastic/elastic-agent-libs/logp"
)
Expand Down Expand Up @@ -56,7 +55,7 @@ type Manager interface {
Stop()

// AgentInfo returns the information of the agent to which the manager is connected.
AgentInfo() client.AgentInfo
AgentInfo() AgentInfo

// SetStopCallback accepts a function that need to be called when the manager want to shutdown the
// beats. This is needed when you want your beats to be gracefully shutdown remotely by the Elastic Agent
Expand All @@ -67,16 +66,16 @@ type Manager interface {
CheckRawConfig(cfg *config.C) error

// RegisterAction registers action handler with the client
RegisterAction(action client.Action)
RegisterAction(action Action)

// UnregisterAction unregisters action handler with the client
UnregisterAction(action client.Action)
UnregisterAction(action Action)

// SetPayload Allows to add additional metadata to future requests made by the manager.
SetPayload(map[string]interface{})

// RegisterDiagnosticHook registers a callback for elastic-agent diagnostics
RegisterDiagnosticHook(name string, description string, filename string, contentType string, hook client.DiagnosticHook)
RegisterDiagnosticHook(name string, description string, filename string, contentType string, hook DiagnosticHook)
}

// ManagerFactory is the factory type for creating a config manager
Expand Down Expand Up @@ -162,12 +161,12 @@ func (n *FallbackManager) Stop() {
// the nilManager is still used for shutdown on some cases,
// but that does not mean the Beat is being managed externally,
// hence it will always return false.
func (n *FallbackManager) Enabled() bool { return false }
func (n *FallbackManager) AgentInfo() client.AgentInfo { return client.AgentInfo{} }
func (n *FallbackManager) Start() error { return nil }
func (n *FallbackManager) CheckRawConfig(cfg *config.C) error { return nil }
func (n *FallbackManager) RegisterAction(action client.Action) {}
func (n *FallbackManager) UnregisterAction(action client.Action) {}
func (n *FallbackManager) SetPayload(map[string]interface{}) {}
func (n *FallbackManager) RegisterDiagnosticHook(_ string, _ string, _ string, _ string, _ client.DiagnosticHook) {
func (n *FallbackManager) Enabled() bool { return false }
func (n *FallbackManager) AgentInfo() AgentInfo { return AgentInfo{} }
func (n *FallbackManager) Start() error { return nil }
func (n *FallbackManager) CheckRawConfig(cfg *config.C) error { return nil }
func (n *FallbackManager) RegisterAction(action Action) {}
func (n *FallbackManager) UnregisterAction(action Action) {}
func (n *FallbackManager) SetPayload(map[string]interface{}) {}
func (n *FallbackManager) RegisterDiagnosticHook(_ string, _ string, _ string, _ string, _ DiagnosticHook) {
}
Loading
Loading