-
Notifications
You must be signed in to change notification settings - Fork 829
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
Implemented base zPages classes and TraceZ zPage #1380
Merged
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
9ca81bc
Implemented a span processor for the TraceZ zPage
williamhu99 86c6db8
Implemented aggregation logic for running and latency based spans,
williamhu99 66bafe2
Implemented aggregation logic for error based spans
williamhu99 af80d27
Finished implementation of TraceZ zPage summary table
wty27 d2eb7be
Finished implementation of HttpHandler, HttpServer, and TraceZ zPage
wty27 219d383
Refactored the sdk_contrib folder to follow updated syntax
williamhu99 febc453
Merge branch 'master' into master
williamhu99 425e436
Removed duplicate function
williamhu99 0f282f2
Changed inline base64 images
wty27 a2ef65c
Fixed copyright statement
wty27 d7f4904
Modified the TracezSpanProcessor to only allow for a limited number o…
williamhu99 50fe3f1
Fixed typos and turned SpanProcessor and DataAggregator to package pr…
williamhu99 12c333a
Separated SpanBuckets and LatencyBoundaries from TracezDataAggregator
williamhu99 1f409ad
Switched to PrintStream, removed bufferWritter, removed factory and c…
wty27 db2b2fa
Fixed package name
wty27 6922488
Changed way of registering handlers, changed atomicBoolean to final, …
wty27 63bc912
Changed registerTracezZPageHandler to package private
wty27 8ed29a7
Fixed javadoc styling and wording
wty27 be0d55d
Added constants for splitters, changed httpserver to compileOnly depe…
wty27 ff9247b
Removed FQNs from backend files
williamhu99 bd28217
Removed style errors
williamhu99 fb41a8b
Updated TracezSpanProcessor to maintain a set of span names increment…
williamhu99 8b46dd9
Added visibleForTesting tag, adjusted HTML expression
wty27 99497ac
Merge branch 'master' of github.com:williamhu99/opentelemetry-java in…
williamhu99 9ee432f
Removed unused functions in the data aggregator
williamhu99 dcaf730
Made TracezSpanBuckets thread-safe
williamhu99 c5e819e
Changed test to use Mockitorule, removed unnecessary Formatter, unrol…
wty27 19b16d7
Changed test with @Mock to use Mockito test runner
wty27 2647c45
Renamed LatencyBoundaries to LatencyBoundary and cleaned up code
williamhu99 eea8895
Merge branch 'master' of github.com:williamhu99/opentelemetry-java in…
williamhu99 88a703b
Replaced the EvictingQueue with a faster SpanBucket class and modifie…
williamhu99 fee6378
Addressed additional comments
williamhu99 a393431
Migrated images to resources, used logger to log errors, and other mi…
wty27 0b2357f
Moved a variable to within a class in TracezZPageHandler
williamhu99 be61de2
Made a small fix to scope
williamhu99 2495cf9
Removed printStackTrace, added test for query parameter
wty27 648a8b4
Changed logger to static field, used log method to log detailed stack…
wty27 d6113ea
Made minor fixes
williamhu99 23e1728
Resolved unmodifiable list error with getOkSpans and getErrorSpans
williamhu99 317876f
Changed map @Mock to empty map, added more test
wty27 842629c
Changed test runner
wty27 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 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,9 @@ | ||
# OpenTelemetry SDK Contrib - zPages | ||
|
||
[![Javadocs][javadoc-image]][javadoc-url] | ||
|
||
This module contains code for OpenTelemetry's Java zPages. | ||
|
||
<!--- TODO: Update javadoc --> | ||
[javadoc-image]: https://www.javadoc.io/badge/io.opentelemetry/opentelemetry-sdk-contrib-auto-config.svg | ||
[javadoc-url]: https://www.javadoc.io/doc/io.opentelemetry/opentelemetry-sdk-contrib-auto-config |
This file contains 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,19 @@ | ||
plugins { | ||
id "java" | ||
id "maven-publish" | ||
|
||
id "ru.vyarus.animalsniffer" | ||
} | ||
|
||
description = 'OpenTelemetry - zPages' | ||
ext.moduleName = "io.opentelemetry.sdk.extension.zpages" | ||
|
||
dependencies { | ||
implementation project(':opentelemetry-api'), | ||
project(':opentelemetry-sdk') | ||
|
||
implementation libraries.guava | ||
compileOnly 'com.sun.net.httpserver:http:20070405' | ||
|
||
signature "org.codehaus.mojo.signature:java17:1.0@signature" | ||
} |
100 changes: 100 additions & 0 deletions
100
...tensions/zpages/src/main/java/io/opentelemetry/sdk/extensions/zpages/LatencyBoundary.java
This file contains 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,100 @@ | ||
/* | ||
* 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 io.opentelemetry.sdk.extensions.zpages; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* A class of boundaries for the latency buckets. The completed spans with a status of {@link | ||
* io.opentelemetry.trace.Status#OK} are categorized into one of these buckets om the traceZ zPage. | ||
*/ | ||
enum LatencyBoundary { | ||
/** Stores finished successful requests of duration within the interval [0, 10us). */ | ||
ZERO_MICROSx10(0, TimeUnit.MICROSECONDS.toNanos(10)), | ||
|
||
/** Stores finished successful requests of duration within the interval [10us, 100us). */ | ||
MICROSx10_MICROSx100(TimeUnit.MICROSECONDS.toNanos(10), TimeUnit.MICROSECONDS.toNanos(100)), | ||
|
||
/** Stores finished successful requests of duration within the interval [100us, 1ms). */ | ||
MICROSx100_MILLIx1(TimeUnit.MICROSECONDS.toNanos(100), TimeUnit.MILLISECONDS.toNanos(1)), | ||
|
||
/** Stores finished successful requests of duration within the interval [1ms, 10ms). */ | ||
MILLIx1_MILLIx10(TimeUnit.MILLISECONDS.toNanos(1), TimeUnit.MILLISECONDS.toNanos(10)), | ||
|
||
/** Stores finished successful requests of duration within the interval [10ms, 100ms). */ | ||
MILLIx10_MILLIx100(TimeUnit.MILLISECONDS.toNanos(10), TimeUnit.MILLISECONDS.toNanos(100)), | ||
|
||
/** Stores finished successful requests of duration within the interval [100ms, 1sec). */ | ||
MILLIx100_SECONDx1(TimeUnit.MILLISECONDS.toNanos(100), TimeUnit.SECONDS.toNanos(1)), | ||
|
||
/** Stores finished successful requests of duration within the interval [1sec, 10sec). */ | ||
SECONDx1_SECONDx10(TimeUnit.SECONDS.toNanos(1), TimeUnit.SECONDS.toNanos(10)), | ||
|
||
/** Stores finished successful requests of duration within the interval [10sec, 100sec). */ | ||
SECONDx10_SECONDx100(TimeUnit.SECONDS.toNanos(10), TimeUnit.SECONDS.toNanos(100)), | ||
|
||
/** Stores finished successful requests of duration greater than or equal to 100sec. */ | ||
SECONDx100_MAX(TimeUnit.SECONDS.toNanos(100), Long.MAX_VALUE); | ||
|
||
private final long latencyLowerBound; | ||
private final long latencyUpperBound; | ||
|
||
/** | ||
* Constructs a {@code LatencyBoundaries} with the given boundaries and label. | ||
* | ||
* @param latencyLowerBound the latency lower bound of the bucket. | ||
* @param latencyUpperBound the latency upper bound of the bucket. | ||
*/ | ||
LatencyBoundary(long latencyLowerBound, long latencyUpperBound) { | ||
this.latencyLowerBound = latencyLowerBound; | ||
this.latencyUpperBound = latencyUpperBound; | ||
} | ||
|
||
/** | ||
* Returns the latency lower bound of the bucket. | ||
* | ||
* @return the latency lower bound of the bucket. | ||
*/ | ||
long getLatencyLowerBound() { | ||
return latencyLowerBound; | ||
} | ||
|
||
/** | ||
* Returns the latency upper bound of the bucket. | ||
* | ||
* @return the latency upper bound of the bucket. | ||
*/ | ||
long getLatencyUpperBound() { | ||
return latencyUpperBound; | ||
} | ||
|
||
/** | ||
* Returns the LatencyBoundary that the argument falls into. | ||
* | ||
* @param latencyNanos latency in nanoseconds. | ||
* @return the LatencyBoundary that latencyNanos falls into. | ||
*/ | ||
static LatencyBoundary getBoundary(long latencyNanos) { | ||
for (LatencyBoundary bucket : LatencyBoundary.values()) { | ||
if (latencyNanos >= bucket.getLatencyLowerBound() | ||
&& latencyNanos < bucket.getLatencyUpperBound()) { | ||
return bucket; | ||
} | ||
} | ||
return ZERO_MICROSx10; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
sdk_extensions/zpages/src/main/java/io/opentelemetry/sdk/extensions/zpages/SpanBucket.java
This file contains 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,64 @@ | ||
/* | ||
* 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 io.opentelemetry.sdk.extensions.zpages; | ||
|
||
import com.google.common.primitives.UnsignedInts; | ||
import io.opentelemetry.sdk.trace.ReadableSpan; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicReferenceArray; | ||
|
||
final class SpanBucket { | ||
// A power of 2 means Integer.MAX_VALUE % bucketSize = bucketSize - 1, so the index will always | ||
// loop back to 0. | ||
private static final int LATENCY_BUCKET_SIZE = 16; | ||
private static final int ERROR_BUCKET_SIZE = 8; | ||
|
||
private final AtomicReferenceArray<ReadableSpan> spans; | ||
private final AtomicInteger index; | ||
private final int bucketSize; | ||
|
||
SpanBucket(boolean isLatencyBucket) { | ||
bucketSize = isLatencyBucket ? LATENCY_BUCKET_SIZE : ERROR_BUCKET_SIZE; | ||
spans = new AtomicReferenceArray<>(bucketSize); | ||
index = new AtomicInteger(); | ||
} | ||
|
||
void add(ReadableSpan span) { | ||
spans.set(UnsignedInts.remainder(index.getAndIncrement(), bucketSize), span); | ||
} | ||
|
||
int size() { | ||
for (int i = bucketSize - 1; i >= 0; i--) { | ||
if (spans.get(i) != null) { | ||
return i + 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
void addTo(List<ReadableSpan> result) { | ||
for (int i = 0; i < bucketSize; i++) { | ||
ReadableSpan span = spans.get(i); | ||
if (span != null) { | ||
result.add(span); | ||
} else { | ||
break; | ||
} | ||
} | ||
} | ||
} |
174 changes: 174 additions & 0 deletions
174
...ons/zpages/src/main/java/io/opentelemetry/sdk/extensions/zpages/TracezDataAggregator.java
This file contains 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,174 @@ | ||
/* | ||
* 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 io.opentelemetry.sdk.extensions.zpages; | ||
|
||
import io.opentelemetry.sdk.trace.ReadableSpan; | ||
import io.opentelemetry.sdk.trace.data.SpanData; | ||
import io.opentelemetry.trace.Status; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.Set; | ||
import java.util.TreeSet; | ||
import javax.annotation.concurrent.ThreadSafe; | ||
|
||
/** | ||
* A data aggregator for the traceZ zPage. | ||
* | ||
* <p>The traceZ data aggregator compiles information about the running spans, span latencies, and | ||
* error spans for the frontend of the zPage. | ||
*/ | ||
@ThreadSafe | ||
final class TracezDataAggregator { | ||
private final TracezSpanProcessor spanProcessor; | ||
|
||
/** | ||
* Constructor for {@link TracezDataAggregator}. | ||
* | ||
* @param spanProcessor collects span data. | ||
*/ | ||
TracezDataAggregator(TracezSpanProcessor spanProcessor) { | ||
this.spanProcessor = spanProcessor; | ||
} | ||
|
||
/** | ||
* Returns a Set of running and completed span names for {@link TracezDataAggregator}. | ||
* | ||
* @return a Set of {@link String}. | ||
*/ | ||
Set<String> getSpanNames() { | ||
Set<String> spanNames = new TreeSet<>(); | ||
wangty27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Collection<ReadableSpan> allRunningSpans = spanProcessor.getRunningSpans(); | ||
wangty27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (ReadableSpan span : allRunningSpans) { | ||
spanNames.add(span.getName()); | ||
} | ||
spanNames.addAll(spanProcessor.getCompletedSpanCache().keySet()); | ||
return spanNames; | ||
} | ||
|
||
/** | ||
* Returns a Map of the running span counts for {@link TracezDataAggregator}. | ||
* | ||
* @return a Map of span counts for each span name. | ||
*/ | ||
Map<String, Integer> getRunningSpanCounts() { | ||
Collection<ReadableSpan> allRunningSpans = spanProcessor.getRunningSpans(); | ||
Map<String, Integer> numSpansPerName = new HashMap<>(); | ||
for (ReadableSpan span : allRunningSpans) { | ||
Integer prevValue = numSpansPerName.get(span.getName()); | ||
numSpansPerName.put(span.getName(), prevValue != null ? prevValue + 1 : 1); | ||
} | ||
return numSpansPerName; | ||
} | ||
|
||
/** | ||
* Returns a List of all running spans with a given span name for {@link TracezDataAggregator}. | ||
* | ||
* @param spanName name to filter returned spans. | ||
* @return a List of {@link SpanData}. | ||
*/ | ||
List<SpanData> getRunningSpans(String spanName) { | ||
Collection<ReadableSpan> allRunningSpans = spanProcessor.getRunningSpans(); | ||
List<SpanData> filteredSpans = new ArrayList<>(); | ||
for (ReadableSpan span : allRunningSpans) { | ||
if (span.getName().equals(spanName)) { | ||
filteredSpans.add(span.toSpanData()); | ||
} | ||
} | ||
return filteredSpans; | ||
} | ||
|
||
/** | ||
* Returns a Map of span names to counts for all {@link Status#OK} spans in {@link | ||
* TracezDataAggregator}. | ||
* | ||
* @return a Map of span names to counts, where the counts are further indexed by the latency | ||
* boundaries. | ||
*/ | ||
Map<String, Map<LatencyBoundary, Integer>> getSpanLatencyCounts() { | ||
Map<String, TracezSpanBuckets> completedSpanCache = spanProcessor.getCompletedSpanCache(); | ||
Map<String, Map<LatencyBoundary, Integer>> numSpansPerName = new HashMap<>(); | ||
for (Entry<String, TracezSpanBuckets> cacheEntry : completedSpanCache.entrySet()) { | ||
numSpansPerName.put( | ||
cacheEntry.getKey(), cacheEntry.getValue().getLatencyBoundaryToCountMap()); | ||
} | ||
return numSpansPerName; | ||
} | ||
|
||
/** | ||
* Returns a List of all {@link Status#OK} spans with a given span name between [lowerBound, | ||
* upperBound) for {@link TracezDataAggregator}. | ||
* | ||
* @param spanName name to filter returned spans. | ||
* @param lowerBound latency lower bound (inclusive) | ||
* @param upperBound latency upper bound (exclusive) | ||
* @return a List of {@link SpanData}. | ||
*/ | ||
List<SpanData> getOkSpans(String spanName, long lowerBound, long upperBound) { | ||
Map<String, TracezSpanBuckets> completedSpanCache = spanProcessor.getCompletedSpanCache(); | ||
TracezSpanBuckets buckets = completedSpanCache.get(spanName); | ||
if (buckets == null) { | ||
return Collections.emptyList(); | ||
} | ||
Collection<ReadableSpan> allOkSpans = buckets.getOkSpans(); | ||
List<SpanData> filteredSpans = new ArrayList<>(); | ||
for (ReadableSpan span : allOkSpans) { | ||
if (span.getLatencyNanos() >= lowerBound && span.getLatencyNanos() < upperBound) { | ||
filteredSpans.add(span.toSpanData()); | ||
} | ||
} | ||
return Collections.unmodifiableList(filteredSpans); | ||
} | ||
|
||
/** | ||
* Returns a Map of error span counts for {@link TracezDataAggregator}. | ||
* | ||
* @return a Map of error span counts for each span name. | ||
*/ | ||
Map<String, Integer> getErrorSpanCounts() { | ||
Map<String, TracezSpanBuckets> completedSpanCache = spanProcessor.getCompletedSpanCache(); | ||
Map<String, Integer> numErrorsPerName = new HashMap<>(); | ||
for (Entry<String, TracezSpanBuckets> cacheEntry : completedSpanCache.entrySet()) { | ||
numErrorsPerName.put(cacheEntry.getKey(), cacheEntry.getValue().getErrorSpans().size()); | ||
} | ||
return numErrorsPerName; | ||
} | ||
|
||
/** | ||
* Returns a List of error spans with a given span name for {@link TracezDataAggregator}. | ||
* | ||
* @param spanName name to filter returned spans. | ||
* @return a List of {@link SpanData}. | ||
*/ | ||
List<SpanData> getErrorSpans(String spanName) { | ||
Map<String, TracezSpanBuckets> completedSpanCache = spanProcessor.getCompletedSpanCache(); | ||
TracezSpanBuckets buckets = completedSpanCache.get(spanName); | ||
if (buckets == null) { | ||
return Collections.emptyList(); | ||
} | ||
Collection<ReadableSpan> allErrorSpans = buckets.getErrorSpans(); | ||
List<SpanData> errorSpans = new ArrayList<>(); | ||
for (ReadableSpan span : allErrorSpans) { | ||
errorSpans.add(span.toSpanData()); | ||
} | ||
return Collections.unmodifiableList(errorSpans); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to have unit tests on this class specifically, but that can be in a follow-up PR.