-
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.
Disable migration aliases in index pattern (#10478)
* Disable migration aliases in index pattern The migration aliases should not show up in the index pattern if `migration.enabled: false`. For this to happen, the Kibana index pattern must be generated on the fly instead of packaging it with each Beat. This PR introduces the generation of the index pattern when Kibana data is loaded. APM still needs the index pattern as file. For this the export command `index-pattern` was added. It will print the index pattern to the standard out: ``` ./metricbeat export index-pattern > pattern.json ``` The commands to generate the index pattern in the dev environment were removed. For checking if aliases are supported, the Kibana version is checked. Fully accurate would be to check the Elasticsearch version as it depends on the ES version in the end and not Kibana. But it's assume that in general the same minor version is used. The reason not Elasticsearch is checked as it would potentially require additional config options and adds unnecessary complexity. For the index pattern the internal fields.go are used. Even if fields.yml is configured still fields.go is used. This is the same behavior as we had so far when the index pattern was generated. It could be improved in the future to also support a fields.yml for the generation if needed. In general this PR tried to change as little code as possible. The code and tests around the Kibana dashboard generation and index pattern generation is not very nice. One reason is that it also contains old logic which was used for previous versions but also has the ability to read dashboards from a zip file. Because of this all the old capabilities have to stay in the code for now. The code should be cleaned up at a later stage. Further changes: * Added system tests to Filebeat to check for correct content in index pattern when migration is enabled. * Fix double generation of common.yml in Metricbeat. It seems some changes in the past caused that the common.yml file was contained in two fields.go files in Metricbeat
- Loading branch information
Showing
21 changed files
with
316 additions
and
301 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
92 changes: 0 additions & 92 deletions
92
dev-tools/cmd/kibana_index_pattern/kibana_index_pattern.go
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
import os | ||
import unittest | ||
from filebeat import BaseTest | ||
|
||
|
||
class Test(BaseTest): | ||
|
||
def test_export_index_pattern(self): | ||
""" | ||
Test export index pattern | ||
""" | ||
self.render_config_template() | ||
exit_code = self.run_beat( | ||
logging_args=[], | ||
extra_args=["export", "index-pattern"]) | ||
|
||
assert exit_code == 0 | ||
assert self.log_contains('"objects": [') | ||
assert self.log_contains('beat.name') == False | ||
|
||
def test_export_index_pattern_migration(self): | ||
""" | ||
Test export index pattern with migration flag enabled | ||
""" | ||
self.render_config_template() | ||
exit_code = self.run_beat( | ||
logging_args=[], | ||
extra_args=["export", "index-pattern", "-E", "migration.enabled:true"]) | ||
|
||
assert exit_code == 0 | ||
assert self.log_contains('"objects": [') | ||
assert self.log_contains('beat.name') |
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,87 @@ | ||
// 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 export | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/elastic/beats/libbeat/cmd/instance" | ||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/libbeat/kibana" | ||
) | ||
|
||
// GenIndexPatternConfigCmd generates an index pattern for Kibana | ||
func GenIndexPatternConfigCmd(settings instance.Settings, name, idxPrefix, beatVersion string) *cobra.Command { | ||
genTemplateConfigCmd := &cobra.Command{ | ||
Use: "index-pattern", | ||
Short: "Export kibana index pattern to stdout", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
version, _ := cmd.Flags().GetString("es.version") | ||
|
||
b, err := instance.NewBeat(name, idxPrefix, beatVersion) | ||
if err != nil { | ||
fatalf("Error initializing beat: %+v", err) | ||
} | ||
err = b.InitWithSettings(settings) | ||
if err != nil { | ||
fatalf("Error initializing beat: %+v", err) | ||
} | ||
|
||
if version == "" { | ||
version = b.Info.Version | ||
} | ||
|
||
var withMigration bool | ||
if b.RawConfig.HasField("migration") { | ||
sub, err := b.RawConfig.Child("migration", -1) | ||
if err != nil { | ||
fatalf("Failed to read migration setting: %+v", err) | ||
} | ||
withMigration = sub.Enabled() | ||
} | ||
|
||
// Index pattern generation | ||
v, err := common.NewVersion(version) | ||
if err != nil { | ||
fatalf("Error creating version: %+v", err) | ||
} | ||
indexPattern, err := kibana.NewGenerator(b.Info.IndexPrefix, b.Info.Beat, b.Fields, beatVersion, *v, withMigration) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
pattern, err := indexPattern.Generate() | ||
if err != nil { | ||
log.Fatalf("ERROR: %s", err) | ||
} | ||
|
||
_, err = os.Stdout.WriteString(pattern.StringToPrint() + "\n") | ||
if err != nil { | ||
fatalf("Error writing index pattern: %+v", err) | ||
} | ||
}, | ||
} | ||
|
||
genTemplateConfigCmd.Flags().String("es.version", beatVersion, "Elasticsearch version") | ||
genTemplateConfigCmd.Flags().String("index", idxPrefix, "Base index name") | ||
|
||
return genTemplateConfigCmd | ||
} |
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
Oops, something went wrong.