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

Move Fields from pacakge libbeat/common to libbeat/mapping #11198

Merged
merged 5 commits into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The list below covers the major changes between 7.0.0-beta1 and master only.

- Remove support for deprecated `GenRootCmd` methods. {pull}10721[10721]
- Remove SkipNormalization, SkipAgentMetadata, SkipAddHostName. {pull}10801[10801] {pull}10769[10769]
- Move Fields from package libbeat/common to libbeat/mapping. {pull}11198[11198]

==== Bugfixes

Expand Down
4 changes: 2 additions & 2 deletions auditbeat/module/auditd/audit_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
"github.com/prometheus/procfs"

"github.com/elastic/beats/auditbeat/core"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/mapping"
"github.com/elastic/beats/metricbeat/mb"
mbtest "github.com/elastic/beats/metricbeat/mb/testing"
"github.com/elastic/go-libaudit"
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestData(t *testing.T) {

// assertFieldsAreDocumented mimics assert_fields_are_documented in Python system tests.
func assertFieldsAreDocumented(t *testing.T, events []mb.Event) {
fieldsYml, err := common.LoadFieldsYaml("../../fields.yml")
fieldsYml, err := mapping.LoadFieldsYaml("../../fields.yml")
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion libbeat/idxmgmt/idxmgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/idxmgmt/ilm"
"github.com/elastic/beats/libbeat/mapping"
"github.com/elastic/beats/libbeat/template"
)

Expand Down Expand Up @@ -96,7 +97,7 @@ func TestDefaultSupport_TemplateConfig(t *testing.T) {

cloneCfg := func(c template.TemplateConfig) template.TemplateConfig {
if c.AppendFields != nil {
tmp := make(common.Fields, len(c.AppendFields))
tmp := make(mapping.Fields, len(c.AppendFields))
copy(tmp, c.AppendFields)
c.AppendFields = tmp
}
Expand Down
25 changes: 13 additions & 12 deletions libbeat/kibana/fields_transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@ import (
"fmt"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/mapping"
)

var v640 = common.MustNewVersion("6.4.0")

type fieldsTransformer struct {
fields common.Fields
fields mapping.Fields
transformedFields []common.MapStr
transformedFieldFormatMap common.MapStr
version *common.Version
keys map[string]int
migration bool
}

func newFieldsTransformer(version *common.Version, fields common.Fields, migration bool) (*fieldsTransformer, error) {
func newFieldsTransformer(version *common.Version, fields mapping.Fields, migration bool) (*fieldsTransformer, error) {
if version == nil {
return nil, errors.New("Version must be given")
}
Expand Down Expand Up @@ -64,10 +65,10 @@ func (t *fieldsTransformer) transform() (transformed common.MapStr, err error) {
// add some meta fields
truthy := true
falsy := false
t.add(common.Field{Path: "_id", Type: "keyword", Index: &falsy, Analyzed: &falsy, DocValues: &falsy, Searchable: &falsy, Aggregatable: &falsy})
t.add(common.Field{Path: "_type", Type: "keyword", Index: &falsy, Analyzed: &falsy, DocValues: &falsy, Searchable: &truthy, Aggregatable: &truthy})
t.add(common.Field{Path: "_index", Type: "keyword", Index: &falsy, Analyzed: &falsy, DocValues: &falsy, Searchable: &falsy, Aggregatable: &falsy})
t.add(common.Field{Path: "_score", Type: "integer", Index: &falsy, Analyzed: &falsy, DocValues: &falsy, Searchable: &falsy, Aggregatable: &falsy})
t.add(mapping.Field{Path: "_id", Type: "keyword", Index: &falsy, Analyzed: &falsy, DocValues: &falsy, Searchable: &falsy, Aggregatable: &falsy})
t.add(mapping.Field{Path: "_type", Type: "keyword", Index: &falsy, Analyzed: &falsy, DocValues: &falsy, Searchable: &truthy, Aggregatable: &truthy})
t.add(mapping.Field{Path: "_index", Type: "keyword", Index: &falsy, Analyzed: &falsy, DocValues: &falsy, Searchable: &falsy, Aggregatable: &falsy})
t.add(mapping.Field{Path: "_score", Type: "integer", Index: &falsy, Analyzed: &falsy, DocValues: &falsy, Searchable: &falsy, Aggregatable: &falsy})

transformed = common.MapStr{
"fields": t.transformedFields,
Expand All @@ -76,7 +77,7 @@ func (t *fieldsTransformer) transform() (transformed common.MapStr, err error) {
return
}

func (t *fieldsTransformer) transformFields(commonFields common.Fields, path string) {
func (t *fieldsTransformer) transformFields(commonFields mapping.Fields, path string) {
for _, f := range commonFields {
f.Path = f.Name
if path != "" {
Expand Down Expand Up @@ -119,7 +120,7 @@ func (t *fieldsTransformer) transformFields(commonFields common.Fields, path str
}
}

func (t *fieldsTransformer) update(target *common.MapStr, override common.Field) error {
func (t *fieldsTransformer) update(target *common.MapStr, override mapping.Field) error {
field, _ := transformField(t.version, override)
if override.Type == "" || (*target)["type"] == field["type"] {
target.Update(field)
Expand All @@ -133,7 +134,7 @@ func (t *fieldsTransformer) update(target *common.MapStr, override common.Field)
return fmt.Errorf("field <%s> is duplicated", override.Path)
}

func (t *fieldsTransformer) add(f common.Field) {
func (t *fieldsTransformer) add(f mapping.Field) {
if idx := t.keys[f.Path]; idx > 0 {
target := &t.transformedFields[idx-1] // 1-indexed
if err := t.update(target, f); err != nil {
Expand All @@ -150,7 +151,7 @@ func (t *fieldsTransformer) add(f common.Field) {
}
}

func transformField(version *common.Version, f common.Field) (common.MapStr, common.MapStr) {
func transformField(version *common.Version, f mapping.Field) (common.MapStr, common.MapStr) {
field := common.MapStr{
"name": f.Path,
"count": f.Count,
Expand Down Expand Up @@ -217,7 +218,7 @@ func getVal(valP *bool, def bool) bool {
return def
}

func addParams(format *common.MapStr, version *common.Version, f common.Field) {
func addParams(format *common.MapStr, version *common.Version, f mapping.Field) {
addFormatParam(format, "pattern", f.Pattern)
addFormatParam(format, "inputFormat", f.InputFormat)
addFormatParam(format, "outputFormat", f.OutputFormat)
Expand Down Expand Up @@ -248,7 +249,7 @@ func addFormatParam(f *common.MapStr, key string, val interface{}) {
}

// takes the highest version where major version <= given version
func addVersionedFormatParam(f *common.MapStr, version *common.Version, key string, val []common.VersionizedString) {
func addVersionedFormatParam(f *common.MapStr, version *common.Version, key string, val []mapping.VersionizedString) {
if len(val) == 0 {
return
}
Expand Down
Loading