-
Notifications
You must be signed in to change notification settings - Fork 851
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the ViewRegistry immutable and remove the mutating deprecated me…
…thod. (#3149) * remove a method deprecated in 1.1.0 * Make the ViewRegistry immutable. * set all the defaults view config via loop, rather than explicitly per instrument type.
- Loading branch information
Showing
8 changed files
with
138 additions
and
128 deletions.
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
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
46 changes: 46 additions & 0 deletions
46
sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/ViewRegistryBuilder.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,46 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.metrics; | ||
|
||
import io.opentelemetry.sdk.metrics.common.InstrumentType; | ||
import io.opentelemetry.sdk.metrics.view.InstrumentSelector; | ||
import io.opentelemetry.sdk.metrics.view.View; | ||
import java.util.EnumMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.regex.Pattern; | ||
|
||
class ViewRegistryBuilder { | ||
private final EnumMap<InstrumentType, LinkedHashMap<Pattern, View>> configuration = | ||
new EnumMap<>(InstrumentType.class); | ||
private static final LinkedHashMap<Pattern, View> EMPTY_CONFIG = new LinkedHashMap<>(); | ||
|
||
ViewRegistryBuilder() { | ||
for (InstrumentType type : InstrumentType.values()) { | ||
configuration.put(type, EMPTY_CONFIG); | ||
} | ||
} | ||
|
||
ViewRegistry build() { | ||
return new ViewRegistry(configuration); | ||
} | ||
|
||
ViewRegistryBuilder addView(InstrumentSelector selector, View view) { | ||
LinkedHashMap<Pattern, View> parentConfiguration = | ||
configuration.get(selector.getInstrumentType()); | ||
configuration.put( | ||
selector.getInstrumentType(), | ||
newLinkedHashMap(selector.getInstrumentNamePattern(), view, parentConfiguration)); | ||
return this; | ||
} | ||
|
||
private static LinkedHashMap<Pattern, View> newLinkedHashMap( | ||
Pattern pattern, View view, LinkedHashMap<Pattern, View> parentConfiguration) { | ||
LinkedHashMap<Pattern, View> result = new LinkedHashMap<>(); | ||
result.put(pattern, view); | ||
result.putAll(parentConfiguration); | ||
return result; | ||
} | ||
} |
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.