-
Notifications
You must be signed in to change notification settings - Fork 851
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
Very basic Aggregation-configuration API in the SDK. #2037
Merged
jkwatson
merged 37 commits into
open-telemetry:master
from
jkwatson:view_prototype_redux
Nov 18, 2020
Merged
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
631d00f
Create a very basic view API in the SDK.
9bbbe44
fix formatting
6063ff4
move the ViewRegistry up one package, and clean up the visibility of …
8432091
Support matching by instrument name
cbe903d
Update sdk/src/main/java/io/opentelemetry/sdk/metrics/ViewRegistry.java
jkwatson d42a9de
Update sdk/src/main/java/io/opentelemetry/sdk/metrics/view/ViewSpecif…
jkwatson 7742cf9
Update sdk/src/main/java/io/opentelemetry/sdk/metrics/view/ViewSpecif…
jkwatson ed28843
Update sdk/src/main/java/io/opentelemetry/sdk/metrics/view/ViewSpecif…
jkwatson ab50fc9
Update sdk/src/main/java/io/opentelemetry/sdk/metrics/view/ViewSpecif…
jkwatson 856ca82
fix formatting issues from GH
eaa2b3d
small renaming to a big name
2d07c94
small renaming to a big name
230627d
re-order matching check and fix a merge issue
36d6887
Update from upstream changes.
jkwatson b1bbf16
Update from upstream changes.
jkwatson b7f2967
Adjust defaults based on the latest behavior
jkwatson 3a3c72f
refactor before writing tests
jkwatson 9678531
tests for the AggregationChooser and a bugfix they uncovered
jkwatson 77f5c7f
tests for the ViewRegistry
jkwatson c85e464
Javadoc for the AggregationConfiguration
jkwatson 778a8a3
Add more javadoc.
jkwatson 567c16e
Update sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/Batcher…
jkwatson 79a29fd
Update sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/view/Ag…
jkwatson 25d5464
Update sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/view/Ag…
jkwatson 55537f0
Update sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/view/In…
jkwatson 02a8324
Update sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/view/In…
jkwatson c7e4b59
Update sdk/src/main/java/io/opentelemetry/sdk/metrics/view/Aggregatio…
jkwatson fd42ee3
Update sdk/src/main/java/io/opentelemetry/sdk/metrics/view/Aggregatio…
jkwatson 28b7636
Update sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/view/Ag…
jkwatson 444c3b9
Update sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/view/In…
jkwatson 5e94bc6
Update sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/view/In…
jkwatson 41180b2
Update sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/view/In…
jkwatson bd60c11
Update sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/view/In…
jkwatson d99012d
Update sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/view/In…
jkwatson 5d783b3
Update sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/view/In…
jkwatson 816c35c
fix formatting issues
jkwatson 2f5862c
Update sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/view/In…
jkwatson 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
104 changes: 104 additions & 0 deletions
104
sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/AggregationChooser.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,104 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.metrics; | ||
|
||
import io.opentelemetry.sdk.metrics.view.AggregationConfiguration; | ||
import io.opentelemetry.sdk.metrics.view.Aggregations; | ||
import io.opentelemetry.sdk.metrics.view.InstrumentSelector; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.regex.Pattern; | ||
|
||
class AggregationChooser { | ||
private static final AggregationConfiguration CUMULATIVE_SUM = | ||
AggregationConfiguration.create( | ||
Aggregations.sum(), AggregationConfiguration.Temporality.CUMULATIVE); | ||
private static final AggregationConfiguration DELTA_SUMMARY = | ||
AggregationConfiguration.create( | ||
Aggregations.minMaxSumCount(), AggregationConfiguration.Temporality.DELTA); | ||
private static final AggregationConfiguration CUMULATIVE_LAST_VALUE = | ||
AggregationConfiguration.create( | ||
Aggregations.lastValue(), AggregationConfiguration.Temporality.CUMULATIVE); | ||
private static final AggregationConfiguration DELTA_LAST_VALUE = | ||
AggregationConfiguration.create( | ||
Aggregations.lastValue(), AggregationConfiguration.Temporality.DELTA); | ||
|
||
private final Map<InstrumentSelector, AggregationConfiguration> configuration = | ||
new ConcurrentHashMap<>(); | ||
|
||
AggregationConfiguration chooseAggregation(InstrumentDescriptor descriptor) { | ||
List<Map.Entry<InstrumentSelector, AggregationConfiguration>> possibleMatches = | ||
new ArrayList<>(); | ||
for (Map.Entry<InstrumentSelector, AggregationConfiguration> entry : configuration.entrySet()) { | ||
InstrumentSelector registeredSelector = entry.getKey(); | ||
// if it matches everything, return it right away... | ||
if (matchesOnType(descriptor, registeredSelector) | ||
&& matchesOnName(descriptor, registeredSelector)) { | ||
return entry.getValue(); | ||
} | ||
// otherwise throw it into a bucket of possible matches if it matches one of the criteria | ||
if (matchesOne(descriptor, registeredSelector)) { | ||
possibleMatches.add(entry); | ||
} | ||
} | ||
|
||
if (possibleMatches.isEmpty()) { | ||
return getDefaultSpecification(descriptor); | ||
} | ||
|
||
// If no exact matches found, pick the first one that matches something: | ||
return possibleMatches.get(0).getValue(); | ||
} | ||
|
||
private static boolean matchesOne(InstrumentDescriptor descriptor, InstrumentSelector selector) { | ||
if (selector.hasInstrumentNameRegex() && !matchesOnName(descriptor, selector)) { | ||
return false; | ||
} | ||
if (selector.hasInstrumentType() && !matchesOnType(descriptor, selector)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
private static boolean matchesOnType( | ||
InstrumentDescriptor descriptor, InstrumentSelector selector) { | ||
if (selector.instrumentType() == null) { | ||
return false; | ||
} | ||
return selector.instrumentType().equals(descriptor.getType()); | ||
} | ||
|
||
private static boolean matchesOnName( | ||
InstrumentDescriptor descriptor, InstrumentSelector registeredSelector) { | ||
Pattern pattern = registeredSelector.instrumentNamePattern(); | ||
if (pattern == null) { | ||
return false; | ||
} | ||
return pattern.matcher(descriptor.getName()).matches(); | ||
} | ||
|
||
private static AggregationConfiguration getDefaultSpecification(InstrumentDescriptor descriptor) { | ||
switch (descriptor.getType()) { | ||
case COUNTER: | ||
case UP_DOWN_COUNTER: | ||
return CUMULATIVE_SUM; | ||
case VALUE_RECORDER: | ||
return DELTA_SUMMARY; | ||
case VALUE_OBSERVER: | ||
return DELTA_LAST_VALUE; | ||
case SUM_OBSERVER: | ||
case UP_DOWN_SUM_OBSERVER: | ||
return CUMULATIVE_LAST_VALUE; | ||
} | ||
throw new IllegalArgumentException("Unknown descriptor type: " + descriptor.getType()); | ||
} | ||
|
||
void addView(InstrumentSelector selector, AggregationConfiguration specification) { | ||
configuration.put(selector, specification); | ||
} | ||
} |
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
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
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
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
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.
Think you can use
Objects.hashCode
instead of your own null checksThere 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 just had IDEA generate this code. Hate to mess with generated code in general.
We should document what we want to do with generated equals/hashcode/toString implementations, so we don't have to discuss it. :)