Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Keep empty fields for fields validation, but not for documentation
  • Loading branch information
jsoriano committed Jul 3, 2023
commit d817ab63cd7c1978b56b39ef182e381362c7b5cf
4 changes: 4 additions & 0 deletions internal/docs/exported_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func renderExportedFields(fieldsParentDir string) (string, error) {
// Keep External parameter when rendering fields, so we can render
// documentation for empty groups imported from ECS, for backwards compatibility.
KeepExternal: true,
Copy link
Member Author

@jsoriano jsoriano Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parameter for fields injection can be a bit difficult to follow. Its only purpose is to mimic a collateral behaviour we had with lazy resolution of external fields: In some places we were skipping group fields when they were empty. But this was not happening with external fields, because on these checks the field was still unresolved.

We may argue that this behaviour is unexpected and we should fix it instead, because it treats fields on different ways depending if they are external or not. But fixing this would break CI builds of packages, because it changes what fields are rendered.

This flag helps keeping the old behaviour for rendered documentation:

  • When rendering documentation, we keep external, so we can keep the old behaviour.
  • In other cases, such as when resolving external fields in package builds, we remove the "external" parameter once the field is injected, so it is not written to fields files. On these cases we may be removing empty groups from built fields files, but this is actually good because they don't generate any meaningful mapping.


// SkipEmptyFields parameter when rendering fields. In other cases we want to
// keep them to accept them for validation.
SkipEmptyFields: true,
}
validator, err := fields.CreateValidatorForDirectory(fieldsParentDir, fields.WithInjectFieldsOptions(injectOptions))
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion internal/fields/dependency_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ type InjectFieldsOptions struct {
// in previous versions on lazy resolution of external fields.
KeepExternal bool

// SkipEmptyFields can be set to true to skip empty groups when injecting fields.
SkipEmptyFields bool

root string
}

Expand Down Expand Up @@ -210,7 +213,7 @@ func (dm *DependencyManager) injectFieldsWithOptions(defs []common.MapStr, optio
}
}

if skipField(def) {
if options.SkipEmptyFields && skipField(def) {
continue
}
updated = append(updated, def)
Expand Down