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 serverless #36649

Merged
merged 48 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
14b8dcd
make serverless integration tests run
fearful-symmetry Sep 13, 2023
9f86184
update deps
fearful-symmetry Sep 13, 2023
ae975c5
Merge remote-tracking branch 'upstream/main' into serverless-aware
fearful-symmetry Sep 13, 2023
dc9d1a3
linter, error handling
fearful-symmetry Sep 13, 2023
be2eb52
still fixing error handling
fearful-symmetry Sep 13, 2023
e14d7fa
fixing old formatting verbs
fearful-symmetry Sep 13, 2023
afe73e8
still finding format verbs
fearful-symmetry Sep 13, 2023
bbb8072
add docs, fix typos
fearful-symmetry Sep 14, 2023
53b0948
initial functional pass
fearful-symmetry Sep 20, 2023
3967eef
Merge remote-tracking branch 'upstream/main' into serverless-idx-mgmt
fearful-symmetry Sep 20, 2023
42e32d5
fix setup, config
fearful-symmetry Sep 21, 2023
81e436a
Merge remote-tracking branch 'upstream/main' into serverless-idx-mgmt
fearful-symmetry Sep 21, 2023
87247b8
fix naming of config section
fearful-symmetry Sep 21, 2023
d0a3c4a
add headers
fearful-symmetry Sep 21, 2023
4a092ae
make linter happy
fearful-symmetry Sep 21, 2023
a50419d
still making linter happy
fearful-symmetry Sep 21, 2023
5d99ee0
tinkering with tests
fearful-symmetry Sep 22, 2023
c57b011
still fixing tests
fearful-symmetry Sep 22, 2023
a3767d4
revert file
fearful-symmetry Sep 22, 2023
9ce2cd5
tinker with export
fearful-symmetry Sep 22, 2023
7d3cd5f
fix logging in tests
fearful-symmetry Sep 22, 2023
a4bd6ce
fix load checking in setup
fearful-symmetry Sep 22, 2023
9dbb890
fix url in integration test
fearful-symmetry Sep 22, 2023
69b4258
fix commented out test line
fearful-symmetry Sep 22, 2023
ebc7bee
stil tinkering with integraton test
fearful-symmetry Sep 22, 2023
0cc4a25
Merge remote-tracking branch 'upstream/main' into serverless-idx-mgmt
fearful-symmetry Sep 22, 2023
df0e289
Merge remote-tracking branch 'upstream/main' into serverless-idx-mgmt
fearful-symmetry Sep 25, 2023
4781fd9
fix bad init in tests, add more check to ES handler
fearful-symmetry Sep 25, 2023
b34465e
add init checks for client handler, add more unit tests
fearful-symmetry Sep 25, 2023
ada16ca
make template loader serverless aware
fearful-symmetry Sep 25, 2023
bdade01
change naming, error handling, rework config system
fearful-symmetry Sep 25, 2023
ec339dc
fix up integration tests
fearful-symmetry Sep 26, 2023
77ef714
clean up load tests
fearful-symmetry Sep 26, 2023
564c1c6
stil making linter happy
fearful-symmetry Sep 26, 2023
d5cbf97
simplify manager init, fix tests, update docs
fearful-symmetry Sep 26, 2023
1fe4331
minor test fixes
fearful-symmetry Sep 26, 2023
1003798
clean up tests
fearful-symmetry Sep 26, 2023
6312c8f
clean up typos, remove legacy error handling
fearful-symmetry Sep 28, 2023
cfe258a
expand logging
fearful-symmetry Sep 28, 2023
a599d2c
Merge remote-tracking branch 'upstream/main' into serverless-idx-mgmt
fearful-symmetry Sep 28, 2023
3e95b58
logging, error handling changes
fearful-symmetry Sep 29, 2023
8d453cd
change error messages
fearful-symmetry Sep 29, 2023
b7db815
update lifetimes for serverless elasticsearch
fearful-symmetry Oct 2, 2023
ffb85e1
fix integration tests
fearful-symmetry Oct 2, 2023
4bb819c
change error handling, clean up log messages
fearful-symmetry Oct 2, 2023
247ef03
tinker with DSL config name
fearful-symmetry Oct 3, 2023
d70168c
update docs
fearful-symmetry Oct 3, 2023
7e0c25c
fix name example
fearful-symmetry Oct 3, 2023
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
24 changes: 24 additions & 0 deletions auditbeat/auditbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,30 @@ setup.template.settings:
# Overwrite the lifecycle policy at startup. The default is false.
#setup.ilm.overwrite: false

# ======================== 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 auditbeat-%{[agent.version]}"
#setup.dsl.data_stream_pattern: "auditbeat-%{[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
# =================================== Kibana ===================================

# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
Expand Down
24 changes: 24 additions & 0 deletions filebeat/filebeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2434,6 +2434,30 @@ setup.template.settings:
# Overwrite the lifecycle policy at startup. The default is false.
#setup.ilm.overwrite: false

# ======================== 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 filebeat-%{[agent.version]}"
#setup.dsl.data_stream_pattern: "filebeat-%{[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
# =================================== Kibana ===================================

# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
Expand Down
24 changes: 24 additions & 0 deletions heartbeat/heartbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,30 @@ setup.template.settings:
# Overwrite the lifecycle policy at startup. The default is false.
#setup.ilm.overwrite: false

# ======================== 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 heartbeat-%{[agent.version]}"
#setup.dsl.data_stream_pattern: "heartbeat-%{[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
# =================================== Kibana ===================================

# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
Expand Down
1 change: 1 addition & 0 deletions libbeat/_meta/config/default.reference.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{{template "setup.dashboards.reference.yml.tmpl" .}}
{{template "setup.template.reference.yml.tmpl" .}}
{{template "setup.ilm.reference.yml.tmpl" .}}
{{template "setup.dsl.reference.yml.tmpl" .}}
{{template "setup.kibana.reference.yml.tmpl" .}}
{{template "logging.reference.yml.tmpl" .}}
{{template "monitoring.reference.yml.tmpl" .}}
Expand Down
24 changes: 24 additions & 0 deletions libbeat/_meta/config/setup.dsl.reference.yml.tmpl
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
Copy link
Member

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:

# Overwrite the lifecycle policy at startup. The default is false.
#setup.dsl.overwrite: false
# =================================== Kibana ===================================

# Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
# This requires a Kibana endpoint configuration.

12 changes: 9 additions & 3 deletions libbeat/cmd/export/ilm_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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"

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Expand Down
11 changes: 7 additions & 4 deletions libbeat/cmd/export/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

// GenTemplateConfigCmd is the command used to export the elasticsearch template.
Expand All @@ -36,18 +36,21 @@ func GenTemplateConfigCmd(settings instance.Settings) *cobra.Command {
noILM, _ := cmd.Flags().GetBool("noilm")

if noILM {
settings.ILM = ilm.NoopSupport
settings.ILM = lifecycle.NoopSupport
}
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))
clientHandler, err := idxmgmt.NewFileClientHandler(newIdxmgmtClient(dir, version), b.Info, b.Config.LifecycleConfig)
if err != nil {
fatalf("error creating file handler: %s", err)
}
idxManager := b.IdxSupporter.Manager(clientHandler, idxmgmt.BeatsAssets(b.Fields))
if err := idxManager.Setup(idxmgmt.LoadModeForce, idxmgmt.LoadModeDisabled); err != nil {
fatalf("Error exporting template: %+v.", err)
Expand Down
18 changes: 16 additions & 2 deletions libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import (
"github.com/elastic/beats/v7/libbeat/esleg/eslegclient"
"github.com/elastic/beats/v7/libbeat/features"
"github.com/elastic/beats/v7/libbeat/idxmgmt"
"github.com/elastic/beats/v7/libbeat/idxmgmt/lifecycle"
"github.com/elastic/beats/v7/libbeat/instrumentation"
"github.com/elastic/beats/v7/libbeat/kibana"
"github.com/elastic/beats/v7/libbeat/management"
Expand Down Expand Up @@ -133,6 +134,9 @@ type beatConfig struct {
// monitoring settings
MonitoringBeatConfig monitoring.BeatConfig `config:",inline"`

// ILM settings
LifecycleConfig lifecycle.RawConfig `config:",inline"`

// central management settings
Management *config.C `config:"management"`

Expand Down Expand Up @@ -671,7 +675,13 @@ func (b *Beat) Setup(settings Settings, bt beat.Creator, setup SetupSettings) er
if setup.IndexManagement || setup.ILMPolicy {
loadILM = idxmgmt.LoadModeEnabled
}
m := b.IdxSupporter.Manager(idxmgmt.NewESClientHandler(esClient), idxmgmt.BeatsAssets(b.Fields))

mgmtHandler, err := idxmgmt.NewESClientHandler(esClient, b.Info, b.Config.LifecycleConfig)
if err != nil {
return fmt.Errorf("error creating index management handler: %w", err)
}

m := b.IdxSupporter.Manager(mgmtHandler, idxmgmt.BeatsAssets(b.Fields))
if ok, warn := m.VerifySetup(loadTemplate, loadILM); !ok {
fmt.Println(warn)
}
Expand Down Expand Up @@ -1065,7 +1075,11 @@ func (b *Beat) registerESIndexManagement() error {

func (b *Beat) indexSetupCallback() elasticsearch.ConnectCallback {
return func(esClient *eslegclient.Connection) error {
m := b.IdxSupporter.Manager(idxmgmt.NewESClientHandler(esClient), idxmgmt.BeatsAssets(b.Fields))
mgmtHandler, err := idxmgmt.NewESClientHandler(esClient, b.Info, b.Config.LifecycleConfig)
if err != nil {
return fmt.Errorf("error creating index management handler: %w", err)
}
m := b.IdxSupporter.Manager(mgmtHandler, idxmgmt.BeatsAssets(b.Fields))
return m.Setup(idxmgmt.LoadModeEnabled, idxmgmt.LoadModeEnabled)
}
}
Expand Down
4 changes: 2 additions & 2 deletions libbeat/cmd/instance/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/elastic/beats/v7/libbeat/cfgfile"
"github.com/elastic/beats/v7/libbeat/idxmgmt"
"github.com/elastic/beats/v7/libbeat/idxmgmt/ilm"
"github.com/elastic/beats/v7/libbeat/idxmgmt/lifecycle"
"github.com/elastic/beats/v7/libbeat/monitoring/report"
"github.com/elastic/beats/v7/libbeat/publisher/processing"
)
Expand All @@ -42,7 +42,7 @@ type Settings struct {

// load custom index manager. The config object will be the Beats root configuration.
IndexManagement idxmgmt.SupportFactory
ILM ilm.SupportFactory
ILM lifecycle.SupportFactory

Processing processing.SupportFactory

Expand Down
29 changes: 14 additions & 15 deletions libbeat/common/fmtstr/formatevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ type eventEvalContext struct {
}

var (
errMissingKeys = errors.New("missing keys")
errConvertString = errors.New("can not convert to string")
)

Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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 := ""
Expand Down Expand Up @@ -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 == "" {
Expand All @@ -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{}
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 make([]string, len(whatever)) statement if I remember, so I just did that.


for len(field) > 0 {
if field[0] != '[' {
Expand Down
4 changes: 2 additions & 2 deletions libbeat/dashboards/kibana_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type KibanaLoader struct {
// NewKibanaLoader creates a new loader to load Kibana files
func NewKibanaLoader(ctx context.Context, cfg *config.C, dashboardsConfig *Config, hostname string, msgOutputter MessageOutputter, beatname string) (*KibanaLoader, error) {
if cfg == nil || !cfg.Enabled() {
return nil, fmt.Errorf("Kibana is not configured or enabled")
return nil, fmt.Errorf("kibana is not configured or enabled")
}

client, err := getKibanaClient(ctx, cfg, dashboardsConfig.Retry, 0, beatname)
Expand Down Expand Up @@ -127,7 +127,7 @@ func (loader KibanaLoader) ImportIndexFile(file string) error {
// ImportIndex imports the passed index pattern to Kibana
func (loader KibanaLoader) ImportIndex(pattern mapstr.M) error {
if loader.version.LessThan(minimumRequiredVersionSavedObjects) {
return fmt.Errorf("Kibana version must be at least " + minimumRequiredVersionSavedObjects.String())
return fmt.Errorf("kibana version must be at least " + minimumRequiredVersionSavedObjects.String())
}

var errs multierror.Errors
Expand Down
1 change: 1 addition & 0 deletions libbeat/esleg/eslegclient/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ func (conn *Connection) getVersion() error {
}

if versionData.Version.BuildFlavor == "serverless" {
conn.log.Info("build flavor of es is severless, marking connection as serverless")
conn.isServerless = true
} else if versionData.Version.BuildFlavor == "default" {
conn.isServerless = false
Expand Down
Loading
Loading