-
Notifications
You must be signed in to change notification settings - Fork 990
Remove Guava dependencies from SDK #2148
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,6 @@ | |
|
|
||
| package io.opentelemetry.sdk.common.export; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import com.google.common.collect.Maps; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
@@ -26,7 +24,7 @@ | |
| */ | ||
| public abstract class ConfigBuilder<T> { | ||
|
|
||
| @VisibleForTesting | ||
| // Visible for testing | ||
| protected enum NamingConvention { | ||
| DOT { | ||
| @Override | ||
|
|
@@ -65,7 +63,9 @@ protected abstract T fromConfigMap( | |
|
|
||
| /** Sets the configuration values from the given {@link Properties} object. */ | ||
| public T readProperties(Properties properties) { | ||
| return fromConfigMap(Maps.fromProperties(properties), NamingConvention.DOT); | ||
| Map<String, String> map = new HashMap<>(properties.size()); | ||
| properties.forEach((key, value) -> map.put((String) key, (String) value)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a normal foreach loop would be more readable.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm - I've always appreciated Java 8's
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively, how about some casting? https://stackoverflow.com/a/17209434/2128694 Map<String, String> map = (Map<String, String>)(Map)properties;
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
| return fromConfigMap(map, NamingConvention.DOT); | ||
| } | ||
|
|
||
| /** Sets the configuration values from environment variables. */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,15 +5,16 @@ | |
|
|
||
| package io.opentelemetry.sdk.resources; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| import com.google.auto.value.AutoValue; | ||
| import com.google.common.annotations.VisibleForTesting; | ||
| import com.google.common.base.Preconditions; | ||
| import com.google.common.base.Splitter; | ||
| import com.google.common.collect.ImmutableSet; | ||
| import io.opentelemetry.sdk.common.export.ConfigBuilder; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.Map; | ||
| import java.util.Properties; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
| import javax.annotation.concurrent.Immutable; | ||
|
|
||
| /** | ||
|
|
@@ -69,7 +70,8 @@ public static ResourcesConfig getDefault() { | |
| * @return a new {@link Builder}. | ||
| */ | ||
| public static Builder builder() { | ||
| return new AutoValue_ResourcesConfig.Builder().setDisabledResourceProviders(ImmutableSet.of()); | ||
| return new AutoValue_ResourcesConfig.Builder() | ||
| .setDisabledResourceProviders(Collections.emptySet()); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -94,7 +96,7 @@ public abstract static class Builder extends ConfigBuilder<Builder> { | |
| * @param configMap {@link Map} holding the configuration values. | ||
| * @return this | ||
| */ | ||
| @VisibleForTesting | ||
| // Visible for testing | ||
| @Override | ||
| protected Builder fromConfigMap( | ||
| Map<String, String> configMap, NamingConvention namingConvention) { | ||
|
|
@@ -103,8 +105,11 @@ protected Builder fromConfigMap( | |
| String stringValue = getStringProperty(OTEL_JAVA_DISABLED_RESOURCES_PROVIDERS, configMap); | ||
| if (stringValue != null) { | ||
| this.setDisabledResourceProviders( | ||
| ImmutableSet.copyOf( | ||
| Splitter.on(',').omitEmptyStrings().trimResults().split(stringValue))); | ||
| Collections.unmodifiableSet( | ||
| Arrays.stream(stringValue.split(",")) | ||
| .map(String::trim) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you might need to swap the order of trim/isEmpty to match Guava. AFAIK
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whether or not it matches guava, this logic seems right. Values that are only whitespace shouldn't be used, I don't think.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My not splitting the PRs up in advance caused this review to be a bit hectic, sorry about that. While GitHub doesn't have the outdated mark here, if I remember correctly, the code used to be in the wrong order and @Oberon00 commented and I fixed it so it should be good now. |
||
| .filter(s -> !s.isEmpty()) | ||
| .collect(Collectors.toSet()))); | ||
| } | ||
| return this; | ||
| } | ||
|
|
@@ -128,8 +133,7 @@ protected Builder fromConfigMap( | |
| */ | ||
| public ResourcesConfig build() { | ||
| ResourcesConfig resourcesConfig = autoBuild(); | ||
| Preconditions.checkArgument( | ||
| resourcesConfig.getDisabledResourceProviders() != null, "disabledResourceProviders"); | ||
| requireNonNull(resourcesConfig.getDisabledResourceProviders(), "disabledResourceProviders"); | ||
| return resourcesConfig; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,6 @@ | |
| package io.opentelemetry.sdk.trace.config; | ||
|
|
||
| import com.google.auto.value.AutoValue; | ||
| import com.google.common.annotations.VisibleForTesting; | ||
| import com.google.common.base.Preconditions; | ||
| import io.opentelemetry.api.internal.Utils; | ||
| import io.opentelemetry.api.trace.Span; | ||
| import io.opentelemetry.sdk.common.export.ConfigBuilder; | ||
|
|
@@ -191,7 +189,7 @@ public abstract static class Builder extends ConfigBuilder<Builder> { | |
| * @param configMap {@link Map} holding the configuration values. | ||
| * @return this | ||
| */ | ||
| @VisibleForTesting | ||
| // Visible for testing | ||
| @Override | ||
| protected Builder fromConfigMap( | ||
| Map<String, String> configMap, Builder.NamingConvention namingConvention) { | ||
|
|
@@ -352,16 +350,26 @@ public Builder setTraceIdRatioBased(double samplerRatio) { | |
| */ | ||
| public TraceConfig build() { | ||
| TraceConfig traceConfig = autoBuild(); | ||
| Preconditions.checkArgument( | ||
| traceConfig.getMaxNumberOfAttributes() > 0, "maxNumberOfAttributes"); | ||
| Preconditions.checkArgument(traceConfig.getMaxNumberOfEvents() > 0, "maxNumberOfEvents"); | ||
| Preconditions.checkArgument(traceConfig.getMaxNumberOfLinks() > 0, "maxNumberOfLinks"); | ||
| Preconditions.checkArgument( | ||
| traceConfig.getMaxNumberOfAttributesPerEvent() > 0, "maxNumberOfAttributesPerEvent"); | ||
| Preconditions.checkArgument( | ||
| traceConfig.getMaxNumberOfAttributesPerLink() > 0, "maxNumberOfAttributesPerLink"); | ||
| Preconditions.checkArgument( | ||
| traceConfig.getMaxLengthOfAttributeValues() >= -1, "maxLengthOfAttributeValues"); | ||
| if (traceConfig.getMaxNumberOfAttributes() <= 0) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't we have some
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah we have it in API - if we're ok with cross-referencing from other artifacts (guess it's ok) I'll use it
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the SDK uses API classes quite a bit (obviously because it has to implement it!). I think this is a fine usage, as long as it's not in a strictly "internal" package. |
||
| throw new IllegalArgumentException("maxNumberOfAttributes must be greater than 0"); | ||
| } | ||
| if (traceConfig.getMaxNumberOfEvents() <= 0) { | ||
| throw new IllegalArgumentException("maxNumberOfEvents must be greater than 0"); | ||
| } | ||
| if (traceConfig.getMaxNumberOfLinks() <= 0) { | ||
| throw new IllegalArgumentException("maxNumberOfLinks must be greater than 0"); | ||
| } | ||
| if (traceConfig.getMaxNumberOfAttributesPerEvent() <= 0) { | ||
| throw new IllegalArgumentException("maxNumberOfAttributesPerEvent must be greater than 0"); | ||
| } | ||
| if (traceConfig.getMaxNumberOfAttributesPerLink() <= 0) { | ||
| throw new IllegalArgumentException("maxNumberOfAttributesPerLink must be greater than 0"); | ||
| } | ||
| if (traceConfig.getMaxLengthOfAttributeValues() < -1) { | ||
| throw new IllegalArgumentException( | ||
| "maxLengthOfAttributeValues must be -1 to " | ||
| + "disable length restriction, or 0 or higher to enable length restriction"); | ||
| } | ||
| return traceConfig; | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.