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 10 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ you can achieve this by overwriting the value using an `add_fields` processor. {
version of Elastic Agent as their own version. This includes all additional
fields added to events containing the Beats version. {pull}37553[37553]
- The behavior of `queue.mem.flush.min_events` has been simplified. It now serves as a simple maximum on the size of all event batches. There are no longer performance implications in its relationship to `bulk_max_size`. {pull}37795[37795]
- Introduce log message for not supported annotations for Hints based autodiscover {pull}38213[38213]

*Auditbeat*

Expand Down
4 changes: 2 additions & 2 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12313,11 +12313,11 @@ various licenses:

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

Contents of probable licence file $GOMODCACHE/github.com/elastic/[email protected].7/LICENSE:
Contents of probable licence file $GOMODCACHE/github.com/elastic/[email protected].9/LICENSE:

Apache License
Version 2.0, January 2004
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
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.4.0
github.com/elastic/elastic-agent-autodiscover v0.6.7
github.com/elastic/elastic-agent-autodiscover v0.6.9
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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,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.4.0 h1:M80eAeJnzvGQgU9cjJqkjFca9pjM3aq/TuZxJeom4bI=
github.com/elastic/ebpfevents v0.4.0/go.mod h1:o21z5xup/9dK8u0Hg9bZRflSqqj1Zu5h2dg2hSTcUPQ=
github.com/elastic/elastic-agent-autodiscover v0.6.7 h1:+KVjltN0rPsBrU8b156gV4lOTBgG/vt0efFCFARrf3g=
github.com/elastic/elastic-agent-autodiscover v0.6.7/go.mod h1:hFeFqneS2r4jD0/QzGkrNk0YVdN0JGh7lCWdsH7zcI4=
github.com/elastic/elastic-agent-autodiscover v0.6.9 h1:F2BeSia5cM0q2NNVXTA3OSrVK0ayPohDQcOhZo514Hc=
github.com/elastic/elastic-agent-autodiscover v0.6.9/go.mod h1:hFeFqneS2r4jD0/QzGkrNk0YVdN0JGh7lCWdsH7zcI4=
github.com/elastic/elastic-agent-client/v7 v7.8.0 h1:GHFzDJIWpdgI0qDk5EcqbQJGvwTsl2E2vQK3/xe+MYQ=
github.com/elastic/elastic-agent-client/v7 v7.8.0/go.mod h1:ihtjqJzYiIltlRhNruaSSc0ogxIhqPD5hOMKq16cI1s=
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
Original file line number Diff line number Diff line change
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
2 changes: 2 additions & 0 deletions libbeat/autodiscover/providers/kubernetes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"github.com/elastic/elastic-agent-libs/logp"
)

var AllSupportedHints = []string{"enabled", "module", "metricsets", "host", "period", "timeout", "metricspath", "username", "password", "stream", "processors", "multiline", "json", "disable", "ssl", "metrics_filters", "raw", "include_lines", "exclude_lines", "fileset", "pipeline"}
Copy link
Contributor

Choose a reason for hiding this comment

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

does metricspath actually works? shouldn't it be metrics_path based on https://www.elastic.co/guide/en/beats/metricbeat/current/configuration-autodiscover-hints.html#_co_elastic_metricsmetrics_path ?

where disable is coming from?

Also as I understand it is a merged list for the metricbeat and for the filebeat, correct? can you please add a comment for that? Is there any way to split it?

Copy link
Contributor Author

@gizas gizas Mar 13, 2024

Choose a reason for hiding this comment

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

I changed metricspath to metrics_path ! Nice catch, thanks Tania!

Disable comes from this: https://github.com/elastic/elastic-agent-autodiscover/blob/7490558445cb8d3248462255edc8ac64bc18b8eb/utils/hints_test.go#L177
We can disable logs collection apparently

I have added a comment in 7d2c429

Currently we parse annotations based on the fact that start with the prefix (L209) and then we split with "/" symbol (L215)
So currently this is a unified solution for elastic-agent and beats. I deliberately had moved the solution to the elastic-agent-autodiscovery in oder not to introduce an additional annotation loop and different implementations. So splitting it for beats will require additional checks if we have Prefix.logs or Prefix.metrics. I consider it out of scope here, mainly because the main reason behind those changes, is to offer the feature in elastic-agent and not in beats. Hope it makes sense


// Config for kubernetes autodiscover provider
type Config struct {
KubeConfig string `config:"kube_config"`
Expand Down Expand Up @@ -57,7 +59,7 @@
AddResourceMetadata *metadata.AddResourceMetadataConfig `config:"add_resource_metadata"`
}

// Public variable, so specific beats (as Filebeat) can set a different cleanup timeout if they need it.

Check failure on line 62 in libbeat/autodiscover/providers/kubernetes/config.go

View workflow job for this annotation

GitHub Actions / lint (windows)

ST1022: comment on exported var DefaultCleanupTimeout should be of the form "DefaultCleanupTimeout ..." (stylecheck)
var DefaultCleanupTimeout time.Duration = 0

func defaultConfig() *Config {
Expand Down
8 changes: 7 additions & 1 deletion libbeat/autodiscover/providers/kubernetes/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ 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
if len(incorrecthints) > 0 {
for _, value := range incorrecthints {
n.logger.Warnf("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
8 changes: 7 additions & 1 deletion libbeat/autodiscover/providers/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,13 @@ 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
if len(incorrecthints) > 0 {
for _, value := range incorrecthints {
p.logger.Warnf("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
11 changes: 9 additions & 2 deletions libbeat/autodiscover/providers/kubernetes/pod_test.go
Original file line number Diff line number Diff line change
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/timeouts": "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/timeouts": "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 Down
8 changes: 7 additions & 1 deletion libbeat/autodiscover/providers/kubernetes/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@
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
if len(incorrecthints) > 0 {
for _, value := range incorrecthints {
s.logger.Warnf("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 +226,7 @@
}
}

var events []bus.Event

Check failure on line 229 in libbeat/autodiscover/providers/kubernetes/service.go

View workflow job for this annotation

GitHub Actions / lint (windows)

Consider pre-allocating `events` (prealloc)
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

for _, port := range svc.Spec.Ports {
event := bus.Event{
"provider": s.uuid,
Expand Down
4 changes: 4 additions & 0 deletions metricbeat/module/kubernetes/util/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ type mockWatcher struct {
started bool
}

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

func (m *mockWatcher) Start() error {
m.started = true
return nil
Expand Down
2 changes: 1 addition & 1 deletion x-pack/libbeat/autodiscover/providers/nomad/nomad.go
Original file line number Diff line number Diff line change
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
Loading