Skip to content

WIP TraceZ Processor#5

Closed
jajanet wants to merge 15 commits into
masterfrom
zpages-tracez-processor1
Closed

WIP TraceZ Processor#5
jajanet wants to merge 15 commits into
masterfrom
zpages-tracez-processor1

Conversation

@jajanet
Copy link
Copy Markdown
Collaborator

@jajanet jajanet commented Jul 6, 2020

Progress includes:

  1. Processor code, which interfaces with the original code and has working added methods relevant to TraceZ. Notably, the methods hold running spans and newly completed spans (completed spans that have been sent before are cleared)
  2. Comprehensive tests that test the functionality described above in different scenarios, including for cumulative and non-cumulative situations. Checking individual span information has been temporary commented out.
  3. Bazel and CMake build files

@jajanet jajanet changed the title Consolidate tracez processor changes WIP TraceZ Processor Jul 6, 2020
@jajanet jajanet requested review from kmanghat and liadavid July 6, 2020 21:37
* Shut down the processor and do any cleanup required. Ended spans are
* exported before shutdown. After the call to Shutdown, subsequent calls to
* OnStart, OnEnd, ForceFlush or Shutdown will return immediately without
* doing anything.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should there be a flag to signal if Shutdown is called so it can exit early in those functions?

Would it be better to throw an exception if any of those are called after Shutdown is called?

Copy link
Copy Markdown
Collaborator Author

@jajanet jajanet Jul 7, 2020

Choose a reason for hiding this comment

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

Yeah I can add that, thanks!! I also made the functions return immediately instead, based on the doc comments

completed_spans_.push_back(std::move(span));
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

One option is to collapse these two functions into one, and return some struct that bundles copies of the running and completed spans together.

struct RunningAndCompletedSpans {
  <> running_spans_;
  <> completed_spans_;
};

RunningAndCompletedSpans GetRunningAndCompletedSpansSnapshot() noexcept {
  auto completed_spans = std::move(completed_spans_);
  completed_spans.clear();
  return {std::unordered_set<Recordable*>(running_spans_), completed_spans};
}

Something like that, that way it'll just give the Aggregator a consistent view while it's aggregating the spans.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Okay, that sounds good! I should replace the running and completed getters in favor of returning them all, since the main goal is giving this information in a consistent manner and the aggregator should change its methods accordingly?


private:
std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> exporter_;
std::unordered_set<opentelemetry::sdk::trace::Recordable*> running_spans_;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is the TraceZProcessor supposed to be a thread-safe class (do multiple threads share a single TraceZProcessor, or do they all have their own)?

Copy link
Copy Markdown
Collaborator Author

@jajanet jajanet Jul 7, 2020

Choose a reason for hiding this comment

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

I think it's supposed to be thread-safe and hypothetical threads could share a single processor if I'm looking the spec correctly https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#interface-definition

I believe usually reading and writing spans in storage would be in the exporter, so adding thread safety isn't a mentioned for the processor and we would need it?

Copy link
Copy Markdown
Collaborator

@liadavid liadavid left a comment

Choose a reason for hiding this comment

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

Looks good, Nice tests! Some small comments.


/**
* Initialize a span processor.
* @param exporter the exporter used by the span processor. Here, the purpose
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: Remove 'exporter' comment

explicit TracezSpanProcessor() noexcept {}

/**
* Create a span recordable using the associated exporter.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: Update comment



/*
* Helper function to create a processor when the type of exporter doesn't
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: remove exporter



/*
* Helper function uses the current processor tov update spans contained in completed_spans
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: typo: tov -> to

completed.clear();
completed = std::move(spans.completed);
}
else {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: It should be:
if () {
...
} else {
...
}

See: https://google.github.io/styleguide/cppguide.html#Conditionals

TEST(TracezSpanProcessor, NoSpans) {
auto processor = MakeProcessor();
auto spans = processor->GetSpanSnapshot();
auto recordable = processor->MakeRecordable();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

'recordable' is not used here.

namespace zpages
{
/**
* The span processor passes finished recordables to an exporter and is
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please update comment

* @return snapshot of all currently running spans and newly completed spans
* at the time that the function is called
*/
CollectedSpans GetSpanSnapshot() noexcept;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Worth adding a TODO: Verify/handle a case when GetSnapshot is called when spans start/end to run.

This should be covered by copy on write. While we plan to add it, it is good to "declare" that it is our plan.

@jajanet
Copy link
Copy Markdown
Collaborator Author

jajanet commented Jul 8, 2020

See WIP PR for the main repo: open-telemetry#164

@jajanet jajanet closed this Jul 8, 2020
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