Skip to content

Commit

Permalink
move the ViewRegistry up one package, and clean up the visibility of …
Browse files Browse the repository at this point in the history
…other classes
  • Loading branch information
jwatson committed Jul 14, 2020
1 parent a739ad1 commit 69f8114
Show file tree
Hide file tree
Showing 24 changed files with 32 additions and 47 deletions.
1 change: 0 additions & 1 deletion sdk/src/jmh/java/io/opentelemetry/sdk/metrics/TestSdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.opentelemetry.metrics.Meter;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.internal.MillisClock;
import io.opentelemetry.sdk.metrics.view.ViewRegistry;
import io.opentelemetry.sdk.resources.Resource;

public enum TestSdk {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* cycle must be protected by a lock. A collection cycle is defined by multiple calls to {@link
* #batch(Labels, Aggregator, boolean)} followed by one {@link #completeCollectionCycle()};
*/
public interface Batcher {
interface Batcher {

/**
* Returns the {@link Aggregator} that should be used by the bindings, or observers.
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/main/java/io/opentelemetry/sdk/metrics/Batchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import java.util.Map;

/** A collection of available Batchers. */
public final class Batchers {
final class Batchers {

public static Batcher getNoop() {
static Batcher getNoop() {
return Noop.INSTANCE;
}

Expand All @@ -45,7 +45,7 @@ public static Batcher getNoop() {
* "Cumulative" means that all metrics that are generated will be considered for the lifetime of
* the Instrument being aggregated.
*/
public static Batcher getCumulativeAllLabels(
static Batcher getCumulativeAllLabels(
InstrumentDescriptor descriptor,
MeterProviderSharedState meterProviderSharedState,
MeterSharedState meterSharedState,
Expand All @@ -63,7 +63,7 @@ public static Batcher getCumulativeAllLabels(
* Create a Batcher that uses the "delta" Temporality and uses all labels for aggregation. "Delta"
* means that all metrics that are generated are only for the most recent collection interval.
*/
public static Batcher getDeltaAllLabels(
static Batcher getDeltaAllLabels(
InstrumentDescriptor descriptor,
MeterProviderSharedState meterProviderSharedState,
MeterSharedState meterSharedState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

@AutoValue
@Immutable
public abstract class InstrumentDescriptor {
public static InstrumentDescriptor create(
abstract class InstrumentDescriptor {
static InstrumentDescriptor create(
String name,
String description,
String unit,
Expand All @@ -45,7 +45,7 @@ public static InstrumentDescriptor create(

abstract Labels getConstantLabels();

public abstract InstrumentType getType();
abstract InstrumentType getType();

abstract InstrumentValueType getValueType();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

@AutoValue
@Immutable
public abstract class MeterProviderSharedState {
abstract class MeterProviderSharedState {
static MeterProviderSharedState create(Clock clock, Resource resource) {
return new AutoValue_MeterProviderSharedState(clock, resource);
}

public abstract Clock getClock();
abstract Clock getClock();

abstract Resource getResource();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.opentelemetry.metrics.Meter;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.view.ViewRegistry;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.export.MetricProducer;
import io.opentelemetry.sdk.metrics.view.InstrumentSelector;
import io.opentelemetry.sdk.metrics.view.ViewRegistry;
import io.opentelemetry.sdk.metrics.view.ViewSpecification;
import io.opentelemetry.sdk.resources.EnvVarResource;
import io.opentelemetry.sdk.resources.Resource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@AutoValue
@Immutable
public abstract class MeterSharedState {
abstract class MeterSharedState {
static MeterSharedState create(InstrumentationLibraryInfo instrumentationLibraryInfo) {
return new AutoValue_MeterSharedState(instrumentationLibraryInfo, new InstrumentRegistry());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
* limitations under the License.
*/

package io.opentelemetry.sdk.metrics.view;
package io.opentelemetry.sdk.metrics;

import io.opentelemetry.sdk.metrics.Batcher;
import io.opentelemetry.sdk.metrics.Batchers;
import io.opentelemetry.sdk.metrics.InstrumentDescriptor;
import io.opentelemetry.sdk.metrics.MeterProviderSharedState;
import io.opentelemetry.sdk.metrics.MeterSharedState;
import io.opentelemetry.sdk.metrics.view.Aggregation;
import io.opentelemetry.sdk.metrics.view.Aggregations;
import io.opentelemetry.sdk.metrics.view.InstrumentSelector;
import io.opentelemetry.sdk.metrics.view.ViewSpecification;
import io.opentelemetry.sdk.metrics.view.ViewSpecification.Temporality;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -42,20 +41,23 @@
* Central location for Views to be registered. Registration of a view should eventually be done via
* the {@link io.opentelemetry.sdk.metrics.MeterSdkProvider}.
*/
public class ViewRegistry {
class ViewRegistry {

public static final ViewSpecification CUMULATIVE_SUM =
private static final ViewSpecification CUMULATIVE_SUM =
ViewSpecification.create(Aggregations.sum(), Temporality.CUMULATIVE);
public static final ViewSpecification DELTA_SUMMARY =
private static final ViewSpecification DELTA_SUMMARY =
ViewSpecification.create(Aggregations.minMaxSumCount(), Temporality.DELTA);
public static final ViewSpecification CUMULATIVE_LAST_VALUE =
private static final ViewSpecification CUMULATIVE_LAST_VALUE =
ViewSpecification.create(Aggregations.lastValue(), Temporality.CUMULATIVE);

private final Map<InstrumentSelector, ViewSpecification> configuration =
new ConcurrentHashMap<>();

/** Create a new {@link Batcher} for use in metric recording aggregation. */
public Batcher createBatcher(
/**
* Create a new {@link io.opentelemetry.sdk.metrics.Batcher} for use in metric recording
* aggregation.
*/
Batcher createBatcher(
MeterProviderSharedState meterProviderSharedState,
MeterSharedState meterSharedState,
InstrumentDescriptor descriptor) {
Expand Down Expand Up @@ -92,6 +94,8 @@ private static ViewSpecification getDefaultSpecification(InstrumentDescriptor de
case COUNTER:
case UP_DOWN_COUNTER:
return CUMULATIVE_SUM;
// TODO: Revisit the batcher used here for value observers,
// currently this does not remove duplicate records in the same cycle.
case VALUE_OBSERVER:
case VALUE_RECORDER:
return DELTA_SUMMARY;
Expand All @@ -102,8 +106,7 @@ private static ViewSpecification getDefaultSpecification(InstrumentDescriptor de
throw new IllegalArgumentException("Unknown descriptor type: " + descriptor.getType());
}

/** todo: javadoc me. */
public void registerView(InstrumentSelector selector, ViewSpecification specification) {
void registerView(InstrumentSelector selector, ViewSpecification specification) {
configuration.put(selector, specification);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
import io.opentelemetry.sdk.metrics.data.MetricData.DoublePoint;
import io.opentelemetry.sdk.metrics.data.MetricData.LongPoint;
import io.opentelemetry.sdk.metrics.view.ViewRegistry;
import io.opentelemetry.sdk.resources.Resource;
import java.util.Collections;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
import io.opentelemetry.sdk.metrics.data.MetricData.DoublePoint;
import io.opentelemetry.sdk.metrics.view.ViewRegistry;
import io.opentelemetry.sdk.resources.Resource;
import java.util.List;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
import io.opentelemetry.sdk.metrics.data.MetricData.DoublePoint;
import io.opentelemetry.sdk.metrics.view.ViewRegistry;
import io.opentelemetry.sdk.resources.Resource;
import java.util.Collections;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
import io.opentelemetry.sdk.metrics.data.MetricData.DoublePoint;
import io.opentelemetry.sdk.metrics.view.ViewRegistry;
import io.opentelemetry.sdk.resources.Resource;
import java.util.List;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
import io.opentelemetry.sdk.metrics.data.MetricData.DoublePoint;
import io.opentelemetry.sdk.metrics.view.ViewRegistry;
import io.opentelemetry.sdk.resources.Resource;
import java.util.Collections;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
import io.opentelemetry.sdk.metrics.data.MetricData.SummaryPoint;
import io.opentelemetry.sdk.metrics.data.MetricData.ValueAtPercentile;
import io.opentelemetry.sdk.metrics.view.ViewRegistry;
import io.opentelemetry.sdk.resources.Resource;
import java.util.Arrays;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
import io.opentelemetry.sdk.metrics.data.MetricData.SummaryPoint;
import io.opentelemetry.sdk.metrics.data.MetricData.ValueAtPercentile;
import io.opentelemetry.sdk.metrics.view.ViewRegistry;
import io.opentelemetry.sdk.resources.Resource;
import java.util.Arrays;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
import io.opentelemetry.sdk.metrics.data.MetricData.LongPoint;
import io.opentelemetry.sdk.metrics.view.ViewRegistry;
import io.opentelemetry.sdk.resources.Resource;
import java.util.List;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
import io.opentelemetry.sdk.metrics.data.MetricData.LongPoint;
import io.opentelemetry.sdk.metrics.view.ViewRegistry;
import io.opentelemetry.sdk.resources.Resource;
import java.util.Collections;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
import io.opentelemetry.sdk.metrics.data.MetricData.LongPoint;
import io.opentelemetry.sdk.metrics.view.ViewRegistry;
import io.opentelemetry.sdk.resources.Resource;
import java.util.List;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
import io.opentelemetry.sdk.metrics.data.MetricData.LongPoint;
import io.opentelemetry.sdk.metrics.view.ViewRegistry;
import io.opentelemetry.sdk.resources.Resource;
import java.util.Collections;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
import io.opentelemetry.sdk.metrics.data.MetricData.SummaryPoint;
import io.opentelemetry.sdk.metrics.data.MetricData.ValueAtPercentile;
import io.opentelemetry.sdk.metrics.view.ViewRegistry;
import io.opentelemetry.sdk.resources.Resource;
import java.util.Arrays;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
import io.opentelemetry.sdk.metrics.data.MetricData.SummaryPoint;
import io.opentelemetry.sdk.metrics.data.MetricData.ValueAtPercentile;
import io.opentelemetry.sdk.metrics.view.ViewRegistry;
import io.opentelemetry.sdk.resources.Resource;
import java.util.Arrays;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io.opentelemetry.sdk.metrics.data.MetricData.LongPoint;
import io.opentelemetry.sdk.metrics.data.MetricData.SummaryPoint;
import io.opentelemetry.sdk.metrics.data.MetricData.ValueAtPercentile;
import io.opentelemetry.sdk.metrics.view.ViewRegistry;
import io.opentelemetry.sdk.resources.Resource;
import java.util.Arrays;
import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@
* limitations under the License.
*/

package io.opentelemetry.sdk.metrics.view;
package io.opentelemetry.sdk.metrics;

import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;

import io.opentelemetry.common.Labels;
import io.opentelemetry.sdk.internal.TestClock;
import io.opentelemetry.sdk.metrics.Batcher;
import io.opentelemetry.sdk.metrics.InstrumentDescriptor;
import io.opentelemetry.sdk.metrics.MeterProviderSharedState;
import io.opentelemetry.sdk.metrics.MeterSharedState;
import io.opentelemetry.sdk.metrics.aggregator.DoubleLastValueAggregator;
import io.opentelemetry.sdk.metrics.aggregator.DoubleMinMaxSumCount;
import io.opentelemetry.sdk.metrics.aggregator.DoubleSumAggregator;
Expand All @@ -33,6 +29,9 @@
import io.opentelemetry.sdk.metrics.aggregator.LongSumAggregator;
import io.opentelemetry.sdk.metrics.common.InstrumentType;
import io.opentelemetry.sdk.metrics.common.InstrumentValueType;
import io.opentelemetry.sdk.metrics.view.Aggregations;
import io.opentelemetry.sdk.metrics.view.InstrumentSelector;
import io.opentelemetry.sdk.metrics.view.ViewSpecification;
import io.opentelemetry.sdk.metrics.view.ViewSpecification.Temporality;
import org.junit.Before;
import org.junit.Test;
Expand Down

0 comments on commit 69f8114

Please sign in to comment.