-
Notifications
You must be signed in to change notification settings - Fork 5k
[Elastic Log Driver] Create a config shim between libbeat and the user #18605
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
Changes from 17 commits
a7fa4cb
909c862
c361c99
f430487
376d4f3
59a5c74
815b1ae
6081adc
87135f5
29b7cd4
1b73771
5b4f426
111354c
3465bfa
10a0536
703a132
26d467c
3a363a0
489af14
82f7e8b
035e3d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| // or more contributor license agreements. Licensed under the Elastic License; | ||
| // you may not use this file except in compliance with the Elastic License. | ||
|
|
||
| package pipelinemanager | ||
|
|
||
| import ( | ||
| "strings" | ||
|
|
||
| "github.com/pkg/errors" | ||
|
|
||
| "github.com/elastic/beats/v7/libbeat/common" | ||
| "github.com/elastic/beats/v7/libbeat/common/transform/typeconv" | ||
| ) | ||
|
|
||
| // ContainerOutputConfig has all the options we'll expect from --log-opts | ||
| type ContainerOutputConfig struct { | ||
| Endpoint []string `struct:"output.elasticsearch.hosts,omitempty"` | ||
fearful-symmetry marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| User string `struct:"output.elasticsearch.username,omitempty"` | ||
| Password string `struct:"output.elasticsearch.password,omitempty"` | ||
| Index string `struct:"output.elasticsearch.index,omitempty"` | ||
| Pipeline string `struct:"output.elasticsearch.pipeline,omitempty"` | ||
| APIKey string `struct:"output.elasticsearch.api_key,omitempty"` | ||
| Timeout string `struct:"output.elasticsearch.timeout,omitempty"` | ||
| BackoffInit string `struct:"output.elasticsearch.backoff.init,omitempty"` | ||
| BackoffMax string `struct:"output.elasticsearch.backoff.max,omitempty"` | ||
| CloudID string `struct:"cloud.id,omitempty"` | ||
| CloudAuth string `struct:"cloud.auth,omitempty"` | ||
| ProxyURL string `struct:"output.elasticsearch.proxy_url,omitempty"` | ||
| } | ||
fearful-symmetry marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note (for follow up PR?): |
||
|
|
||
| // NewCfgFromRaw returns a ContainerOutputConfig based on a raw config we get from the API | ||
| func NewCfgFromRaw(input map[string]string) (ContainerOutputConfig, error) { | ||
fearful-symmetry marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| newCfg := ContainerOutputConfig{} | ||
| endpoint, ok := input["endpoint"] | ||
| if !ok { | ||
| return newCfg, errors.New("An endpoint flag is required") | ||
| } | ||
|
|
||
| endpointList := strings.Split(endpoint, ",") | ||
|
|
||
| newCfg.Endpoint = endpointList | ||
|
|
||
| newCfg.User = input["user"] | ||
| newCfg.Password = input["password"] | ||
| newCfg.Index, _ = input["index"] | ||
| newCfg.Pipeline = input["pipeline"] | ||
| newCfg.CloudID = input["cloud_id"] | ||
| newCfg.CloudAuth = input["cloud_auth"] | ||
| newCfg.ProxyURL = input["proxy_url"] | ||
| newCfg.APIKey = input["api_key"] | ||
| newCfg.Timeout = input["timeout"] | ||
| newCfg.BackoffInit = input["backoff_init"] | ||
| newCfg.BackoffMax = input["backoff_max"] | ||
|
|
||
| return newCfg, nil | ||
| } | ||
|
|
||
| // CreateConfig converts the struct into a config object that can be absorbed by libbeat | ||
| func (cfg ContainerOutputConfig) CreateConfig() (*common.Config, error) { | ||
|
|
||
| // the use of typeconv is a hacky shim so we can impliment `omitempty` where needed. | ||
| var tmp map[string]interface{} | ||
| err := typeconv.Convert(&tmp, cfg) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "error converting config struct to interface") | ||
| } | ||
| cfgFinal, err := common.NewConfigFrom(tmp) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "error creating config object") | ||
| } | ||
|
|
||
| return cfgFinal, nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.