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

Add support for migration alias in index pattern #10204

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 4 additions & 2 deletions dev-tools/cmd/kibana_index_pattern/kibana_index_pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
indexPattern string
fieldsYAMLFile string
outputDir string
migration bool
)

func init() {
Expand All @@ -49,6 +50,7 @@ func init() {
flag.StringVar(&indexPattern, "index", "", "Kibana index pattern. (Required)")
flag.StringVar(&fieldsYAMLFile, "fields", "fields.yml", "fields.yml file containing all fields used by the Beat.")
flag.StringVar(&outputDir, "out", "build/kibana", "Output dir.")
flag.BoolVar(&migration, "migration", false, "Enable migration fields in index pattern.")
}

func main() {
Expand All @@ -68,11 +70,11 @@ func main() {
}

versions := []string{
"6.0.0",
"7.0.0",
}
for _, version := range versions {
version, _ := common.NewVersion(version)
indexPattern, err := kibana.NewGenerator(indexPattern, beatName, fieldsYAMLFile, outputDir, beatVersion, *version)
indexPattern, err := kibana.NewGenerator(indexPattern, beatName, fieldsYAMLFile, outputDir, beatVersion, *version, migration)
if err != nil {
log.Fatal(err)
}
Expand Down
7 changes: 6 additions & 1 deletion libbeat/kibana/fields_transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ type fieldsTransformer struct {
transformedFieldFormatMap common.MapStr
version *common.Version
keys map[string]int
migration bool
}

func newFieldsTransformer(version *common.Version, fields common.Fields) (*fieldsTransformer, error) {
func newFieldsTransformer(version *common.Version, fields common.Fields, migration bool) (*fieldsTransformer, error) {
if version == nil {
return nil, errors.New("Version must be given")
}
Expand All @@ -44,6 +45,7 @@ func newFieldsTransformer(version *common.Version, fields common.Fields) (*field
transformedFields: []common.MapStr{},
transformedFieldFormatMap: common.MapStr{},
keys: map[string]int{},
migration: migration,
}, nil
}

Expand Down Expand Up @@ -87,6 +89,9 @@ func (t *fieldsTransformer) transformFields(commonFields common.Fields, path str
}
} else {
if f.Type == "alias" {
if f.MigrationAlias && !t.migration {
continue
}
if t.version.LessThan(v640) {
continue
}
Expand Down
6 changes: 4 additions & 2 deletions libbeat/kibana/index_pattern_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ type IndexPatternGenerator struct {
version common.Version
targetDir string
targetFilename string
migration bool
}

// Create an instance of the Kibana Index Pattern Generator
func NewGenerator(indexName, beatName, fieldsYAMLFile, outputDir, beatVersion string, version common.Version) (*IndexPatternGenerator, error) {
func NewGenerator(indexName, beatName, fieldsYAMLFile, outputDir, beatVersion string, version common.Version, migration bool) (*IndexPatternGenerator, error) {
beatName = clean(beatName)

if _, err := os.Stat(fieldsYAMLFile); err != nil {
Expand All @@ -51,6 +52,7 @@ func NewGenerator(indexName, beatName, fieldsYAMLFile, outputDir, beatVersion st
version: version,
targetDir: createTargetDir(outputDir, version),
targetFilename: beatName + ".json",
migration: migration,
}, nil
}

Expand Down Expand Up @@ -125,7 +127,7 @@ func (i *IndexPatternGenerator) addFieldsSpecific(indexPattern *common.MapStr) e
if err != nil {
return err
}
transformer, err := newFieldsTransformer(&i.version, fields)
transformer, err := newFieldsTransformer(&i.version, fields, i.migration)
if err != nil {
return err
}
Expand Down