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

Fix OutputPrecision in kibana-index-generation script. #5318

Merged
merged 1 commit into from
Oct 4, 2017
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
2 changes: 1 addition & 1 deletion libbeat/common/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Field struct {
Pattern string `config:"pattern"`
InputFormat string `config:"input_format"`
OutputFormat string `config:"output_format"`
OutputPrecision string `config:"output_precision"`
OutputPrecision *int `config:"output_precision"`
LabelTemplate string `config:"label_template"`
UrlTemplate string `config:"url_template"`

Expand Down
2 changes: 1 addition & 1 deletion libbeat/kibana/index_pattern_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func testGenerate(t *testing.T, beatDir string, tests []map[string]string) {
for _, e := range fieldsExisting {
idx := find(fieldsCreated, e["name"].(string))
assert.NotEqual(t, -1, idx)
assert.Equal(t, fieldsCreated[idx], e)
assert.Equal(t, e, fieldsCreated[idx])
}
}
}
Expand Down
24 changes: 17 additions & 7 deletions libbeat/kibana/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ func transformField(f common.Field) (common.MapStr, common.MapStr) {

if f.Format != "" {
format["id"] = f.Format
addFormatParam(&format, "inputFormat", f.InputFormat)
addFormatParam(&format, "outputFormat", f.OutputFormat)
addFormatParam(&format, "outputPrecision", f.OutputPrecision)
addFormatParam(&format, "labelTemplate", f.LabelTemplate)
addFormatParam(&format, "urlTemplate", f.UrlTemplate)
addStringFormatParam(&format, "inputFormat", f.InputFormat)
addStringFormatParam(&format, "outputFormat", f.OutputFormat)
addIntPFormatParam(&format, "outputPrecision", f.OutputPrecision)
addStringFormatParam(&format, "labelTemplate", f.LabelTemplate)
addStringFormatParam(&format, "urlTemplate", f.UrlTemplate)
}
addFormatParam(&format, "pattern", f.Pattern)
addStringFormatParam(&format, "pattern", f.Pattern)
}

return field, format
Expand Down Expand Up @@ -159,7 +159,7 @@ func getVal(valP *bool, def bool) bool {
return def
}

func addFormatParam(f *common.MapStr, key string, val string) {
func addStringFormatParam(f *common.MapStr, key string, val string) {
if val == "" {
return
}
Expand All @@ -169,6 +169,16 @@ func addFormatParam(f *common.MapStr, key string, val string) {
(*f)["params"].(common.MapStr)[key] = val
}

func addIntPFormatParam(f *common.MapStr, key string, valP *int) {
if valP == nil {
return
}
if (*f)["params"] == nil {
(*f)["params"] = common.MapStr{}
}
(*f)["params"].(common.MapStr)[key] = *valP
}

var (
typeMapping = map[string]string{
"half_float": "number",
Expand Down
5 changes: 3 additions & 2 deletions libbeat/kibana/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func TestTransformMisc(t *testing.T) {
}

func TestTransformFieldFormatMap(t *testing.T) {
precision := 3
tests := []struct {
commonField common.Field
expected common.MapStr
Expand Down Expand Up @@ -289,7 +290,7 @@ func TestTransformFieldFormatMap(t *testing.T) {
Pattern: "[^-]",
InputFormat: "string",
OutputFormat: "float",
OutputPrecision: "3",
OutputPrecision: &precision,
LabelTemplate: "lblT",
UrlTemplate: "urlT",
},
Expand All @@ -300,7 +301,7 @@ func TestTransformFieldFormatMap(t *testing.T) {
"pattern": "[^-]",
"inputFormat": "string",
"outputFormat": "float",
"outputPrecision": "3",
"outputPrecision": 3,
"labelTemplate": "lblT",
"urlTemplate": "urlT",
},
Expand Down