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

Expose non-nullable elements from slices of pointers #2200

Merged
merged 1 commit into from
Dec 1, 2020

Conversation

bogdandrutu
Copy link
Member

@bogdandrutu bogdandrutu commented Nov 21, 2020

Currently for slices of pointers, pdata exposes elements that are pointers to the pointer in the slice (double pointers in the internal implementation). Because of this users have to deal with possible nil values, have to initialize elements (in some cases) etc, but in reality the elements in the slice cannot be nil, so this just adds extra unnecessary complexity. This is possible because:

  • Gogo proto (and protobuf) will not unmarshal any nil element in a slice;
  • Current APIs to add elements/remove elements from the slice (e.g. Resize or Append) will guarantee that we never have a nil element in the slice between [0, len-1]; For Append by not allowing to create nil messages, we always append non-nil elements to the slice.

This is an important change because will allow us to change the internal representation (use slice of pointers or non-pointers) without affecting the public API.

Signed-off-by: Bogdan Drutu bogdandrutu@gmail.com

@codecov
Copy link

codecov bot commented Nov 21, 2020

Codecov Report

Merging #2200 (4eeb597) into master (14047fd) will increase coverage by 0.17%.
The diff coverage is 98.90%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2200      +/-   ##
==========================================
+ Coverage   91.97%   92.15%   +0.17%     
==========================================
  Files         271      271              
  Lines       15656    15269     -387     
==========================================
- Hits        14400    14071     -329     
+ Misses        854      824      -30     
+ Partials      402      374      -28     
Impacted Files Coverage Δ
consumer/pdata/generated_common.go 100.00% <ø> (ø)
consumer/pdata/generated_resource.go 100.00% <ø> (ø)
consumer/pdata/log.go 100.00% <ø> (ø)
consumer/pdata/trace.go 97.22% <ø> (-0.34%) ⬇️
consumer/simple/metrics.go 98.71% <ø> (-0.07%) ⬇️
internal/goldendataset/metric_gen.go 100.00% <ø> (ø)
processor/attributesprocessor/attributes_log.go 100.00% <ø> (ø)
processor/attributesprocessor/attributes_trace.go 100.00% <ø> (+9.09%) ⬆️
processor/batchprocessor/splittraces.go 96.42% <ø> (-0.24%) ⬇️
processor/filterprocessor/metric_index.go 100.00% <ø> (ø)
... and 29 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 14047fd...4eeb597. Read the comment docs.

@bogdandrutu bogdandrutu changed the title Expose non-nullable elements from slices to pointers Expose non-nullable elements from slices of pointers Nov 30, 2020
@bogdandrutu bogdandrutu force-pushed the notnilslice branch 6 times, most recently from 0acc0f3 to e0d2934 Compare November 30, 2020 18:02
@tigrannajaryan
Copy link
Member

I do not quite understand the change. I see that you removed one level of indirection from the wrappers, but it is still not quite clear to me. Can you add a bit more details to the description?

@bogdandrutu
Copy link
Member Author

@tigrannajaryan PTAL, tried one more time :)

Copy link
Member

@tigrannajaryan tigrannajaryan left a comment

Choose a reason for hiding this comment

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

Mostly LGTM. Good change.

consumer/pdata/generated_log.go Outdated Show resolved Hide resolved
proto_patch.sed Show resolved Hide resolved
Currently for slices of pointers, pdata exposes elements that are pointers to the pointer in the slice (double pointers in the internal implementation). Because of this users have to deal with possible nil values, have to initialize elements (in some cases) etc, but in reality the elements in the slice cannot be nil, so this just adds extra unnecessary complexity. This is possible because:

* Gogo proto (and protobuf) will not unmarshal any nil element in a slice;
* Our APIs to add elements/remove elements from the slice will guarantee that we never have a nil element in the slice between [0, len-1];

This is an important change because will allow us to change the internal representation (use slice of pointers or non-pointers) without affecting the public API.

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
@bogdandrutu
Copy link
Member Author

@tigrannajaryan PTAL

@bogdandrutu bogdandrutu merged commit f4f68db into open-telemetry:master Dec 1, 2020
@bogdandrutu bogdandrutu deleted the notnilslice branch December 1, 2020 18:50
tigrannajaryan added a commit to tigrannajaryan/opentelemetry-collector-contrib that referenced this pull request Dec 1, 2020
Troels51 pushed a commit to Troels51/opentelemetry-collector that referenced this pull request Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants