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

Refactoring trace_state to reuse common functionality in baggage #638

Merged
merged 6 commits into from
Apr 5, 2021

Conversation

nikhil1511
Copy link
Contributor

@nikhil1511 nikhil1511 commented Mar 29, 2021

Related to #79

  • Refactoring trace_state code to reuse functionality in baggage implementation
  • Extracting out common parsing logic from trace_state into kv_properties

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@nikhil1511 nikhil1511 requested a review from a team March 29, 2021 18:49
@nikhil1511 nikhil1511 changed the title Refactoring trace_state to reuse common part in baggage Refactoring trace_state to reuse common functionality in baggage Mar 29, 2021
@codecov
Copy link

codecov bot commented Mar 29, 2021

Codecov Report

Merging #638 (c93764d) into main (2181b01) will increase coverage by 0.15%.
The diff coverage is 99.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #638      +/-   ##
==========================================
+ Coverage   94.51%   94.66%   +0.15%     
==========================================
  Files         199      203       +4     
  Lines        9136     9322     +186     
==========================================
+ Hits         8635     8825     +190     
+ Misses        501      497       -4     
Impacted Files Coverage Δ
api/include/opentelemetry/trace/trace_state.h 97.59% <96.36%> (+0.04%) ⬆️
api/include/opentelemetry/common/kv_properties.h 98.80% <98.80%> (ø)
api/include/opentelemetry/common/string_util.h 100.00% <100.00%> (ø)
api/test/common/kv_properties_test.cc 100.00% <100.00%> (ø)
api/test/common/string_util_test.cc 100.00% <100.00%> (ø)
api/test/trace/trace_state_test.cc 100.00% <100.00%> (+2.22%) ⬆️
... and 3 more

if (list_member.size() == 0)
{
// empty list member. Move to next entry. For both baggage and trace_state this is valid
// behaviour.
Copy link
Member

Choose a reason for hiding this comment

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

nit - as this tokenizer class is not just for baggage and trace_state, we can remove comment specific to them. Or perhaps add flag whether to skip empty entries ( with default as true ) ?

Copy link
Contributor Author

@nikhil1511 nikhil1511 Mar 31, 2021

Choose a reason for hiding this comment

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

Makes sense, I will update the comment. About the flag, I am not sure if we will need this parsing at many places, so thought of not making it too generic.
If we go ahead with the flag approach, do you think we should have that as part of tokenizer's constructor (I feel flag will be same for all next calls) ? In that case we can probably create TokenizerConfigOption struct to be passed to the constructor.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I actually meant this flag for constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added flag

{

// Iterator for key-value headers
class KeyValueStringIterator
Copy link
Member

Choose a reason for hiding this comment

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

change class name to KeyValueStringTokenizer taking inspiration from strtok function in C ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed

api/include/opentelemetry/trace/trace_state.h Outdated Show resolved Hide resolved
@@ -5,3 +5,25 @@ otel_cc_benchmark(
srcs = ["spinlock_benchmark.cc"],
deps = ["//api"],
)

cc_test(
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding the tests to CMake build script as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@lalitb lalitb requested a review from pyohannes April 1, 2021 17:42
{
first = false;
}
header_s.append(std::string(key));
Copy link
Member

Choose a reason for hiding this comment

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

This is probably my mistake - but I don't think this conversion (nostd::string_view to std::string) will work properly always (eg if key contains end of line character). As C++11 std::string constructor won't accept std::string_view type. Better to use proper conversion : https://stackoverflow.com/questions/59424390/how-to-correctly-create-stdstring-from-a-stdstring-view

}
header_s.append(std::string(key));
header_s.append(1, kKeyValueSeparator);
header_s.append(std::string(value));
Copy link
Member

Choose a reason for hiding this comment

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

Need to check this conversion in other places too

@@ -7,58 +21,14 @@ namespace
{

using opentelemetry::trace::TraceState;
namespace nostd = opentelemetry::nostd;
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its used in the newly added tests (check line 200). I see that there is some inconsistency, at some places opentelemetry::nostd is used and at some nostd is directly used.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest keeping its usage consistent.

Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

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

Thanks for the changes. Looks good to me once we take care of string_view to string conversion. Will wait for feedback from others.

@@ -7,58 +21,14 @@ namespace
{

using opentelemetry::trace::TraceState;
namespace nostd = opentelemetry::nostd;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest keeping its usage consistent.

@lalitb lalitb merged commit afa2e79 into open-telemetry:main Apr 5, 2021
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.

3 participants