Skip to content

Add nomad processor#14500

Closed
jorgemarey wants to merge 12 commits intoelastic:masterfrom
jorgemarey:feature/nomad
Closed

Add nomad processor#14500
jorgemarey wants to merge 12 commits intoelastic:masterfrom
jorgemarey:feature/nomad

Conversation

@jorgemarey
Copy link
Copy Markdown

@jorgemarey jorgemarey commented Nov 13, 2019

This adds a nomad proccessor that annotates the logs with properties. Adds the following to each log:

  • region
  • namespace
  • dc
  • job
  • group
  • allocation
  • task
  • alloc_index
  • stream (stderr / stdour)
  • meta (those that start with a defined prefix)

The following is a configuration example:

filebeat.inputs:
- type: log
  paths:
    - /opt/nomad/alloc/*/alloc/logs/*
  exclude_files: ['\.fifo$']

processors:
- add_nomad_metadata:
    when:
      regexp:
        log.file.path: "/opt/nomad/alloc/.*"

The tests are missing. I'm working on them (I decided to do the PR first to do the needed changes for this to be aproved).

@elasticmachine
Copy link
Copy Markdown
Contributor

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

1 similar comment
@elasticmachine
Copy link
Copy Markdown
Contributor

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@kvch kvch added :Processors in progress Pull request is currently in progress. libbeat review labels Nov 15, 2019
Previously DefaultConfig() was not being called so default environment
vaiables weren't used.
This also renames the library import from nomadbeat to nomadlib.
return nil, err
}

go watcher.Start()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Which function calls watcher.Stop? How do you make sure that the goroutine is stopped when it has to?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It's not called anywhere. I tried to find a way to call this, but the Processor interface only defines the Run and String methods. Anyway, in filebeat, the processor is defined on the configuration and applied until the program is stopped, so watcher.Stop would only be called at the end of the program, and in that case the program will exit, so no need to clean goroutines.

I was looking at other processors (docker, k8s) and the Stop functions of them are not called on the provider.

What should I do here?

@kvch
Copy link
Copy Markdown
Contributor

kvch commented Nov 19, 2019

Great addition, thank you! I added a few more questions to the PR. Could you please provide documentation or at least a description for the processors so we can add documentation for the processors?
Also, ping me when you are ready with the tests.

@kvch
Copy link
Copy Markdown
Contributor

kvch commented Nov 19, 2019

I have run make crosscompile in the root of Filebeat. Unfortunately, I am getting the following errors:

n@sleipnir ~/go/src/github.com/elastic/beats/filebeat                                                                                               [15:56:40]
> $ make crosscompile                                                                                                             ⬡ 10.14.1 [±feature/nomad ✓]
go get github.com/mitchellh/gox
mkdir -p /home/n/go/src/github.com/elastic/beats/filebeat/build/bin
gox -output="/home/n/go/src/github.com/elastic/beats/filebeat/build/bin/{{.Dir}}-{{.OS}}-{{.Arch}}" -os="linux darwin windows freebsd netbsd openbsd" -osarch="!darwin/arm !darwin/arm64 !darwin/386" -arch="amd64 386 arm ppc64 ppc64le"
Number of parallel builds: 3

-->     openbsd/386: github.com/elastic/beats/filebeat
-->     linux/ppc64: github.com/elastic/beats/filebeat
-->     windows/386: github.com/elastic/beats/filebeat
-->    netbsd/amd64: github.com/elastic/beats/filebeat
-->   freebsd/amd64: github.com/elastic/beats/filebeat
-->     freebsd/386: github.com/elastic/beats/filebeat
-->     freebsd/arm: github.com/elastic/beats/filebeat
-->    darwin/amd64: github.com/elastic/beats/filebeat
-->   linux/ppc64le: github.com/elastic/beats/filebeat
-->   windows/amd64: github.com/elastic/beats/filebeat
-->      netbsd/arm: github.com/elastic/beats/filebeat
-->      netbsd/386: github.com/elastic/beats/filebeat
-->       linux/386: github.com/elastic/beats/filebeat
-->     linux/amd64: github.com/elastic/beats/filebeat
-->       linux/arm: github.com/elastic/beats/filebeat
-->   openbsd/amd64: github.com/elastic/beats/filebeat

8 errors occurred:
--> openbsd/386 error: exit status 1
Stderr: ../libbeat/processors/add_nomad_metadata/nomad.go:28:2: build constraints exclude all Go files in /home/n/go/src/github.com/elastic/beats/libbeat/common/nomad

--> netbsd/amd64 error: exit status 1
Stderr: ../libbeat/processors/add_nomad_metadata/nomad.go:28:2: build constraints exclude all Go files in /home/n/go/src/github.com/elastic/beats/libbeat/common/nomad

--> freebsd/amd64 error: exit status 1
Stderr: ../libbeat/processors/add_nomad_metadata/nomad.go:28:2: build constraints exclude all Go files in /home/n/go/src/github.com/elastic/beats/libbeat/common/nomad

--> freebsd/386 error: exit status 1
Stderr: ../libbeat/processors/add_nomad_metadata/nomad.go:28:2: build constraints exclude all Go files in /home/n/go/src/github.com/elastic/beats/libbeat/common/nomad

--> freebsd/arm error: exit status 1
Stderr: ../libbeat/processors/add_nomad_metadata/nomad.go:28:2: build constraints exclude all Go files in /home/n/go/src/github.com/elastic/beats/libbeat/common/nomad

--> netbsd/arm error: exit status 1
Stderr: ../libbeat/processors/add_nomad_metadata/nomad.go:28:2: build constraints exclude all Go files in /home/n/go/src/github.com/elastic/beats/libbeat/common/nomad

--> netbsd/386 error: exit status 1
Stderr: ../libbeat/processors/add_nomad_metadata/nomad.go:28:2: build constraints exclude all Go files in /home/n/go/src/github.com/elastic/beats/libbeat/common/nomad

--> openbsd/amd64 error: exit status 1
Stderr: ../libbeat/processors/add_nomad_metadata/nomad.go:28:2: build constraints exclude all Go files in /home/n/go/src/github.com/elastic/beats/libbeat/common/nomad

../libbeat/scripts/Makefile:118: recipe for target 'crosscompile' failed
make: *** [crosscompile] Error 1

Could you please resolve this issue? I assume you need to adjust the build tags.

Copy link
Copy Markdown
Author

@jorgemarey jorgemarey left a comment

Choose a reason for hiding this comment

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

I changed the build tags to fix the compiling problems.
I'm working on the tests. Sorry for the delay, I'm a little busy this days.
Where should I add the documentation?

@kvch
Copy link
Copy Markdown
Contributor

kvch commented Nov 26, 2019

Documentation should be added to the docs folder of the processor: libbeat/processors/add_nomad_metadata/docs and named as add_nomad_metadata.asciidoc. Then add a reference to it to the file libbeat/docs/processors-list.asciidoc. See the doc of add_docker_metadata: https://github.com/elastic/beats/blob/master/libbeat/processors/add_docker_metadata/docs/add_docker_metadata.asciidoc

@kvch kvch self-assigned this Nov 26, 2019
jsprocessor.RegisterPlugin("AddNomadMetadata", New)
}

// New constructs a new add_kubernetes_metadata processor.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please correct the comment.

@@ -0,0 +1,79 @@
[[add-nomad-metadata]]
=== Add Nomad metadata
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please also mark the docs beta by adding the following line:

beta[]

Copy link
Copy Markdown
Contributor

@kvch kvch left a comment

Choose a reason for hiding this comment

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

LGTM, waiting for marking it beta.

@@ -0,0 +1 @@
package add_nomad_metadata
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

don't use an underscore in package name

@kvch kvch added Team:Integrations Label for the Integrations team and removed Team:Beats labels Dec 16, 2019
@kvch
Copy link
Copy Markdown
Contributor

kvch commented Dec 16, 2019

Handing it over to @elastic/integrations

@kvch kvch removed their assignment Dec 23, 2019
@andresrc andresrc added Team:Platforms Label for the Integrations - Platforms team [zube]: In Progress and removed libbeat [zube]: Inbox labels Feb 5, 2020
@jsoriano jsoriano mentioned this pull request Mar 5, 2020
7 tasks
@jsoriano jsoriano mentioned this pull request Mar 20, 2020
4 tasks
@jsoriano
Copy link
Copy Markdown
Member

Hey @jorgemarey, thanks a lot for your efforts, they are very appreciated, and sorry for the delay giving feedback!

As commented in #16853, let's put this PR on hold by now and let's try to move #14954 forward. #14954 includes a nomad processor, but also an autodiscover provider.
I think that in any case there are good ideas here that could be added to #14954, so it would be great if you have some time to take a look there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in progress Pull request is currently in progress. needs_docs :Processors review Team:Integrations Label for the Integrations team Team:Platforms Label for the Integrations - Platforms team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants