-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Handles data streams from fleet, the current heartbeat code doesn't handle data_streams at all, this fixes that. Additionally, it hoists the id from the top level of the yaml config, and merges both levels of data_streams, since one is at the input level, and the other is at the stream level. Additionally, this cleans up the data streams code significantly, introducing a new add_data_streams_index processor that: More efficiently formats index names for data streams Allows individual events to override the dataset (useful for synthetics where we have a base browser dataset, but also browser_screenshot and browser_network for extended data that can take up lots of space, and often requires a different ILM policy).
- Loading branch information
Showing
10 changed files
with
413 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package stdfields | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/elastic/beats/v7/libbeat/common" | ||
) | ||
|
||
// OptionalStream represents a config that has a stream set, which in practice | ||
// means agent/fleet. In this case we primarily use the first stream for the | ||
// config, but we do pull the Id from the root, and merge the root data stream | ||
// in as well | ||
type OptionalStream struct { | ||
Id string `config:"id"` | ||
DataStream *common.Config `config:"data_stream"` | ||
Streams []*common.Config `config:"streams"` | ||
} | ||
|
||
// UnnestStream detects configs that come from fleet and transforms the config into something compatible | ||
// with heartbeat, by mixing some fields (id, data_stream) with those from the first stream. It assumes | ||
// that there is exactly one stream associated with the input. | ||
func UnnestStream(config *common.Config) (res *common.Config, err error) { | ||
optS := &OptionalStream{} | ||
err = config.Unpack(optS) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not unnest stream: %w", err) | ||
} | ||
|
||
if len(optS.Streams) == 0 { | ||
return config, nil | ||
} | ||
|
||
res = optS.Streams[0] | ||
err = res.MergeWithOpts(common.MapStr{"id": optS.Id, "data_stream": optS.DataStream}) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package stdfields | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/elastic/beats/v7/libbeat/common" | ||
"github.com/elastic/go-lookslike" | ||
"github.com/elastic/go-lookslike/testslike" | ||
"github.com/elastic/go-lookslike/validator" | ||
) | ||
|
||
func TestUnnestStream(t *testing.T) { | ||
type testCase struct { | ||
name string | ||
cfg common.MapStr | ||
v validator.Validator | ||
} | ||
tests := []testCase{ | ||
{ | ||
name: "simple", | ||
cfg: common.MapStr{ | ||
"id": "myuuid", | ||
"streams": []common.MapStr{ | ||
common.MapStr{ | ||
"streamid": "mystreamid", | ||
"data_stream": common.MapStr{ | ||
"namespace": "mynamespace", | ||
"dataset": "mydataset", | ||
"type": "mytype", | ||
}, | ||
}, | ||
}, | ||
}, | ||
v: lookslike.MustCompile(common.MapStr{ | ||
"id": "myuuid", | ||
"data_stream": common.MapStr{ | ||
"namespace": "mynamespace", | ||
"dataset": "mydataset", | ||
"type": "mytype", | ||
}, | ||
}), | ||
}, | ||
{ | ||
name: "split data stream", | ||
cfg: common.MapStr{ | ||
"id": "myuuid", | ||
"data_stream": common.MapStr{ | ||
"type": "mytype", | ||
}, | ||
"streams": []common.MapStr{ | ||
common.MapStr{ | ||
"data_stream": common.MapStr{ | ||
"namespace": "mynamespace", | ||
"dataset": "mydataset", | ||
}, | ||
}, | ||
}, | ||
}, | ||
v: lookslike.MustCompile(common.MapStr{ | ||
"id": "myuuid", | ||
"data_stream": common.MapStr{ | ||
"namespace": "mynamespace", | ||
"dataset": "mydataset", | ||
"type": "mytype", | ||
}, | ||
}), | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
src, err := common.NewConfigFrom(test.cfg) | ||
require.NoError(t, err) | ||
|
||
unnested, err := UnnestStream(src) | ||
require.NoError(t, err) | ||
|
||
unpacked := common.MapStr{} | ||
err = unnested.Unpack(unpacked) | ||
require.NoError(t, err) | ||
testslike.Test(t, test.v, unpacked) | ||
}) | ||
} | ||
} |
Oops, something went wrong.