Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable kubeadm for filebeat (both filbeat.input and filbeat.autodiscover) #40301

Merged
merged 36 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7ec7a1b
first effort to disable kubeadm for filebeat autodiscover
gizas Jul 19, 2024
e040782
merging with main
gizas Aug 28, 2024
634c37f
merging with main util
gizas Aug 28, 2024
badda64
merging with main test file
gizas Aug 28, 2024
2657b9a
adding kubeadm changes and merging to main
gizas Sep 10, 2024
9cb2e68
adding filebeat
gizas Sep 10, 2024
9f127ca
adding filebeat manifest
gizas Sep 10, 2024
ed5e62f
adding go.sum
gizas Sep 10, 2024
72e8ec2
removing printf
gizas Sep 10, 2024
4301d26
Merge branch 'main' into kubeadm_filebeat
gizas Sep 10, 2024
df80e6f
fixing conflicts
gizas Sep 10, 2024
c57c9a3
fixing conflicts
gizas Sep 10, 2024
c830308
adding Changelog
gizas Sep 10, 2024
f048bb0
adding description on relevant refenrence yaml files
gizas Sep 10, 2024
d05c2ac
adding description on relevant refenrence yaml files
gizas Sep 10, 2024
ea37261
adding description on relevant refenrence yaml files
gizas Sep 10, 2024
a4a9f7f
adding description on relevant refenrence yaml files
gizas Sep 10, 2024
a1a2287
adding description on relevant refenrence yaml files
gizas Sep 10, 2024
ce90016
adding err handling to fix linting errors
gizas Sep 10, 2024
03882cd
Merge branch 'main' into kubeadm_filebeat
gizas Sep 10, 2024
7c53e7e
adding description on relevant refenrence yaml files
gizas Sep 10, 2024
1ea2121
Merge branch 'kubeadm_filebeat' of github.com:elastic/beats into kube…
gizas Sep 10, 2024
3534ecf
adding processor fixes
gizas Sep 10, 2024
f5aff00
adding processor docs
gizas Sep 10, 2024
cef81a6
adding processor docs
gizas Sep 10, 2024
831a647
Update filebeat/_meta/test/docs/01_playground/filebeat.yaml
gizas Sep 10, 2024
3adaadf
Update libbeat/processors/add_kubernetes_metadata/docs/add_kubernetes…
gizas Sep 10, 2024
41ffe1c
Update dev-tools/kubernetes/filebeat/Dockerfile.debug
gizas Sep 10, 2024
47e82d3
fixing docs and adding mericbeat references
gizas Sep 10, 2024
f079b5a
fixing docs and adding mericbeat references
gizas Sep 10, 2024
e3613ac
Merge branch 'main' into kubeadm_filebeat
gizas Sep 13, 2024
69862e3
Update filebeat/_meta/config/filebeat.autodiscover.reference.yml.tmpl
gizas Sep 18, 2024
4489901
Merge branch 'main' of github.com:elastic/beats into kubeadm_filebeat
gizas Sep 18, 2024
b50a0cb
updating docs
gizas Sep 18, 2024
a419fcb
Merge branch 'main' of github.com:elastic/beats into kubeadm_filebeat
gizas Sep 18, 2024
8213010
updating docs
gizas Sep 18, 2024
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: 1 addition & 1 deletion dev-tools/kubernetes/filebeat/Dockerfile.debug
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/go/bin:/usr/local/go/bin

ENV CGO_ENABLED=0

RUN go install github.com/go-delve/delve/cmd/dlv@v1.21.2
RUN go install github.com/go-delve/delve/cmd/dlv@v1.23.0
gizas marked this conversation as resolved.
Show resolved Hide resolved

COPY build/filebeat-debugger /usr/share/filebeat/filebeat-debugger

Expand Down
2 changes: 1 addition & 1 deletion dev-tools/kubernetes/heartbeat/Dockerfile.debug
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/go/bin:/usr/local/go/bin

ENV CGO_ENABLED=0

RUN go install github.com/go-delve/delve/cmd/dlv@v1.21.2
RUN go install github.com/go-delve/delve/cmd/dlv@v1.23.0

COPY build/heartbeat-debugger /usr/share/heartbeat/heartbeat-debugger

Expand Down
2 changes: 1 addition & 1 deletion dev-tools/kubernetes/metricbeat/Dockerfile.debug
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/go/bin:/usr/local/go/bin

ENV CGO_ENABLED=0

RUN go install github.com/go-delve/delve/cmd/dlv@v1.21.2
RUN go install github.com/go-delve/delve/cmd/dlv@v1.23.0

COPY build/metricbeat-debugger /usr/share/metricbeat/metricbeat-debugger

Expand Down
19 changes: 14 additions & 5 deletions filebeat/_meta/test/docs/01_playground/filebeat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,24 @@ data:
logs_path: "/var/log/containers/"

# To enable hints based autodiscover, remove `filebeat.inputs` configuration and uncomment this:
#filebeat.autodiscover:
# filebeat.autodiscover:
gizas marked this conversation as resolved.
Show resolved Hide resolved
# providers:
# - type: kubernetes
# node: ${NODE_NAME}
# hints.enabled: true
# #use_kubeadm: true
# hints.default_config:
# type: container
# type: filestream
# id: kubernetes-container-logs-${data.kubernetes.pod.name}-${data.kubernetes.container.id}
# paths:
# - /var/log/containers/*${data.kubernetes.container.id}.log
# - /var/log/containers/*-${data.kubernetes.container.id}.log
# parsers:
# - container: ~
# prospector:
# scanner:
# fingerprint.enabled: true
# symlinks: true
# file_identity.fingerprint: ~
gizas marked this conversation as resolved.
Show resolved Hide resolved

processors:
- add_cloud_metadata:
Expand Down Expand Up @@ -64,12 +73,12 @@ spec:
dnsPolicy: ClusterFirstWithHostNet
containers:
- name: filebeat
image: docker.elastic.co/beats/filebeat:8.0.0-SNAPSHOT
image: docker.elastic.co/beats/filebeat:8.16.0-SNAPSHOT
command: [ "sleep" ]
args: [ "infinity" ]
env:
- name: ELASTICSEARCH_HOST
value: elasticsearch.default.svc.cluster.local
value: elasticsearch
- name: ELASTICSEARCH_PORT
value: "9200"
- name: ELASTICSEARCH_USERNAME
Expand Down
2 changes: 2 additions & 0 deletions libbeat/autodiscover/providers/kubernetes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var AllSupportedHints = []string{"enabled", "module", "metricsets", "hosts", "pe
type Config struct {
KubeConfig string `config:"kube_config"`
KubeClientOptions kubernetes.KubeClientOptions `config:"kube_client_options"`
KubeAdm bool `config:"use_kubeadm"`

Namespace string `config:"namespace"`
SyncPeriod time.Duration `config:"sync_period"`
Expand Down Expand Up @@ -71,6 +72,7 @@ var DefaultCleanupTimeout time.Duration = 0
func defaultConfig() *Config {
return &Config{
SyncPeriod: 10 * time.Minute,
KubeAdm: true,
Resource: "pod",
CleanupTimeout: DefaultCleanupTimeout,
Prefix: "co.elastic",
Expand Down
6 changes: 3 additions & 3 deletions libbeat/autodiscover/providers/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@ func NewEventerManager(
em := &eventerManager{}
switch cfg.Resource {
case "pod":
em.eventer, err = NewPodEventer(uuid, c, client, publish)
em.eventer, err = NewPodEventer(uuid, c, cfg.KubeAdm, client, publish)
case "node":
em.eventer, err = NewNodeEventer(uuid, c, client, publish)
em.eventer, err = NewNodeEventer(uuid, c, cfg.KubeAdm, client, publish)
case "service":
em.eventer, err = NewServiceEventer(uuid, c, client, publish)
em.eventer, err = NewServiceEventer(uuid, c, cfg.KubeAdm, client, publish)
default:
return nil, fmt.Errorf("unsupported autodiscover resource %s", cfg.Resource)
}
Expand Down
4 changes: 3 additions & 1 deletion libbeat/autodiscover/providers/kubernetes/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type node struct {
}

// NewNodeEventer creates an eventer that can discover and process node objects
func NewNodeEventer(uuid uuid.UUID, cfg *config.C, client k8s.Interface, publish func(event []bus.Event)) (Eventer, error) {
func NewNodeEventer(uuid uuid.UUID, cfg *config.C, kubeadm bool, client k8s.Interface, publish func(event []bus.Event)) (Eventer, error) {
logger := logp.NewLogger("autodiscover.node")

config := defaultConfig()
Expand All @@ -76,6 +76,7 @@ func NewNodeEventer(uuid uuid.UUID, cfg *config.C, client k8s.Interface, publish
}

logger.Debugf("Initializing a new Kubernetes watcher using node: %v", config.Node)
logger.Errorf("Initializing a new Kubernetes watcher using kubeadm: %v", config.KubeAdm)

watcher, err := kubernetes.NewNamedWatcher("node", client, &kubernetes.Node{}, kubernetes.WatchOptions{
SyncTimeout: config.SyncPeriod,
Expand All @@ -88,6 +89,7 @@ func NewNodeEventer(uuid uuid.UUID, cfg *config.C, client k8s.Interface, publish
return nil, fmt.Errorf("couldn't create watcher for %T due to error %w", &kubernetes.Node{}, err)
}

cfg.SetBool("use_kubeadm", -1, kubeadm)
p := &node{
config: config,
uuid: uuid,
Expand Down
5 changes: 4 additions & 1 deletion libbeat/autodiscover/providers/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type pod struct {
}

// NewPodEventer creates an eventer that can discover and process pod objects
func NewPodEventer(uuid uuid.UUID, cfg *conf.C, client k8s.Interface, publish func(event []bus.Event)) (Eventer, error) {
func NewPodEventer(uuid uuid.UUID, cfg *conf.C, kubeadm bool, client k8s.Interface, publish func(event []bus.Event)) (Eventer, error) {
logger := logp.NewLogger("autodiscover.pod")

var replicaSetWatcher, jobWatcher, namespaceWatcher, nodeWatcher kubernetes.Watcher
Expand Down Expand Up @@ -97,6 +97,9 @@ func NewPodEventer(uuid uuid.UUID, cfg *conf.C, client k8s.Interface, publish fu
}

metaConf := config.AddResourceMetadata
// We initialise the use_kubeadm variable based on modules KubeAdm base configuration
metaConf.Namespace.SetBool("use_kubeadm", -1, config.KubeAdm)
metaConf.Node.SetBool("use_kubeadm", -1, config.KubeAdm)

if metaConf.Node.Enabled() || config.Hints.Enabled() {
options := kubernetes.WatchOptions{
Expand Down
2 changes: 1 addition & 1 deletion libbeat/autodiscover/providers/kubernetes/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2203,7 +2203,7 @@ func TestPodEventer_Namespace_Node_Watcher(t *testing.T) {
err = config.Unpack(&c)
assert.NoError(t, err)

eventer, err := NewPodEventer(uuid, config, client, nil)
eventer, err := NewPodEventer(uuid, config, true, client, nil)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 5 additions & 1 deletion libbeat/autodiscover/providers/kubernetes/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type service struct {
}

// NewServiceEventer creates an eventer that can discover and process service objects
func NewServiceEventer(uuid uuid.UUID, cfg *conf.C, client k8s.Interface, publish func(event []bus.Event)) (Eventer, error) {
func NewServiceEventer(uuid uuid.UUID, cfg *conf.C, kubeadm bool, client k8s.Interface, publish func(event []bus.Event)) (Eventer, error) {
logger := logp.NewLogger("autodiscover.service")

config := defaultConfig()
Expand All @@ -71,6 +71,9 @@ func NewServiceEventer(uuid uuid.UUID, cfg *conf.C, client k8s.Interface, publis
var namespaceWatcher kubernetes.Watcher

metaConf := config.AddResourceMetadata
// We initialise the use_kubeadm variable based on modules KubeAdm base configuration
metaConf.Namespace.SetBool("use_kubeadm", -1, config.KubeAdm)
metaConf.Node.SetBool("use_kubeadm", -1, config.KubeAdm)

if metaConf.Namespace.Enabled() || config.Hints.Enabled() {
namespaceWatcher, err = kubernetes.NewNamedWatcher("namespace", client, &kubernetes.Namespace{}, kubernetes.WatchOptions{
Expand All @@ -81,6 +84,7 @@ func NewServiceEventer(uuid uuid.UUID, cfg *conf.C, client k8s.Interface, publis
if err != nil {
return nil, fmt.Errorf("couldn't create watcher for %T due to error %w", &kubernetes.Namespace{}, err)
}
metaConf.Namespace.SetBool("use_kubeadm", -1, kubeadm)
namespaceMeta = metadata.NewNamespaceMetadataGenerator(metaConf.Namespace, namespaceWatcher.Store(), client)
}

Expand Down
2 changes: 1 addition & 1 deletion libbeat/autodiscover/providers/kubernetes/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ func TestServiceEventer_NamespaceWatcher(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
config := conf.MustNewConfigFrom(&test.cfg)

eventer, err := NewServiceEventer(uuid, config, client, nil)
eventer, err := NewServiceEventer(uuid, config, true, client, nil)
if err != nil {
t.Fatal(err)
}
Expand Down
1 change: 1 addition & 0 deletions libbeat/processors/add_kubernetes_metadata/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
type kubeAnnotatorConfig struct {
KubeConfig string `config:"kube_config"`
KubeClientOptions kubernetes.KubeClientOptions `config:"kube_client_options"`
kubeAdm bool `config:"use_kubeadm"`
Node string `config:"node"`
Scope string `config:"scope"`
Namespace string `config:"namespace"`
Expand Down
10 changes: 5 additions & 5 deletions metricbeat/module/kubernetes/util/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@

// createMetadataGen creates and returns the metadata generator for resources other than pod and service
// metaGen is a struct of type Resource and implements Generate method for metadata generation for a given resource kind.
func createMetadataGen(client k8sclient.Interface, commonConfig *conf.C, addResourceMetadata *metadata.AddResourceMetadataConfig,
func createMetadataGen(client k8sclient.Interface, commonConfig *conf.C, addResourceMetadata *metadata.AddResourceMetadataConfig, kubeadm bool,
resourceName string, resourceWatchers *Watchers) (*metadata.Resource, error) {

resourceWatchers.lock.RLock()
Expand Down Expand Up @@ -492,7 +492,7 @@

// createMetadataGenSpecific creates and returns the metadata generator for a specific resource - pod or service
// A metaGen struct implements a MetaGen interface and is designed to utilize the necessary watchers to collect(Generate) metadata for a specific resource.
func createMetadataGenSpecific(client k8sclient.Interface, commonConfig *conf.C, addResourceMetadata *metadata.AddResourceMetadataConfig,
func createMetadataGenSpecific(client k8sclient.Interface, commonConfig *conf.C, addResourceMetadata *metadata.AddResourceMetadataConfig, kubeadm bool,
resourceName string, resourceWatchers *Watchers) (metadata.MetaGen, error) {

resourceWatchers.lock.RLock()
Expand Down Expand Up @@ -590,8 +590,8 @@
return &nilEnricher{}
}

var specificMetaGen metadata.MetaGen

Check failure on line 593 in metricbeat/module/kubernetes/util/kubernetes.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

specificMetaGen declared and not used (typecheck)
var generalMetaGen *metadata.Resource

Check failure on line 594 in metricbeat/module/kubernetes/util/kubernetes.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

generalMetaGen declared and not used (typecheck)
// We initialise the use_kubeadm variable based on modules KubeAdm base configuration
config.AddResourceMetadata.Namespace.SetBool("use_kubeadm", -1, commonMetaConfig.KubeAdm)
config.AddResourceMetadata.Node.SetBool("use_kubeadm", -1, commonMetaConfig.KubeAdm)
Expand All @@ -599,9 +599,9 @@
// Create the metadata generator to be used in the watcher's event handler.
// Both specificMetaGen and generalMetaGen implement Generate method for metadata collection.
if resourceName == ServiceResource || resourceName == PodResource {
specificMetaGen, err = createMetadataGenSpecific(client, commonConfig, config.AddResourceMetadata, resourceName, resourceWatchers)
specificMetaGen, err = createMetadataGenSpecific(client, commonConfig, config.AddResourceMetadata, config.KubeAdm, resourceName, resourceWatchers)
} else {
generalMetaGen, err = createMetadataGen(client, commonConfig, config.AddResourceMetadata, resourceName, resourceWatchers)
generalMetaGen, err = createMetadataGen(client, commonConfig, config.AddResourceMetadata, config.KubeAdm, resourceName, resourceWatchers)
}
if err != nil {
log.Errorf("Error trying to create the metadata generators: %s", err)
Expand Down Expand Up @@ -763,7 +763,7 @@
config.AddResourceMetadata.Namespace.SetBool("use_kubeadm", -1, commonMetaConfig.KubeAdm)
config.AddResourceMetadata.Node.SetBool("use_kubeadm", -1, commonMetaConfig.KubeAdm)

metaGen, err := createMetadataGenSpecific(client, commonConfig, config.AddResourceMetadata, PodResource, resourceWatchers)
metaGen, err := createMetadataGenSpecific(client, commonConfig, config.AddResourceMetadata, config.KubeAdm, PodResource, resourceWatchers)
if err != nil {
log.Errorf("Error trying to create the metadata generators: %s", err)
return &nilEnricher{}
Expand Down
12 changes: 6 additions & 6 deletions metricbeat/module/kubernetes/util/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func TestCreateMetaGen(t *testing.T) {
}
client := k8sfake.NewSimpleClientset()

_, err = createMetadataGen(client, commonConfig, config.AddResourceMetadata, DeploymentResource, resourceWatchers)
_, err = createMetadataGen(client, commonConfig, config.AddResourceMetadata, true, DeploymentResource, resourceWatchers)
// At this point, no watchers were created
require.Error(t, err)

Expand All @@ -253,7 +253,7 @@ func TestCreateMetaGen(t *testing.T) {
require.NoError(t, err)

// Create the generators, this time without error
_, err = createMetadataGen(client, commonConfig, config.AddResourceMetadata, DeploymentResource, resourceWatchers)
_, err = createMetadataGen(client, commonConfig, config.AddResourceMetadata, true, DeploymentResource, resourceWatchers)
require.NoError(t, err)
}

Expand Down Expand Up @@ -286,19 +286,19 @@ func TestCreateMetaGenSpecific(t *testing.T) {
// For pod:
metricsetPod := "pod"

_, err = createMetadataGenSpecific(client, commonConfig, config.AddResourceMetadata, PodResource, resourceWatchers)
_, err = createMetadataGenSpecific(client, commonConfig, config.AddResourceMetadata, true, PodResource, resourceWatchers)
// At this point, no watchers were created
require.Error(t, err)

// Create the pod resource + the extras
err = createAllWatchers(client, metricsetPod, PodResource, false, config, log, resourceWatchers)
require.NoError(t, err)

_, err = createMetadataGenSpecific(client, commonConfig, config.AddResourceMetadata, PodResource, resourceWatchers)
_, err = createMetadataGenSpecific(client, commonConfig, config.AddResourceMetadata, true, PodResource, resourceWatchers)
require.NoError(t, err)

// For service:
_, err = createMetadataGenSpecific(client, commonConfig, config.AddResourceMetadata, ServiceResource, resourceWatchers)
_, err = createMetadataGenSpecific(client, commonConfig, config.AddResourceMetadata, true, ServiceResource, resourceWatchers)
// At this point, no watchers were created
require.Error(t, err)

Expand All @@ -307,7 +307,7 @@ func TestCreateMetaGenSpecific(t *testing.T) {
err = createAllWatchers(client, metricsetService, ServiceResource, false, config, log, resourceWatchers)
require.NoError(t, err)

_, err = createMetadataGenSpecific(client, commonConfig, config.AddResourceMetadata, ServiceResource, resourceWatchers)
_, err = createMetadataGenSpecific(client, commonConfig, config.AddResourceMetadata, true, ServiceResource, resourceWatchers)
require.NoError(t, err)
}

Expand Down
Loading