Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Remove '$' from field syntax #364

Merged

Conversation

djaglowski
Copy link
Member

@djaglowski djaglowski commented Feb 2, 2022

This is a possible resolution to #164. This would be a major breaking change, so if accepted, the timing of a merge should be considered carefully.


This library has a construct called 'field', which has the
purpose of providing a concise way to refer to values in a
log record. The special symbol $ has been used in key
words that refer to top level fields in the log record.
i.e. $body, $attributes, $resource

Additionally, some shorthand notion was supported. Notably,
$.foo and .foo were equivalent to $body.foo.

This change proposes to remove the usage of $ in field syntax.
The main idea here is that all usages of field syntax MUST
begin with a key word i.e. body, attributes, resource.
With this requirement built in, there is no need to differentiate
between top level fields and arbitrary keys. The distinction is
implicit because the first word is always a top level field and
the remainder are arbitrary nested keys.

@codecov
Copy link

codecov bot commented Feb 2, 2022

Codecov Report

Merging #364 (81157ca) into main (a523052) will increase coverage by 0.0%.
The diff coverage is 97.2%.

Impacted file tree graph

@@          Coverage Diff          @@
##            main    #364   +/-   ##
=====================================
  Coverage   75.2%   75.3%           
=====================================
  Files         83      83           
  Lines       4033    4036    +3     
=====================================
+ Hits        3035    3041    +6     
+ Misses       696     694    -2     
+ Partials     302     301    -1     
Impacted Files Coverage Δ
operator/transformer/remove/rootable_field.go 62.5% <ø> (ø)
entry/field.go 95.1% <66.6%> (-2.5%) ⬇️
entry/attribute_field.go 100.0% <100.0%> (ø)
entry/body_field.go 100.0% <100.0%> (ø)
entry/resource_field.go 100.0% <100.0%> (ø)
operator/helper/expr_string.go 86.4% <100.0%> (ø)
operator/transformer/flatten/flatten.go 62.9% <100.0%> (ø)
operator/transformer/retain/retain.go 81.0% <100.0%> (ø)
operator/transformer/recombine/recombine.go 77.7% <0.0%> (+2.0%) ⬆️
... and 1 more

@djaglowski djaglowski marked this pull request as ready for review February 2, 2022 18:03
@djaglowski djaglowski requested review from a team and jsirianni February 2, 2022 18:03
@djaglowski
Copy link
Member Author

@jsirianni, @pmm-sumo, @rockb1017, please take a look. Any reservations on this approach?

@tigrannajaryan
Copy link
Member

@dmitryax please have a look. Will our helm chart be affected by this change?

@tigrannajaryan
Copy link
Member

The change looks good to me. The syntax becomes clearer.

I do not see any downsides to this change, are there any?

@pmm-sumo
Copy link

pmm-sumo commented Feb 8, 2022

This is a large set of changes, I agree it improves the syntax actually. I asked @pmalek-sumo for another look as well (he was commenting on the issue)

@djaglowski
Copy link
Member Author

The change looks good to me. The syntax becomes clearer.

I do not see any downsides to this change, are there any?

I don't see any downsides either.

Copy link
Contributor

@pmalek-sumo pmalek-sumo left a comment

Choose a reason for hiding this comment

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

I like the idea of making it more explicit and easier to reason about.

🚀 some nits in .md tables

docs/operators/k8s_event_input.md Outdated Show resolved Hide resolved
docs/operators/json_parser.md Outdated Show resolved Hide resolved
docs/operators/journald_input.md Outdated Show resolved Hide resolved
docs/operators/generate_input.md Outdated Show resolved Hide resolved
@dmitryax
Copy link
Member

dmitryax commented Feb 8, 2022

@dmitryax please have a look. Will our helm chart be affected by this change?

It will be affected, but we can adopt for this change.

I like the proposal. The syntax seems cleaner now

djaglowski and others added 2 commits March 11, 2022 16:25
@djaglowski djaglowski force-pushed the field-syntax-without-symbol branch from d5013f8 to 3f42492 Compare March 11, 2022 21:26
@djaglowski
Copy link
Member Author

The contrib test failures are expected due to them using fields that are implicitly body fields.

Copy link
Member

@dmitryax dmitryax left a comment

Choose a reason for hiding this comment

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

LGTM, but shouldn't we throw deprecation warnings in logs?

@djaglowski
Copy link
Member Author

LGTM, but shouldn't we throw deprecation warnings in logs?

Unfortunately, there's not a great way to complain about the deprecated usage because it is processed during unmarshaling, where we don't have a handle to a logger. We could add a flag to the Field struct, set it during unmarshaling, and then log every time the field is used in the pipeline, but this seems overkill to me. In my opinion, logging about deprecations is a nice-to-have feature and probably not worth any substantial code changes to do it. If you feel strongly though, I can make the above change, or perhaps you see a better way that I missed.

Another option is to fully remove support, but to detect the old syntax and return a clear error. This forces migration immediately, but at least would not be ambiguous at all.

@dmitryax
Copy link
Member

dmitryax commented Mar 16, 2022

Maybe we can drop the old interface support here but do all the necessary translation from the deprecated format in the collector-contrib? There we can throw all the warnings during the translation.

@djaglowski
Copy link
Member Author

Unfortunately, I don't think unmarshaling in collector-contrib gives us a better opportunity to do this.

@djaglowski
Copy link
Member Author

@dmitryax, can you clarify whether you see the lack of deprecation warning as a blocker?

I do not see a good way to log warnings here or at the collector level, so I would prefer to either error or quietly support the old syntax.

@dmitryax
Copy link
Member

What if we return an error of a DeprecationError type from unmarshal functions? Then contrib can look for that error and throw a warning message to the output with everything else working as usual.

@djaglowski
Copy link
Member Author

What if we return an error of a DeprecationError type from unmarshal functions? Then contrib can look for that error and throw a warning message to the output with everything else working as usual.

I liked this idea and gave it a shot, but unfortunately, the yaml library does not appear to allow for partial failures like this. Any error returned ultimately triggers a call to fail.

@dmitryax
Copy link
Member

I see, if it's not possible to show a warning, I don't think silently support both versions is useful. Changing the interface right away seems to be a better option then.

@djaglowski djaglowski merged commit fd659de into open-telemetry:main Mar 24, 2022
@djaglowski djaglowski deleted the field-syntax-without-symbol branch March 24, 2022 13:46
jsirianni pushed a commit to jsirianni/opentelemetry-log-collection that referenced this pull request Mar 28, 2022
* Remove '$' from field syntax

* Enforce rule that body fields must start with 'body'
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants