-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 serverless #36649
Support serverless #36649
Changes from all commits
14b8dcd
9f86184
ae975c5
dc9d1a3
be2eb52
e14d7fa
afe73e8
bbb8072
53b0948
3967eef
42e32d5
81e436a
87247b8
d0a3c4a
4a092ae
a50419d
5d99ee0
c57b011
a3767d4
9ce2cd5
7d3cd5f
a4bd6ce
9dbb890
69b4258
ebc7bee
0cc4a25
df0e289
4781fd9
b34465e
ada16ca
bdade01
ec339dc
77ef714
564c1c6
d5cbf97
1fe4331
1003798
6312c8f
cfe258a
a599d2c
3e95b58
8d453cd
b7db815
ffb85e1
4bb819c
247ef03
d70168c
7e0c25c
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,24 @@ | ||
{{header "Data Stream Lifecycle (DSL)"}} | ||
|
||
# Configure Data Stream Lifecycle to manage data streams while connected to Serverless elasticsearch. | ||
# These settings are mutually exclusive with ILM settings which are not supported in Serverless projects. | ||
|
||
# Enable DSL support. Valid values are true, or false. | ||
#setup.dsl.enabled: true | ||
|
||
# Set the lifecycle policy name or pattern. For DSL, this name must match the data stream that the lifecycle is for. | ||
# The default data stream pattern is {{.BeatName}}-%{[agent.version]}" | ||
#setup.dsl.data_stream_pattern: "{{.BeatName}}-%{[agent.version]}" | ||
|
||
# The path to a JSON file that contains a lifecycle policy configuration. Used | ||
# to load your own lifecycle policy. | ||
# If no custom policy is specified, a default policy with a lifetime of 7 days will be created. | ||
#setup.dsl.policy_file: | ||
|
||
# Disable the check for an existing lifecycle policy. The default is true. If | ||
# you disable this check, set setup.dsl.overwrite: true so the lifecycle policy | ||
# can be installed. | ||
#setup.dsl.check_exists: true | ||
|
||
# Overwrite the lifecycle policy at startup. The default is false. | ||
#setup.dsl.overwrite: false | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ import ( | |
|
||
"github.com/elastic/beats/v7/libbeat/cmd/instance" | ||
"github.com/elastic/beats/v7/libbeat/idxmgmt" | ||
"github.com/elastic/beats/v7/libbeat/idxmgmt/ilm" | ||
"github.com/elastic/beats/v7/libbeat/idxmgmt/lifecycle" | ||
) | ||
|
||
// GenGetILMPolicyCmd is the command used to export the ilm policy. | ||
|
@@ -35,14 +35,20 @@ func GenGetILMPolicyCmd(settings instance.Settings) *cobra.Command { | |
dir, _ := cmd.Flags().GetString("dir") | ||
|
||
if settings.ILM == nil { | ||
settings.ILM = ilm.StdSupport | ||
settings.ILM = lifecycle.StdSupport | ||
} | ||
b, err := instance.NewInitializedBeat(settings) | ||
if err != nil { | ||
fatalfInitCmd(err) | ||
} | ||
|
||
clientHandler := idxmgmt.NewFileClientHandler(newIdxmgmtClient(dir, version)) | ||
// the way this works, we decide to export ILM or DSL based on the user's config. | ||
// This means that if a user has no index management config, we'll default to ILM, regardless of what the user | ||
// is connected to. Might not be a problem since a user who doesn't have any custom lifecycle config has nothing to export? | ||
clientHandler, err := idxmgmt.NewFileClientHandler(newIdxmgmtClient(dir, version), b.Info, b.Config.LifecycleConfig) | ||
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. might be nice to have a Debug or Info log here that says something like "neither ilm or dsl specified, defaulting to ilm" 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. +1 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. Alright, will add to the file handler, since that component has a little more insight into config state. |
||
if err != nil { | ||
fatalf("error creating file handler: %s", err) | ||
} | ||
idxManager := b.IdxSupporter.Manager(clientHandler, idxmgmt.BeatsAssets(b.Fields)) | ||
if err := idxManager.Setup(idxmgmt.LoadModeDisabled, idxmgmt.LoadModeForce); err != nil { | ||
fatalf("Error exporting ilm-policy: %+v.", err) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,6 @@ type eventEvalContext struct { | |
} | ||
|
||
var ( | ||
errMissingKeys = errors.New("missing keys") | ||
errConvertString = errors.New("can not convert to string") | ||
) | ||
|
||
|
@@ -157,19 +156,24 @@ func CompileEvent(in string) (*EventFormatString, error) { | |
func (fs *EventFormatString) Unpack(v interface{}) error { | ||
s, err := tryConvString(v) | ||
if err != nil { | ||
return err | ||
return fmt.Errorf("error converting type %T to event formatter: %w", v, err) | ||
} | ||
|
||
tmp, err := CompileEvent(s) | ||
if err != nil { | ||
return err | ||
return fmt.Errorf("error compiling event formatter: %w", err) | ||
} | ||
|
||
// init fs from tmp | ||
*fs = *tmp | ||
return nil | ||
} | ||
|
||
// IsInitialized returns true if the underlying event formatter is prepared to format an event | ||
func (fs *EventFormatString) IsInitialized() bool { | ||
return fs.formatter != nil | ||
} | ||
|
||
// NumFields returns number of unique event fields used by the format string. | ||
func (fs *EventFormatString) NumFields() int { | ||
return len(fs.fields) | ||
|
@@ -190,6 +194,9 @@ func (fs *EventFormatString) Fields() []string { | |
// Run executes the format string returning a new expanded string or an error | ||
// if execution or event field expansion fails. | ||
func (fs *EventFormatString) Run(event *beat.Event) (string, error) { | ||
if !fs.IsInitialized() { | ||
return "", fmt.Errorf("event formatter is nil") | ||
} | ||
ctx := newEventCtx(len(fs.fields)) | ||
defer releaseCtx(ctx) | ||
|
||
|
@@ -296,7 +303,7 @@ func (e *eventFieldCompiler) compileEventField( | |
ops []VariableOp, | ||
) (FormatEvaler, error) { | ||
if len(ops) > 1 { | ||
return nil, errors.New("Too many format modifiers given") | ||
return nil, errors.New("too many format modifiers given") | ||
} | ||
|
||
defaultValue := "" | ||
|
@@ -340,34 +347,26 @@ func (e *eventFieldCompiler) compileTimestamp( | |
ops []VariableOp, | ||
) (FormatEvaler, error) { | ||
if expression[0] != '+' { | ||
return nil, errors.New("No timestamp expression") | ||
return nil, errors.New("no timestamp expression") | ||
} | ||
|
||
formatter, err := dtfmt.NewFormatter(expression[1:]) | ||
if err != nil { | ||
return nil, fmt.Errorf("%v in timestamp expression", err) | ||
return nil, fmt.Errorf("%w in timestamp expression", err) | ||
} | ||
|
||
e.timestamp = true | ||
return &eventTimestampEvaler{formatter}, nil | ||
} | ||
|
||
func (e *eventFieldEvaler) Eval(c interface{}, out *bytes.Buffer) error { | ||
type stringer interface { | ||
String() string | ||
} | ||
|
||
ctx := c.(*eventEvalContext) | ||
s := ctx.keys[e.index] | ||
_, err := out.WriteString(s) | ||
return err | ||
} | ||
|
||
func (e *defaultEventFieldEvaler) Eval(c interface{}, out *bytes.Buffer) error { | ||
type stringer interface { | ||
String() string | ||
} | ||
|
||
ctx := c.(*eventEvalContext) | ||
s := ctx.keys[e.index] | ||
if s == "" { | ||
|
@@ -385,7 +384,7 @@ func (e *eventTimestampEvaler) Eval(c interface{}, out *bytes.Buffer) error { | |
|
||
func parseEventPath(field string) (string, error) { | ||
field = strings.Trim(field, " \n\r\t") | ||
var fields []string | ||
fields := []string{} | ||
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. Why make this change? https://github.com/golang/go/wiki/CodeReviewComments#declaring-empty-slices 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. Yah, there was a linter message that complained about that line, which I thought was odd. The for loop was a little too complicated to do a |
||
|
||
for len(field) > 0 { | ||
if field[0] != '[' { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need a newline at the end of the file otherwise there is a missing space between the end of this section and the next one: