diff options
author | Yang Song <songy23@users.noreply.github.com> | 2018-03-07 14:51:17 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-07 14:51:17 -0800 |
commit | b28e6efbf8d36304cae8977e83faf1f47b4d5c69 (patch) | |
tree | f1744f08ba8322e26d05efe6fb8681c6b7621a41 /api | |
parent | 35bf957b19c9775eec129e62f1122a7ebe5f595b (diff) | |
download | opencensus-java-b28e6efbf8d36304cae8977e83faf1f47b4d5c69.tar.gz |
Deprecate Window and WindowData. (#1018)
* Deprecate Window and WindowType in Stats APIs
* Window and WindowData will continue to be NonNull
* Suppress warnings for impl, exporter and zpages.
* NoopStats should continue to use old method.
Diffstat (limited to 'api')
4 files changed, 144 insertions, 31 deletions
diff --git a/api/src/main/java/io/opencensus/stats/NoopStats.java b/api/src/main/java/io/opencensus/stats/NoopStats.java index 74f8f660..97d2976a 100644 --- a/api/src/main/java/io/opencensus/stats/NoopStats.java +++ b/api/src/main/java/io/opencensus/stats/NoopStats.java @@ -27,10 +27,6 @@ import io.opencensus.common.Functions; import io.opencensus.common.Timestamp; import io.opencensus.stats.Measure.MeasureDouble; import io.opencensus.stats.Measure.MeasureLong; -import io.opencensus.stats.View.AggregationWindow; -import io.opencensus.stats.ViewData.AggregationWindowData; -import io.opencensus.stats.ViewData.AggregationWindowData.CumulativeData; -import io.opencensus.stats.ViewData.AggregationWindowData.IntervalData; import io.opencensus.tags.TagContext; import io.opencensus.tags.TagValue; import java.util.Collection; @@ -176,6 +172,7 @@ final class NoopStats { @Override @Nullable + @SuppressWarnings("deprecation") public ViewData getView(View.Name name) { checkNotNull(name, "name"); synchronized (registeredViews) { @@ -188,11 +185,12 @@ final class NoopStats { Collections.<List<TagValue>, AggregationData>emptyMap(), view.getWindow() .match( - Functions.<AggregationWindowData>returnConstant( - CumulativeData.create(ZERO_TIMESTAMP, ZERO_TIMESTAMP)), - Functions.<AggregationWindowData>returnConstant( - IntervalData.create(ZERO_TIMESTAMP)), - Functions.<AggregationWindowData>throwAssertionError())); + Functions.<ViewData.AggregationWindowData>returnConstant( + ViewData.AggregationWindowData.CumulativeData.create( + ZERO_TIMESTAMP, ZERO_TIMESTAMP)), + Functions.<ViewData.AggregationWindowData>returnConstant( + ViewData.AggregationWindowData.IntervalData.create(ZERO_TIMESTAMP)), + Functions.<ViewData.AggregationWindowData>throwAssertionError())); } } } @@ -209,12 +207,14 @@ final class NoopStats { } // Returns the subset of the given views that should be exported + @SuppressWarnings("deprecation") private static Set<View> filterExportedViews(Collection<View> allViews) { Set<View> views = Sets.newHashSet(); for (View view : allViews) { - if (view.getWindow() instanceof AggregationWindow.Cumulative) { - views.add(view); + if (view.getWindow() instanceof View.AggregationWindow.Interval) { + continue; } + views.add(view); } return Collections.unmodifiableSet(views); } diff --git a/api/src/main/java/io/opencensus/stats/View.java b/api/src/main/java/io/opencensus/stats/View.java index a26c777b..32915919 100644 --- a/api/src/main/java/io/opencensus/stats/View.java +++ b/api/src/main/java/io/opencensus/stats/View.java @@ -40,7 +40,7 @@ import javax.annotation.concurrent.Immutable; @AutoValue // Suppress Checker Framework warning about missing @Nullable in generated equals method. @AutoValue.CopyAnnotations -@SuppressWarnings("nullness") +@SuppressWarnings({"nullness", "deprecation"}) public abstract class View { @VisibleForTesting static final int NAME_MAX_LENGTH = 255; @@ -90,7 +90,9 @@ public abstract class View { * * @return the time {@link AggregationWindow}. * @since 0.8 + * @deprecated since 0.13. In the future all {@link View}s will be cumulative. */ + @Deprecated public abstract AggregationWindow getWindow(); /** @@ -105,7 +107,9 @@ public abstract class View { * @param window the {@link AggregationWindow} of view. * @return a new {@link View}. * @since 0.8 + * @deprecated in favor of {@link #create(Name, String, Measure, Aggregation, List)}. */ + @Deprecated public static View create( Name name, String description, @@ -125,6 +129,35 @@ public abstract class View { } /** + * Constructs a new {@link View}. + * + * @param name the {@link Name} of view. Must be unique. + * @param description the description of view. + * @param measure the {@link Measure} to be aggregated by this view. + * @param aggregation the basic {@link Aggregation} that this view will support. + * @param columns the {@link TagKey}s that this view will aggregate on. Columns should not contain + * duplicates. + * @return a new {@link View}. + * @since 0.13 + */ + public static View create( + Name name, + String description, + Measure measure, + Aggregation aggregation, + List<TagKey> columns) { + checkArgument(new HashSet<TagKey>(columns).size() == columns.size(), "Columns have duplicate."); + + return new AutoValue_View( + name, + description, + measure, + aggregation, + Collections.unmodifiableList(new ArrayList<TagKey>(columns)), + AggregationWindow.Cumulative.create()); + } + + /** * The name of a {@code View}. * * @since 0.8 @@ -169,7 +202,9 @@ public abstract class View { * The time window for a {@code View}. * * @since 0.8 + * @deprecated since 0.13. In the future all {@link View}s will be cumulative. */ + @Deprecated @Immutable public abstract static class AggregationWindow { @@ -189,7 +224,9 @@ public abstract class View { * Cumulative (infinite interval) time {@code AggregationWindow}. * * @since 0.8 + * @deprecated since 0.13. In the future all {@link View}s will be cumulative. */ + @Deprecated @Immutable @AutoValue // Suppress Checker Framework warning about missing @Nullable in generated equals method. @@ -227,7 +264,9 @@ public abstract class View { * Interval (finite interval) time {@code AggregationWindow}. * * @since 0.8 + * @deprecated since 0.13. In the future all {@link View}s will be cumulative. */ + @Deprecated @Immutable @AutoValue // Suppress Checker Framework warning about missing @Nullable in generated equals method. diff --git a/api/src/main/java/io/opencensus/stats/ViewData.java b/api/src/main/java/io/opencensus/stats/ViewData.java index 951afb2e..3ee67ca9 100644 --- a/api/src/main/java/io/opencensus/stats/ViewData.java +++ b/api/src/main/java/io/opencensus/stats/ViewData.java @@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkArgument; import com.google.auto.value.AutoValue; import com.google.common.collect.Maps; +import io.opencensus.common.Duration; import io.opencensus.common.Function; import io.opencensus.common.Functions; import io.opencensus.common.Timestamp; @@ -34,7 +35,6 @@ import io.opencensus.stats.AggregationData.SumDataDouble; import io.opencensus.stats.AggregationData.SumDataLong; import io.opencensus.stats.Measure.MeasureDouble; import io.opencensus.stats.Measure.MeasureLong; -import io.opencensus.stats.View.AggregationWindow; import io.opencensus.tags.TagValue; import java.util.ArrayList; import java.util.Collections; @@ -56,7 +56,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; @AutoValue // Suppress Checker Framework warning about missing @Nullable in generated equals method. @AutoValue.CopyAnnotations -@SuppressWarnings("nullness") +@SuppressWarnings({"nullness", "deprecation"}) public abstract class ViewData { // Prevents this class from being subclassed anywhere else. @@ -80,12 +80,33 @@ public abstract class ViewData { /** * Returns the {@link AggregationWindowData} associated with this {@link ViewData}. * + * <p>{@link AggregationWindowData} is deprecated since 0.13, please avoid using this method. Use + * {@link #getStart()} and {@link #getEnd()} instead. + * * @return the {@code AggregationWindowData}. * @since 0.8 + * @deprecated in favor of {@link #getStart()} and {@link #getEnd()}. */ + @Deprecated public abstract AggregationWindowData getWindowData(); /** + * Returns the start {@code Timestamp} for a {@link ViewData}. + * + * @return the start {@code Timestamp}. + * @since 0.13 + */ + public abstract Timestamp getStart(); + + /** + * Returns the end {@code Timestamp} for a {@link ViewData}. + * + * @return the end {@code Timestamp}. + * @since 0.13 + */ + public abstract Timestamp getEnd(); + + /** * Constructs a new {@link ViewData}. * * @param view the {@link View} associated with this {@link ViewData}. @@ -96,12 +117,62 @@ public abstract class ViewData { * AggregationData} don't match, or the types of {@code Window} and {@code WindowData} don't * match. * @since 0.8 + * @deprecated in favor of {@link #create(View, Map, Timestamp, Timestamp)}. */ + @Deprecated public static ViewData create( - View view, + final View view, Map<? extends List</*@Nullable*/ TagValue>, ? extends AggregationData> map, final AggregationWindowData windowData) { checkWindow(view.getWindow(), windowData); + final Map<List<TagValue>, AggregationData> deepCopy = Maps.newHashMap(); + for (Entry<? extends List<TagValue>, ? extends AggregationData> entry : map.entrySet()) { + checkAggregation(view.getAggregation(), entry.getValue(), view.getMeasure()); + deepCopy.put( + Collections.unmodifiableList(new ArrayList</*@Nullable*/ TagValue>(entry.getKey())), + entry.getValue()); + } + return windowData.match( + new Function<ViewData.AggregationWindowData.CumulativeData, ViewData>() { + @Override + public ViewData apply(ViewData.AggregationWindowData.CumulativeData arg) { + return new AutoValue_ViewData( + view, Collections.unmodifiableMap(deepCopy), arg, arg.getStart(), arg.getEnd()); + } + }, + new Function<ViewData.AggregationWindowData.IntervalData, ViewData>() { + @Override + public ViewData apply(ViewData.AggregationWindowData.IntervalData arg) { + Duration duration = ((View.AggregationWindow.Interval) view.getWindow()).getDuration(); + return new AutoValue_ViewData( + view, + Collections.unmodifiableMap(deepCopy), + arg, + arg.getEnd() + .addDuration(Duration.create(-duration.getSeconds(), -duration.getNanos())), + arg.getEnd()); + } + }, + Functions.<ViewData>throwAssertionError()); + } + + /** + * Constructs a new {@link ViewData}. + * + * @param view the {@link View} associated with this {@link ViewData}. + * @param map the mapping from {@link TagValue} list to {@link AggregationData}. + * @param start the start {@link Timestamp} for this {@link ViewData}. + * @param end the end {@link Timestamp} for this {@link ViewData}. + * @return a {@code ViewData}. + * @throws IllegalArgumentException if the types of {@code Aggregation} and {@code + * AggregationData} don't match. + * @since 0.13 + */ + public static ViewData create( + View view, + Map<? extends List</*@Nullable*/ TagValue>, ? extends AggregationData> map, + Timestamp start, + Timestamp end) { Map<List<TagValue>, AggregationData> deepCopy = Maps.newHashMap(); for (Entry<? extends List<TagValue>, ? extends AggregationData> entry : map.entrySet()) { checkAggregation(view.getAggregation(), entry.getValue(), view.getMeasure()); @@ -109,11 +180,16 @@ public abstract class ViewData { Collections.unmodifiableList(new ArrayList</*@Nullable*/ TagValue>(entry.getKey())), entry.getValue()); } - return new AutoValue_ViewData(view, Collections.unmodifiableMap(deepCopy), windowData); + return new AutoValue_ViewData( + view, + Collections.unmodifiableMap(deepCopy), + AggregationWindowData.CumulativeData.create(start, end), + start, + end); } private static void checkWindow( - AggregationWindow window, final AggregationWindowData windowData) { + View.AggregationWindow window, final AggregationWindowData windowData) { window.match( new Function<View.AggregationWindow.Cumulative, Void>() { @Override @@ -133,11 +209,11 @@ public abstract class ViewData { return null; } }, - Functions.</*@Nullable*/ Void>throwIllegalArgumentException()); + Functions.</*@Nullable*/ Void>throwAssertionError()); } private static String createErrorMessageForWindow( - AggregationWindow window, AggregationWindowData windowData) { + View.AggregationWindow window, AggregationWindowData windowData) { return "AggregationWindow and AggregationWindowData types mismatch. " + "AggregationWindow: " + window @@ -217,7 +293,9 @@ public abstract class ViewData { * The {@code AggregationWindowData} for a {@link ViewData}. * * @since 0.8 + * @deprecated since 0.13, please use start and end {@link Timestamp} instead. */ + @Deprecated @Immutable public abstract static class AggregationWindowData { @@ -237,7 +315,9 @@ public abstract class ViewData { * Cumulative {@code AggregationWindowData}. * * @since 0.8 + * @deprecated since 0.13, please use start and end {@link Timestamp} instead. */ + @Deprecated @Immutable @AutoValue // Suppress Checker Framework warning about missing @Nullable in generated equals method. @@ -288,7 +368,9 @@ public abstract class ViewData { * Interval {@code AggregationWindowData}. * * @since 0.8 + * @deprecated since 0.13, please use start and end {@link Timestamp} instead. */ + @Deprecated @Immutable @AutoValue // Suppress Checker Framework warning about missing @Nullable in generated equals method. diff --git a/api/src/test/java/io/opencensus/stats/NoopViewManagerTest.java b/api/src/test/java/io/opencensus/stats/NoopViewManagerTest.java index 4aaa60dc..44c7626f 100644 --- a/api/src/test/java/io/opencensus/stats/NoopViewManagerTest.java +++ b/api/src/test/java/io/opencensus/stats/NoopViewManagerTest.java @@ -105,6 +105,8 @@ public final class NoopViewManagerTest { ViewData viewData = viewManager.getView(VIEW_NAME); assertThat(viewData.getView()).isEqualTo(view); assertThat(viewData.getAggregationMap()).isEmpty(); + assertThat(viewData.getStart()).isEqualTo(Timestamp.create(0, 0)); + assertThat(viewData.getEnd()).isEqualTo(Timestamp.create(0, 0)); assertThat(viewData.getWindowData()) .isEqualTo(CumulativeData.create(Timestamp.create(0, 0), Timestamp.create(0, 0))); } @@ -171,23 +173,13 @@ public final class NoopViewManagerTest { ViewManager viewManager = NoopStats.newNoopViewManager(); View view1 = View.create( - View.Name.create("View 1"), - VIEW_DESCRIPTION, - MEASURE, - AGGREGATION, - Arrays.asList(KEY), - CUMULATIVE); + View.Name.create("View 1"), VIEW_DESCRIPTION, MEASURE, AGGREGATION, Arrays.asList(KEY)); viewManager.registerView(view1); Set<View> exported = viewManager.getAllExportedViews(); View view2 = View.create( - View.Name.create("View 2"), - VIEW_DESCRIPTION, - MEASURE, - AGGREGATION, - Arrays.asList(KEY), - CUMULATIVE); + View.Name.create("View 2"), VIEW_DESCRIPTION, MEASURE, AGGREGATION, Arrays.asList(KEY)); thrown.expect(UnsupportedOperationException.class); exported.add(view2); } |