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

Allow to override ECS fields type from keyword to constant_keyword #969

Merged
merged 1 commit into from
Sep 12, 2022
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
7 changes: 6 additions & 1 deletion internal/fields/dependency_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,14 @@ func (dm *DependencyManager) injectFieldsWithRoot(root string, defs []common.Map

// Allow overrides of everything, except the imported type, for consistency.
transformed.DeepUpdate(def)
transformed["type"] = imported.Type
transformed.Delete("external")

// Allow to override the type only from keyword to constant_keyword,
// to support the case of setting the value already in the mappings.
if ttype, _ := transformed["type"].(string); ttype != "constant_keyword" || imported.Type != "keyword" {
transformed["type"] = imported.Type
}

def = transformed
changed = true
} else {
Expand Down
26 changes: 26 additions & 0 deletions internal/fields/dependency_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,27 @@ func TestDependencyManagerInjectExternalFields(t *testing.T) {
changed: true,
valid: true,
},
{
title: "keyword to constant_keyword override",
defs: []common.MapStr{
{
"name": "event.dataset",
"type": "constant_keyword",
"external": "test",
"value": "nginx.access",
},
},
result: []common.MapStr{
{
"name": "event.dataset",
"type": "constant_keyword",
"description": "Dataset that collected this event",
"value": "nginx.access",
},
},
changed: true,
valid: true,
},
{
title: "external dimension",
defs: []common.MapStr{
Expand Down Expand Up @@ -362,6 +383,11 @@ func TestDependencyManagerInjectExternalFields(t *testing.T) {
Description: "Data stream dataset.",
Type: "constant_keyword",
},
{
Name: "event.dataset",
Description: "Dataset that collected this event",
Type: "keyword",
},
{
Name: "process.command_line",
Description: "Full command line that started the process.",
Expand Down