-
Notifications
You must be signed in to change notification settings - Fork 559
Add zPages Tracez Processor #164
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
Merged
reyang
merged 23 commits into
open-telemetry:master
from
kmanghat:zpages-tracez-spanprocessor
Jul 16, 2020
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
27adfde
Clean add of tracez processor files
jajanet 8f3d1bc
Change cmake files
jajanet f106309
adjust cmake files
jajanet 75cb6ee
Fix CMake and test style
jajanet d5d8ed5
Add tests, better test names/docstrings
jajanet f8df6bb
Cast recordable to span_data, fix test formatting
jajanet 8508a00
Add touchups to tests and formatting
jajanet f1f54f0
Change asserts into expects
jajanet 2b1a5b7
Fix OnEnd mem leak, reset flush/shutdown functions
jajanet bc0aaea
Add TODOs for thread safety concerns, update README
jajanet af3b3a7
Make processor more thread-safe with tests
jajanet 7085288
Add missed TODO comment
jajanet 80f04c5
Merge branch 'zpages-tracez-spanprocessor-threading' into zpages-trac…
jajanet 09037be
Fix test thread safety, add test fixtures
jajanet 69a30c9
Adjust import order, spacing
jajanet 466ac2e
Add noop tests for ForceFlush/Shutdown
jajanet d9ba5b3
Move includes, remove README update date
jajanet 0dc7aa6
Order includes alphabetically
jajanet 4c23ec5
Merge remote-tracking branch 'open-telemetry/master' into zpages-trac…
jajanet dde9a4f
Increase span creation numbers
jajanet 649367e
Decrease spans created in thread safety tests
jajanet 7d5182f
Merge remote-tracking branch 'open-telemetry/master' into zpages-trac…
jajanet b7e83b7
Merge branch 'zpages-tracez-spanprocessor' of https://github.com/kman…
jajanet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package(default_visibility = ["//visibility:public"]) | ||
|
|
||
| cc_library( | ||
| name = "headers", | ||
| hdrs = glob(["include/**/*.h"]), | ||
| strip_include_prefix = "include", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| add_subdirectory(src) | ||
|
|
||
| if(BUILD_TESTING) | ||
| add_subdirectory(test) | ||
| endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| #pragma once | ||
|
|
||
| #include <chrono> | ||
| #include <memory> | ||
| #include <mutex> | ||
| #include <unordered_set> | ||
| #include <vector> | ||
| #include <utility> | ||
|
|
||
| #include "opentelemetry/sdk/trace/processor.h" | ||
| #include "opentelemetry/sdk/trace/recordable.h" | ||
| #include "opentelemetry/sdk/trace/span_data.h" | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace ext | ||
| { | ||
| namespace zpages | ||
| { | ||
| /* | ||
| * The span processor passes and stores running and completed recordables (casted as span_data) | ||
| * to be used by the TraceZ Data Aggregator. | ||
| */ | ||
| class TracezSpanProcessor : public opentelemetry::sdk::trace::SpanProcessor { | ||
| public: | ||
|
|
||
| struct CollectedSpans { | ||
| std::unordered_set<opentelemetry::sdk::trace::SpanData*> running; | ||
| std::vector<std::unique_ptr<opentelemetry::sdk::trace::SpanData>> completed; | ||
| }; | ||
|
|
||
| /* | ||
| * Initialize a span processor. | ||
| */ | ||
| explicit TracezSpanProcessor() noexcept {} | ||
|
|
||
| /* | ||
| * Create a span recordable, which is span_data | ||
| * @return a newly initialized recordable | ||
| */ | ||
| std::unique_ptr<opentelemetry::sdk::trace::Recordable> MakeRecordable() noexcept override | ||
| { | ||
| return std::unique_ptr<opentelemetry::sdk::trace::Recordable>(new opentelemetry::sdk::trace::SpanData); | ||
| } | ||
|
|
||
| /* | ||
| * OnStart is called when a span starts; the recordable is cast to span_data and added to running_spans. | ||
| * @param span a recordable for a span that was just started | ||
| */ | ||
| void OnStart(opentelemetry::sdk::trace::Recordable &span) noexcept override; | ||
|
|
||
| /* | ||
| * OnEnd is called when a span ends; that span_data is moved from running_spans to | ||
| * completed_spans | ||
| * @param span a recordable for a span that was ended | ||
| */ | ||
| void OnEnd(std::unique_ptr<opentelemetry::sdk::trace::Recordable> &&span) noexcept override; | ||
|
|
||
| /* | ||
| * Returns a snapshot of all spans stored. This snapshot has a copy of the | ||
| * stored running_spans and gives ownership of completed spans to the caller. | ||
| * Stored completed_spans are cleared from the processor. Currently, | ||
| * copy-on-write is utilized where possible to minimize contention, but locks | ||
| * may be added in the future. | ||
| * @return snapshot of all currently running spans and newly completed spans | ||
| * (spans never sent while complete) at the time that the function is called | ||
| */ | ||
| CollectedSpans GetSpanSnapshot() noexcept; | ||
|
|
||
| /* | ||
| * For now, does nothing. In the future, it | ||
| * may send all ended spans that have not yet been sent to the aggregator. | ||
| * @param timeout an optional timeout, the default timeout of 0 means that no | ||
| * timeout is applied. Currently, timeout does nothing. | ||
| */ | ||
| void ForceFlush( | ||
| std::chrono::microseconds timeout = std::chrono::microseconds(0)) noexcept override {} | ||
|
|
||
| /* | ||
| * Shut down the processor and do any cleanup required, which is none. | ||
| * After the call to Shutdown, subsequent calls to OnStart, OnEnd, ForceFlush | ||
| * or Shutdown will return immediately without doing anything. | ||
| * @param timeout an optional timeout, the default timeout of 0 means that no | ||
| * timeout is applied. Currently, timeout does nothing. | ||
| */ | ||
| void Shutdown(std::chrono::microseconds timeout = std::chrono::microseconds(0)) noexcept override {} | ||
|
|
||
| private: | ||
| mutable std::mutex mtx_; | ||
| CollectedSpans spans_; | ||
| }; | ||
| } // namespace zpages | ||
| } // namespace ext | ||
| OPENTELEMETRY_END_NAMESPACE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| add_subdirectory(zpages) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Copyright 2020, OpenTelemetry Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| package(default_visibility = ["//visibility:public"]) | ||
|
|
||
| cc_library( | ||
| name = "zpages", | ||
| srcs = glob(["**/*.cc"]), | ||
| hdrs = glob(["**/*.h"]), | ||
| include_prefix = "ext/zpages", | ||
| deps = [ | ||
| "//api", | ||
| "//sdk:headers", | ||
| "//ext:headers", | ||
| ], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| add_library(opentelemetry_zpages | ||
| tracez_processor.cc | ||
| ../../include/opentelemetry/ext/zpages/tracez_processor.h) | ||
|
|
||
| target_include_directories(opentelemetry_zpages PUBLIC ../../include) | ||
|
|
||
| target_link_libraries(opentelemetry_zpages opentelemetry_api opentelemetry_trace) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #include "opentelemetry/ext/zpages/tracez_processor.h" | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace ext { | ||
| namespace zpages { | ||
|
|
||
| void TracezSpanProcessor::OnStart(opentelemetry::sdk::trace::Recordable &span) noexcept { | ||
| std::lock_guard<std::mutex> lock(mtx_); | ||
|
jajanet marked this conversation as resolved.
|
||
| spans_.running.insert(static_cast<opentelemetry::sdk::trace::SpanData*>(&span)); | ||
|
jajanet marked this conversation as resolved.
|
||
| } | ||
|
|
||
| void TracezSpanProcessor::OnEnd(std::unique_ptr<opentelemetry::sdk::trace::Recordable> &&span) noexcept { | ||
| if (span == nullptr) return; | ||
| auto span_raw = static_cast<opentelemetry::sdk::trace::SpanData*>(span.get()); | ||
| std::lock_guard<std::mutex> lock(mtx_); | ||
| auto span_it = spans_.running.find(span_raw); | ||
| if (span_it != spans_.running.end()) { | ||
| spans_.running.erase(span_it); | ||
| spans_.completed.push_back( | ||
| std::unique_ptr<opentelemetry::sdk::trace::SpanData>( | ||
| static_cast<opentelemetry::sdk::trace::SpanData*>(span.release()))); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| TracezSpanProcessor::CollectedSpans TracezSpanProcessor::GetSpanSnapshot() noexcept { | ||
| CollectedSpans snapshot; | ||
| std::lock_guard<std::mutex> lock(mtx_); | ||
| snapshot.running = spans_.running; | ||
| snapshot.completed = std::move(spans_.completed); | ||
| spans_.completed.clear(); | ||
| return snapshot; | ||
| } | ||
|
|
||
|
|
||
| } // namespace zpages | ||
| } // namespace ext | ||
| OPENTELEMETRY_END_NAMESPACE | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| add_subdirectory(zpages) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| cc_test( | ||
| name = "tracez_processor_tests", | ||
| srcs = [ | ||
| "tracez_processor_test.cc", | ||
| ], | ||
| deps = [ | ||
| "//sdk/src/trace", | ||
| "//ext/src/zpages", | ||
| "@com_google_googletest//:gtest_main", | ||
| ], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| foreach(testname | ||
| tracez_processor_test) | ||
| add_executable(${testname} "${testname}.cc") | ||
| target_link_libraries( | ||
| ${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} | ||
| opentelemetry_zpages) | ||
|
|
||
| gtest_add_tests( | ||
| TARGET ${testname} | ||
| TEST_PREFIX ext. | ||
| TEST_LIST ${testname}) | ||
| endforeach() | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.