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

feat: clean up lint.sh, use API to set grpc layer #467

Merged
merged 6 commits into from
Mar 15, 2021

Conversation

TommyCpp
Copy link
Contributor

@TommyCpp TommyCpp commented Mar 4, 2021

  • As per Remove tracer provider guard. #444 (comment).
    We should try to throw compile errors when users set two exclusive features instead of default to use one of them.
  • Added a precommit.sh to run fmt, clippy and test
  • Clean up the lint.sh a little bit. Haven't worked with Bash for a while so please let me know if something doesn't look right.

@TommyCpp TommyCpp force-pushed the tommycpp/exclusive-features branch from 3bb9b97 to cef5eea Compare March 4, 2021 03:17
@TommyCpp TommyCpp marked this pull request as ready for review March 4, 2021 03:17
@TommyCpp TommyCpp requested a review from a team March 4, 2021 03:17
@djc
Copy link
Contributor

djc commented Mar 4, 2021

IMO making features non-additive is frowned upon in the ecosystem. Perhaps we could do it as part of the tests to flush out issues in our test suite, but I don't think we should intentionally start doing this for our published libraries.

@frigus02
Copy link
Member

frigus02 commented Mar 4, 2021

IMO making features non-additive is frowned upon in the ecosystem. Perhaps we could do it as part of the tests to flush out issues in our test suite, but I don't think we should intentionally start doing this for our published libraries.

I'm not super happy with this, either. If I understand correctly, the features are already mutually exclusive, though. At the moment we just silently ignore one of the features if the other one is enabled. I would prefer a helpful error message instead.

That said, I'm still undecided if it would be better to configure these things at runtime.


The scripts look fine to me. I think a trailing newline might be nice. I think that's common for shell scripts, too.

@TommyCpp
Copy link
Contributor Author

TommyCpp commented Mar 4, 2021

I think the real problems I would like to solve is how do we tell user that featureA and featureB is exclusive and should only enable one of them. Some of our crates have complex features. For example, in opentelemetry-otlp we have following features.

async = ["default"]
trace = ["opentelemetry/trace"]
metrics = ["opentelemetry/metrics"]
default = ["tonic", "tonic-build", "prost", "tokio"]
grpc-sys = ["grpcio", "protobuf", "protobuf-codegen", "protoc-grpcio"]
tls = ["tonic/tls"]
tls-roots = ["tls", "tonic/tls-roots"]
openssl = ["grpcio/openssl"]
openssl-vendored = ["grpcio/openssl-vendored"]
integration-testing = ["tonic", "tonic-build", "prost", "tokio/full", "opentelemetry/trace"]

This basically comes down to four choices.

  • Is it trace or metrics.
  • If it's trace, for grpc layer, is it tonic or grpcio.
  • Is it tls/ssl or not encrypted
  • Different choice on how to encrypted.

But I don't think it's trivial to understand how to choose between those features without some knowledge of the implementation.

@djc
Copy link
Contributor

djc commented Mar 4, 2021

trace or metrics doesn't have to be an either/or choice, or does it?

I made a change in hyper-rustls which removed the compiler error on feature conflict in favor of having the API be explicit about which feature to prefer. rustls/hyper-rustls@fc60b8c I think this is probably the best way to do it if possible, though I don't quite understand why the grpc vs tonic features (for example) necessarily/naturally conflict.

@TommyCpp
Copy link
Contributor Author

TommyCpp commented Mar 5, 2021

trace or metrics doesn't have to be an either/or choice, or does it?

Sorry those two are not mutually exclusive. 🤦‍♂️

Thanks for the example! I think it could be a good approach.

though I don't quite understand why the grpc vs tonic features (for example) necessarily/naturally conflict.

I think it's mostly because we have different ways to build the client based on different grpc layers. But I will try to poke around to see if we can use the API to separate those two features.

@TommyCpp TommyCpp marked this pull request as draft March 6, 2021 16:47
@TommyCpp
Copy link
Contributor Author

TommyCpp commented Mar 6, 2021

Still need to add docs, change tests and fix small nits. But my general idea for this crate is to use an enum to represent different grpc layers.

The reason for not using trait is that the trace exporter here has two tasks,

  • convert the otel spans into otlp format
  • send it via grpc.

In our current implementation, tonic and grpcio take different approaches in both of those tasks. It's hard to abstract the behavior as it involves a lot of sturcts like Spans, Links, etc.

If users want to bring their own grpc layer, they can just implement a new tracer exporter with SpanExporter trait and install it.

@TommyCpp TommyCpp force-pushed the tommycpp/exclusive-features branch 3 times, most recently from 9a350b6 to b2a5540 Compare March 6, 2021 21:33
@TommyCpp TommyCpp changed the title feat: clean up lint.sh, make sure exclusive features don't set at the same time feat: clean up lint.sh, use API to set grpc layer Mar 6, 2021
@djc djc mentioned this pull request Mar 8, 2021
TommyCpp added 3 commits March 8, 2021 19:30
… same time.

As per open-telemetry#444 (comment).

We should try to throw compile error when users set two exclusive features instead of default to use one of them.
The TracerExporter basically have two tasks. The first one is convert OTEL trace to binary, the second one is send it.

`tonic` and `grpcio` take different approaches in both of those two tasks. Thus, we use enum here to represent two different grpc layers. If user want to bring their own grpc layer. They can just implement a new TracerExporter with SpanExporter trait and install it.
@TommyCpp TommyCpp force-pushed the tommycpp/exclusive-features branch from b2a5540 to 685c26b Compare March 9, 2021 00:33
@TommyCpp TommyCpp marked this pull request as ready for review March 9, 2021 03:07
@frigus02
Copy link
Member

frigus02 commented Mar 9, 2021

I'm still on the fence between cargo features and setting things up at runtime. Since cargo doesn't have a way of describing that features are mutually exclusive, I'm leaning slightly towards the setup in Rust code at runtime.

This looks quite nice to me. Didn't see anything worth commenting on. 👍

Do you want to update docs/tests/etc in this PR?

Copy link
Contributor

@djc djc left a comment

Choose a reason for hiding this comment

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

I think the API-based approach works out pretty well, I especially like the builder setup.

Comment on lines +128 to +130
#[cfg(
not(feature = "integration-testing")
)]
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks a little odd?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the idea is to hide the proto mod unless we are running integrationt testing.

not(feature = "integration-testing")
))]
#[allow(clippy::all, unreachable_pub, dead_code)]
#[allow(warnings)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we allowing all the warnings here? Maybe add a comment about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly because the proto mod only contains generated code. We should change it.

scripts/lint.sh Outdated
cargo_feature opentelemetry-jaeger "reqwest_collector_client"
cargo_feature opentelemetry-jaeger "collector_client"

fi
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: add a newline?

@TommyCpp TommyCpp requested a review from djc March 11, 2021 23:52
Copy link
Member

@jtescher jtescher left a comment

Choose a reason for hiding this comment

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

LGTM @djc is this good to merge or do you have additional feedback?

@djc
Copy link
Contributor

djc commented Mar 15, 2021

LGTM. @TommyCpp, good work!

@jtescher jtescher merged commit e9ef3e2 into open-telemetry:main Mar 15, 2021
TommyCpp added a commit to TommyCpp/opentelemetry-rust that referenced this pull request Mar 17, 2021
…nc feature is not set.

This was introduced in open-telemetry#467. I believe the async feature was there to spin up a tokio runtime if the exporter was not already in one. It's mostly because the tonic cannot work without a tokio runtime.

Renamed the feature to be less confusing.

Also clean up all the clippy problems in metrics module and add some links into doc.
TommyCpp added a commit to TommyCpp/opentelemetry-rust that referenced this pull request Mar 17, 2021
…nc feature is not set.

This was introduced in open-telemetry#467. I believe the async feature was there to spin up a tokio runtime if the exporter was not already in one. It's mostly because the tonic cannot work without a tokio runtime.

Renamed the feature to be less confusing.

Also clean up all the clippy problems in metrics module and add some links into doc.
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.

None yet

4 participants