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

[Beats] Adding support for elastic-agent-autodiscovery v0.6.13 Introduce log message for not supported annotations #38213

Merged
merged 46 commits into from Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
6dba856
adding support for logshints and autodiscovery 0.6.9
gizas Mar 7, 2024
39b32e9
fixing test errors
gizas Mar 8, 2024
8c08dff
fixing test errors
gizas Mar 8, 2024
51728af
adding changelog
gizas Mar 8, 2024
4009d15
Merge branch 'main' into logshints
gizas Mar 8, 2024
6985610
updating go.mod with v0.6.9 autodiscovery library
gizas Mar 13, 2024
e023e50
Merge branch 'main' into logshints
gizas Mar 13, 2024
4661676
Merge branch 'logshints' of github.com:elastic/beats into logshints
gizas Mar 13, 2024
3e1e1fb
updating Notice.txt
gizas Mar 13, 2024
edb7c3a
Merge branch 'main' into logshints
gizas Mar 13, 2024
3542df5
Merge branch 'main' into logshints
gizas Mar 13, 2024
7d2c429
updating AllSupportedHints list
gizas Mar 13, 2024
0e00df6
correcting changelog for v0.6.12
gizas Apr 15, 2024
382ef5f
correcting changelog
gizas Apr 15, 2024
24b07fb
correcting ebpfevent in go.mod
gizas Apr 15, 2024
9a5ad55
correcting ebpfevent in go.mod
gizas Apr 15, 2024
bce8fc7
correcting test failures
gizas Apr 15, 2024
9decff6
correcting events prealloc lint error
gizas Apr 15, 2024
e161254
Merge branch 'main' into logshints
gizas Apr 16, 2024
0a40b85
updating to elastic-agent-autodiscovery v.0.6.13
gizas Apr 22, 2024
2e6ad5f
Merge branch 'logshints' of github.com:elastic/beats into logshints
gizas Apr 22, 2024
142f1ac
Merge branch 'main' of github.com:elastic/beats into logshints
gizas Apr 22, 2024
dbd20e5
updating Changelog and placing PR description in correct section
gizas Apr 22, 2024
2d19a40
Merge branch 'main' into logshints
gizas Apr 22, 2024
1c10c37
Merge branch 'main' into logshints
gizas Apr 22, 2024
55451c6
fixing hint hosts
gizas Apr 23, 2024
e159e75
Merge branch 'logshints' of github.com:elastic/beats into logshints
gizas Apr 23, 2024
097b7ea
Update libbeat/autodiscover/providers/kubernetes/node.go
gizas Apr 24, 2024
08f3c60
Update libbeat/autodiscover/providers/kubernetes/pod.go
gizas Apr 24, 2024
bf441cf
Update libbeat/autodiscover/providers/kubernetes/service.go
gizas Apr 24, 2024
92c266b
adding support for docker
gizas Apr 24, 2024
05d71ef
Merge branch 'logshints' of github.com:elastic/beats into logshints
gizas Apr 24, 2024
95f30aa
Merge branch 'main' into logshints
gizas Apr 24, 2024
ea50b00
fixing linting error
gizas Apr 24, 2024
f3b6f21
adding comment to skip validation error of test
gizas Apr 24, 2024
58da62a
Merge branch 'main' into logshints
gizas Apr 24, 2024
e3ca45d
fixing conflicts
gizas Apr 24, 2024
6e282d0
Merge branch 'logshints' of github.com:elastic/beats into logshints
gizas Apr 24, 2024
e0c255d
fixing conflicts
gizas Apr 24, 2024
8ae7814
Merge branch 'main' into logshints
rdner Apr 24, 2024
58f476f
Merge branch 'main' into logshints
gizas Apr 25, 2024
63131b2
fixing conflicts
gizas Apr 25, 2024
14815b2
fixing conflicts with go.sum
gizas Apr 25, 2024
7954069
fixing conflicts with go.sum
gizas Apr 25, 2024
7bfd450
fixing conflicts with go.sum
gizas Apr 25, 2024
7b5a9bb
Merge branch 'main' into logshints
gizas Apr 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.next.asciidoc
Expand Up @@ -9,6 +9,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
==== Breaking changes

*Affecting all Beats*
- Introduce log message for not supported annotations for Hints based autodiscover {pull}38213[38213]
gizas marked this conversation as resolved.
Show resolved Hide resolved


*Auditbeat*
Expand Down Expand Up @@ -368,6 +369,5 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]






8 changes: 4 additions & 4 deletions NOTICE.txt
Expand Up @@ -11088,11 +11088,11 @@ third-party archives.

--------------------------------------------------------------------------------
Dependency : github.com/docker/docker
Version: v24.0.7+incompatible
Version: v24.0.9+incompatible
Licence type (autodetected): Apache-2.0
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/docker/docker@v24.0.7+incompatible/LICENSE:
Contents of probable licence file $GOMODCACHE/github.com/docker/docker@v24.0.9+incompatible/LICENSE:


Apache License
Expand Down Expand Up @@ -12313,11 +12313,11 @@ various licenses:

--------------------------------------------------------------------------------
Dependency : github.com/elastic/elastic-agent-autodiscover
Version: v0.6.8
Version: v0.6.12
Licence type (autodetected): Apache-2.0
--------------------------------------------------------------------------------

Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-autodiscover@v0.6.8/LICENSE:
Contents of probable licence file $GOMODCACHE/github.com/elastic/elastic-agent-autodiscover@v0.6.12/LICENSE:

Apache License
Version 2.0, January 2004
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Expand Up @@ -59,7 +59,7 @@ require (
github.com/devigned/tab v0.1.2-0.20190607222403-0c15cf42f9a2 // indirect
github.com/dgraph-io/badger/v3 v3.2103.1
github.com/digitalocean/go-libvirt v0.0.0-20180301200012-6075ea3c39a1
github.com/docker/docker v24.0.7+incompatible
github.com/docker/docker v24.0.9+incompatible
github.com/docker/go-connections v0.4.0
github.com/docker/go-plugins-helpers v0.0.0-20181025120712-1e6269c305b8
github.com/docker/go-units v0.5.0
Expand Down Expand Up @@ -202,7 +202,7 @@ require (
github.com/awslabs/kinesis-aggregation/go/v2 v2.0.0-20220623125934-28468a6701b5
github.com/elastic/bayeux v1.0.5
github.com/elastic/ebpfevents v0.6.0
github.com/elastic/elastic-agent-autodiscover v0.6.8
github.com/elastic/elastic-agent-autodiscover v0.6.12
github.com/elastic/elastic-agent-libs v0.7.5
github.com/elastic/elastic-agent-shipper-client v0.5.1-0.20230228231646-f04347b666f3
github.com/elastic/elastic-agent-system-metrics v0.9.2
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Expand Up @@ -629,8 +629,8 @@ github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4Kfc
github.com/docker/docker v1.4.2-0.20170802015333-8af4db6f002a/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v1.4.2-0.20190924003213-a8608b5b67c7/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v20.10.7+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v24.0.7+incompatible h1:Wo6l37AuwP3JaMnZa226lzVXGA3F9Ig1seQen0cKYlM=
github.com/docker/docker v24.0.7+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v24.0.9+incompatible h1:HPGzNmwfLZWdxHqK9/II92pyi1EpYKsAqcl4G0Of9v0=
github.com/docker/docker v24.0.9+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker-credential-helpers v0.6.3/go.mod h1:WRaJzqw3CTB9bk10avuGsjVBZsD05qeibJ1/TYlvc0Y=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
Expand Down Expand Up @@ -674,8 +674,8 @@ github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3 h1:lnDkqiRFKm0rxdljqr
github.com/elastic/dhcp v0.0.0-20200227161230-57ec251c7eb3/go.mod h1:aPqzac6AYkipvp4hufTyMj5PDIphF3+At8zr7r51xjY=
github.com/elastic/ebpfevents v0.6.0 h1:BrL3m7JFK7U6h2jkbk3xAWWs//IZnugCHEDds5u2v68=
github.com/elastic/ebpfevents v0.6.0/go.mod h1:ESG9gw7N+n5yCCMgdg1IIJENKWSmX7+X0Fi9GUs9nvU=
github.com/elastic/elastic-agent-autodiscover v0.6.8 h1:BSXz+QwjZAEt08G+T3GDGl14Bh9a6zD8luNCvZut/b8=
github.com/elastic/elastic-agent-autodiscover v0.6.8/go.mod h1:hFeFqneS2r4jD0/QzGkrNk0YVdN0JGh7lCWdsH7zcI4=
github.com/elastic/elastic-agent-autodiscover v0.6.12 h1:tAKM7ImtMA+mKFrjVfAi4M1pTBvb+8EZSTaOF0RxQaA=
github.com/elastic/elastic-agent-autodiscover v0.6.12/go.mod h1:7P6YVKxuBT0qE/VxuA87obwZUAEU0O44mCN3r4/6x8w=
github.com/elastic/elastic-agent-client/v7 v7.8.1 h1:J9wZc/0mUvSEok0X5iR5+n60Jgb+AWooKddb3XgPWqM=
github.com/elastic/elastic-agent-client/v7 v7.8.1/go.mod h1:axl1nkdqc84YRFkeJGD9jExKNPUrOrzf3DFo2m653nY=
github.com/elastic/elastic-agent-libs v0.7.5 h1:4UMqB3BREvhwecYTs/L23oQp1hs/XUkcunPlmTZn5yg=
Expand Down
2 changes: 1 addition & 1 deletion libbeat/autodiscover/providers/docker/docker.go
Expand Up @@ -383,7 +383,7 @@ func (d *Provider) generateHints(event bus.Event) bus.Event {
e["ports"] = ports
}
if labels, err := dockerMeta.GetValue("labels"); err == nil {
hints := utils.GenerateHints(labels.(mapstr.M), "", d.config.Prefix)
hints, _ := utils.GenerateHints(labels.(mapstr.M), "", d.config.Prefix, []string{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't know we call GenerateHints here. Looking on this use case, wondering if it wouldn't be a better option to introduce additionally smth like GenerateHintsWithValidation instead - maybe we should consider it in future for cases when signature is changed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here GenerateHints will actually return all hints as incorrect but we just ignore them. I think we should make it more clear. Maybe add a bool (validate), which is then checked in GenerateHints

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e["hints"] = hints
}
return e
Expand Down
3 changes: 3 additions & 0 deletions libbeat/autodiscover/providers/kubernetes/config.go
Expand Up @@ -30,6 +30,9 @@ import (
"github.com/elastic/elastic-agent-libs/logp"
)

// AllSupportedHints includes the set of all supported hints for both logs and metrics autodiscovery
var AllSupportedHints = []string{"enabled", "module", "metricsets", "host", "period", "timeout", "metrics_path", "username", "password", "stream", "processors", "multiline", "json", "disable", "ssl", "metrics_filters", "raw", "include_lines", "exclude_lines", "fileset", "pipeline", "raw"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated in 55451c6 and also added some test


// Config for kubernetes autodiscover provider
type Config struct {
KubeConfig string `config:"kube_config"`
Expand Down
6 changes: 5 additions & 1 deletion libbeat/autodiscover/providers/kubernetes/node.go
Expand Up @@ -153,7 +153,11 @@ func (n *node) GenerateHints(event bus.Event) bus.Event {
e["port"] = port
}

hints := utils.GenerateHints(annotations, "", n.config.Prefix)
hints, incorrecthints := utils.GenerateHints(annotations, "", n.config.Prefix, AllSupportedHints)
//We check whether the provided annotation follows the supported format and vocabulary. The check happens for annotations that have prefix co.elastic
gizas marked this conversation as resolved.
Show resolved Hide resolved
for _, value := range incorrecthints {
n.logger.Debugf("provided hint: %s/%s is not in the supported list", n.config.Prefix, value)
}
n.logger.Debugf("Generated hints %+v", hints)
if len(hints) != 0 {
e["hints"] = hints
Expand Down
6 changes: 5 additions & 1 deletion libbeat/autodiscover/providers/kubernetes/pod.go
Expand Up @@ -246,7 +246,11 @@ func (p *pod) GenerateHints(event bus.Event) bus.Event {
cname := utils.GetContainerName(container)

// Generate hints based on the cumulative of both namespace and pod annotations.
hints := utils.GenerateHints(annotations, cname, p.config.Prefix)
hints, incorrecthints := utils.GenerateHints(annotations, cname, p.config.Prefix, AllSupportedHints)
//We check whether the provided annotation follows the supported format and vocabulary. The check happens for annotations that have prefix co.elastic
gizas marked this conversation as resolved.
Show resolved Hide resolved
for _, value := range incorrecthints {
p.logger.Debugf("provided hint: %s/%s is not in the supported list", p.config.Prefix, value)
}
p.logger.Debugf("Generated hints %+v", hints)

if len(hints) != 0 {
Expand Down
15 changes: 9 additions & 6 deletions libbeat/autodiscover/providers/kubernetes/pod_test.go
Expand Up @@ -108,6 +108,7 @@ func TestGenerateHints(t *testing.T) {
"co.elastic.logs/multiline.pattern": "^test",
"co.elastic.logs/json.keys_under_root": "true",
"co.elastic.metrics/module": "prometheus",
"co.elastic.metrics/timeoutssssssss": "5s", //On purpose we added this annotation with typo
"co.elastic.metrics/period": "10s",
"co.elastic.metrics.foobar/period": "15s",
"not.to.include": "true",
Expand All @@ -125,6 +126,7 @@ func TestGenerateHints(t *testing.T) {
"co.elastic.logs/multiline.pattern": "^test",
"co.elastic.logs/json.keys_under_root": "true",
"co.elastic.metrics/module": "prometheus",
"co.elastic.metrics/timeoutssssssss": "5s",
"not.to.include": "true",
"co.elastic.metrics/period": "10s",
"co.elastic.metrics.foobar/period": "15s",
Expand All @@ -145,8 +147,9 @@ func TestGenerateHints(t *testing.T) {
},
},
"metrics": mapstr.M{
"module": "prometheus",
"period": "15s",
"module": "prometheus",
"period": "15s",
"timeouts": "5s",
},
},
"container": mapstr.M{
Expand Down Expand Up @@ -2140,6 +2143,10 @@ func (s *mockUpdaterWatcher) Start() error {
return err
}

func (s *mockUpdaterWatcher) GetEventHandler() kubernetes.ResourceEventHandler {
return nil
}

func (s *mockUpdaterWatcher) Stop() {
}

Expand All @@ -2150,10 +2157,6 @@ func (s *mockUpdaterWatcher) Store() caches.Store {
func (s *mockUpdaterWatcher) AddEventHandler(kubernetes.ResourceEventHandler) {
}

func (s *mockUpdaterWatcher) GetEventHandler() kubernetes.ResourceEventHandler {
return nil
}

func (s *mockUpdaterStore) List() []interface{} {
return s.objects
}
Expand Down
8 changes: 6 additions & 2 deletions libbeat/autodiscover/providers/kubernetes/service.go
Expand Up @@ -155,7 +155,11 @@ func (s *service) GenerateHints(event bus.Event) bus.Event {
e["port"] = port
}

hints := utils.GenerateHints(annotations, "", s.config.Prefix)
hints, incorrecthints := utils.GenerateHints(annotations, "", s.config.Prefix, AllSupportedHints)
//We check whether the provided annotation follows the supported format and vocabulary. The check happens for annotations that have prefix co.elastic
gizas marked this conversation as resolved.
Show resolved Hide resolved
for _, value := range incorrecthints {
s.logger.Debugf("provided hint: %s/%s is not in the supported list", s.config.Prefix, value)
}
s.logger.Debugf("Generated hints %+v", hints)

if len(hints) != 0 {
Expand Down Expand Up @@ -220,7 +224,7 @@ func (s *service) emit(svc *kubernetes.Service, flag string) {
}
}

var events []bus.Event
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was done in order to remove:
Consider pre-allocating events (prealloc) lint error

events := []bus.Event{}
for _, port := range svc.Spec.Ports {
event := bus.Event{
"provider": s.uuid,
Expand Down
8 changes: 4 additions & 4 deletions metricbeat/module/kubernetes/util/kubernetes_test.go
Expand Up @@ -706,6 +706,10 @@ type mockWatcher struct {
handler kubernetes.ResourceEventHandler
}

func (m *mockWatcher) GetEventHandler() kubernetes.ResourceEventHandler {
return m.handler
}

func (m *mockWatcher) Start() error {
return nil
}
Expand All @@ -718,10 +722,6 @@ func (m *mockWatcher) AddEventHandler(r kubernetes.ResourceEventHandler) {
m.handler = r
}

func (m *mockWatcher) GetEventHandler() kubernetes.ResourceEventHandler {
return m.handler
}

func (m *mockWatcher) Store() cache.Store {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/libbeat/autodiscover/providers/nomad/nomad.go
Expand Up @@ -277,7 +277,7 @@ func (p *Provider) generateHints(event bus.Event) bus.Event {
}

cname := utils.GetContainerName(container)
hints := utils.GenerateHints(tasks, cname, p.config.Prefix)
hints, _ := utils.GenerateHints(tasks, cname, p.config.Prefix, []string{})
if len(hints) > 0 {
e["hints"] = hints
}
Expand Down