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

support multiple configurations per collector #441

Merged
merged 20 commits into from
Sep 14, 2022
Merged

Conversation

mpfz0r
Copy link
Contributor

@mpfz0r mpfz0r commented Sep 1, 2022

This PR contains 3 changes.

1. Refactor the sidecar so it can handle more than one configuration per backend.

The sidecar has three different global "stores" where it keeps the current state:

  • backends (aka collectors)
  • assignments
  • daemon / runner

All of these stores are currently tied together with the collector id.
If we want to support multiple instances of one collector, we need to use a unique ID for this.
The obvious choice is to build an ID out of the collector and the configuration ID. (collector_id-configuration_id)

An assignment like:

     [
       { "collector_id": "1234", "configuration_id": "aaa" },
       { "collector_id": "1234", "configuration_id": "bbb" },
       { "collector_id": "5678", "configuration_id": "eee" }
     ]

Will create 3 backends:
1234-aaa, 1234-bbb, 5678-eee

2. Report the collector_configuration_directory back to Graylog

This allows Graylog to create a sidecar config variable
${sidecar.spoolDir} would expand to sth like /var/lib/graylog-sidecar/generated/62864e0056caeb4862bf016b/

To make this backwards compatible with older Graylog servers that won't accept additional
NodeDetail fields in the API. (:roll_eyes:) we need to add a version check, and only send this to servers that support it.

3. Backwards compatible collector status.

The status of each collector was reported back to Graylog by using the collector_id.
Additionally, we will now report this with the assigned configuration_id.
But only to Graylog > 4.3

Refs https://github.com/Graylog2/graylog-plugin-enterprise/issues/3956

mpfz0r added 10 commits August 24, 2022 19:03
This enables us to use the same backend with multiple
configurations
Expand each assignment and backend into a unique ID
that combines the backendID + configID

Most of the stores us a map with this Id that holds
everything together.
Multiple configs can still be assigned by using multiple assignments.
E.g.:
 [
   { "collector-1": "config-A" },
   { "collector-1": "config-B" }
 ]
This will be used to create the ${sidecar.spoolDir} config variable.
Older Graylog servers will refuse unknown NodeDetails attributes

Also update go module to version 1.19
If we are talking to an older Graylog instance,
report the collectors with just the collector ID.

Refactor version handling into separate type
Speeds up testing the sidecar
@mpfz0r mpfz0r changed the title Multi backend support support multiple configurations per collector Sep 8, 2022
@mpfz0r mpfz0r marked this pull request as ready for review September 8, 2022 08:36
@mpfz0r mpfz0r requested a review from thll September 8, 2022 08:36
@mpfz0r mpfz0r self-assigned this Sep 8, 2022
@thll thll assigned thll and unassigned mpfz0r Sep 8, 2022
Copy link
Contributor

@thll thll left a comment

Choose a reason for hiding this comment

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

First round of review. I'd like to look into it some more. Only did a smoke test with a server version <4.4 to see if we are still compatible. Got the following error when un-assigning a configuration from a collector in the UI:

DEBU[0045] Cleaning up backend: filebeat-6246ef72b8dc9c6bba59bf89 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x132c354]

goroutine 19 [running]:
github.com/Graylog2/collector-sidecar/daemon.(*DaemonConfig).SyncWithAssignments(0xc000138240, 0xc00013ea00)
        /Users/thll/go/src/github.com/Graylog2/collector-sidecar/daemon/daemon.go:146 +0x5f4
github.com/Graylog2/collector-sidecar/services.StartPeriodicals.func1()
        /Users/thll/go/src/github.com/Graylog2/collector-sidecar/services/periodicals.go:93 +0x773
created by github.com/Graylog2/collector-sidecar/services.StartPeriodicals
        /Users/thll/go/src/github.com/Graylog2/collector-sidecar/services/periodicals.go:40 +0xae
Exiting.

Debugger finished with the exit code 0

api/version.go Outdated Show resolved Hide resolved
api/graylog.go Outdated Show resolved Hide resolved
backends/backend.go Outdated Show resolved Hide resolved
The recent code changes triggered an old exisiting bug,
because we would only keep a backend list of actually assigned
backends.
@mpfz0r mpfz0r requested a review from thll September 12, 2022 09:27
api/graylog.go Outdated Show resolved Hide resolved
Newer Graylog servers can use it to differentiate
multiple configs on one collector.
Older servers won't see this field for backwards compatibility.
@mpfz0r mpfz0r requested a review from thll September 13, 2022 14:52
@thll thll merged commit 0d69657 into master Sep 14, 2022
@thll thll deleted the multi-backend-support branch September 14, 2022 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants