Skip to content

Commit

Permalink
Fix command line template generation (#4463)
Browse files Browse the repository at this point in the history
The params for `New` change in the template package. This PR adjusts to the new params. It requires to make the settings available globally.

In addition the version handling is changed so the command can also be run without `$VERSION` and just the beats version is used.
  • Loading branch information
ruflin authored and tsg committed Jun 7, 2017
1 parent ef4234a commit 8ba93a7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dev-tools/cmd/index_template/index_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {
*version = "2.0.0"
}

tmpl, err := template.New(beatVersion, *version, *index)
tmpl, err := template.New(beatVersion, *version, *index, template.TemplateSettings{})
if err != nil {
fmt.Fprintf(os.Stderr, "Error generating template: %+v", err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion libbeat/scripts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ docs-preview: ## @build Preview the documents for the beat in the browser

.PHONY: index-template
index-template: ## @build Generate index templates for the given $VERSION. This is for manual testing.
go run ${ES_BEATS}/dev-tools/cmd/index_template/index_template.go -es.version ${VERSION} -index ${BEAT_NAME} -output ${BEAT_GOPATH}/src/${BEAT_PATH}/${BEAT_NAME}.template-es${VERSION}.json -file ${BEAT_GOPATH}/src/${BEAT_PATH}/fields.yml
go run ${ES_BEATS}/dev-tools/cmd/index_template/index_template.go -index ${BEAT_NAME} -output ${BEAT_GOPATH}/src/${BEAT_PATH}/${BEAT_NAME}.template-es${VERSION}.json -file ${BEAT_GOPATH}/src/${BEAT_PATH}/fields.yml -es.version=${VERSION}

### KIBANA FILES HANDLING ###
ES_URL?=http://localhost:9200
Expand Down
4 changes: 2 additions & 2 deletions libbeat/template/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type TemplateConfig struct {
Name string `config:"name"`
Fields string `config:"fields"`
Overwrite bool `config:"overwrite"`
Settings templateSettings `config:"settings"`
Settings TemplateSettings `config:"settings"`
OutputToFile OutputToFile `config:"output_to_file"`
}

Expand All @@ -16,7 +16,7 @@ type OutputToFile struct {
Version string `config:"version"`
}

type templateSettings struct {
type TemplateSettings struct {
Index map[string]interface{} `config:"index"`
Source map[string]interface{} `config:"_source"`
}
Expand Down
10 changes: 5 additions & 5 deletions libbeat/template/load_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestLoadTemplate(t *testing.T) {
fieldsPath := absPath + "/fields.yml"
index := "testbeat"

tmpl, err := New(version.GetDefaultVersion(), client.GetVersion(), index, templateSettings{})
tmpl, err := New(version.GetDefaultVersion(), client.GetVersion(), index, TemplateSettings{})
assert.NoError(t, err)
content, err := tmpl.Load(fieldsPath)
assert.NoError(t, err)
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestLoadBeatsTemplate(t *testing.T) {
fieldsPath := absPath + "/fields.yml"
index := beat

tmpl, err := New(version.GetDefaultVersion(), client.GetVersion(), index, templateSettings{})
tmpl, err := New(version.GetDefaultVersion(), client.GetVersion(), index, TemplateSettings{})
assert.NoError(t, err)
content, err := tmpl.Load(fieldsPath)
assert.NoError(t, err)
Expand Down Expand Up @@ -173,7 +173,7 @@ func TestTemplateSettings(t *testing.T) {

fieldsPath := absPath + "/fields.yml"

settings := templateSettings{
settings := TemplateSettings{
Index: common.MapStr{
"number_of_shards": 1,
},
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestOverwrite(t *testing.T) {
config = newConfigFrom(t, TemplateConfig{
Enabled: true,
Fields: absPath + "/fields.yml",
Settings: templateSettings{
Settings: TemplateSettings{
Source: map[string]interface{}{
"enabled": false,
},
Expand All @@ -266,7 +266,7 @@ func TestOverwrite(t *testing.T) {
Enabled: true,
Overwrite: true,
Fields: absPath + "/fields.yml",
Settings: templateSettings{
Settings: TemplateSettings{
Source: map[string]interface{}{
"enabled": false,
},
Expand Down
4 changes: 2 additions & 2 deletions libbeat/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ type Template struct {
index string
beatVersion Version
esVersion Version
settings templateSettings
settings TemplateSettings
}

// New creates a new template instance
func New(beatVersion string, esVersion string, index string, settings templateSettings) (*Template, error) {
func New(beatVersion string, esVersion string, index string, settings TemplateSettings) (*Template, error) {

bV, err := NewVersion(beatVersion)
if err != nil {
Expand Down

0 comments on commit 8ba93a7

Please sign in to comment.