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

[pkg/ottl] Add InsertXML Converter #35436

Merged
merged 1 commit into from
Sep 30, 2024

Conversation

djaglowski
Copy link
Member

@djaglowski djaglowski commented Sep 26, 2024

This simple converter allows a basic form of XML document modification. Aside from the obvious, this can be used to disambiguate elements which should be members of a slice when parsed by the proposed ParseSimplifiedXML.

To illustrate this, consider how you would expect the following two documents to parse:

<Files>
   <File>foo.txt</File>
</Files>
<Files>
   <File>foo.txt</File>
   <File>bar.txt</File>
</Files>

The second document can clearly be understood as a slice of File elements:

Files:
  - File: foo.txt
  - File: bar.txt

but the first document could be misunderstood as a map where File is a unique key:

Files:
  File: foo.txt

That is, there is no way to infer the schema from a single example. However, by adding an empty File element, we can disambiguate the schema.

<Files>
   <File>foo.txt</File>
   <File/>
</Files>

Many users will not care about this detail but for those who need the schema to be interpreted consistently, this mechanism provides a solution. Note that in the proposed ParseSimplifyXML converter, empty elements without text content are dropped, since they would be keys without values in a map.

See #35281

@djaglowski
Copy link
Member Author

I converted this back to a draft because I think there is a way to better generalize this. Rather than providing just a string to name the element, we should be able to accept any valid XML document and insert it in the same way.

@djaglowski djaglowski changed the title [pkg/ottl] Add AddElementXML Converter [pkg/ottl] Add InsertXML Converter Sep 26, 2024
@djaglowski djaglowski changed the base branch from ottl-add-element-xml to main September 26, 2024 16:55
@djaglowski djaglowski merged commit 36733ce into open-telemetry:main Sep 30, 2024
158 checks passed
@github-actions github-actions bot added this to the next release milestone Sep 30, 2024
@djaglowski djaglowski deleted the ottl-add-element-xml branch September 30, 2024 19:23
jriguera pushed a commit to springernature/opentelemetry-collector-contrib that referenced this pull request Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants