Remove export component from metrics. Cleanup metrics API.
This commit is contained in:
parent
2a077ce1fa
commit
4124fdacc8
|
@ -21,6 +21,8 @@ import java.util.List;
|
|||
import javax.annotation.concurrent.ThreadSafe;
|
||||
import openconsensus.common.ToDoubleFunction;
|
||||
import openconsensus.internal.Utils;
|
||||
import openconsensus.metrics.data.LabelKey;
|
||||
import openconsensus.metrics.data.LabelValue;
|
||||
|
||||
/**
|
||||
* Derived Double Gauge metric, to report instantaneous measurement of a double value. Gauges can go
|
||||
|
|
|
@ -21,6 +21,8 @@ import java.util.List;
|
|||
import javax.annotation.concurrent.ThreadSafe;
|
||||
import openconsensus.common.ToLongFunction;
|
||||
import openconsensus.internal.Utils;
|
||||
import openconsensus.metrics.data.LabelKey;
|
||||
import openconsensus.metrics.data.LabelValue;
|
||||
|
||||
/**
|
||||
* Derived Long Gauge metric, to report instantaneous measurement of an int64 value. Gauges can go
|
||||
|
|
|
@ -19,6 +19,8 @@ package openconsensus.metrics;
|
|||
import java.util.List;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
import openconsensus.internal.Utils;
|
||||
import openconsensus.metrics.data.LabelKey;
|
||||
import openconsensus.metrics.data.LabelValue;
|
||||
|
||||
/**
|
||||
* Double Gauge metric, to report instantaneous measurement of a double value. Gauges can go both up
|
||||
|
|
|
@ -19,6 +19,8 @@ package openconsensus.metrics;
|
|||
import java.util.List;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
import openconsensus.internal.Utils;
|
||||
import openconsensus.metrics.data.LabelKey;
|
||||
import openconsensus.metrics.data.LabelValue;
|
||||
|
||||
/**
|
||||
* Long Gauge metric, to report instantaneous measurement of an int64 value. Gauges can go both up
|
||||
|
|
|
@ -16,22 +16,24 @@
|
|||
|
||||
package openconsensus.metrics;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import openconsensus.common.ExperimentalApi;
|
||||
import openconsensus.common.ToDoubleFunction;
|
||||
import openconsensus.common.ToLongFunction;
|
||||
import openconsensus.internal.Utils;
|
||||
import openconsensus.metrics.export.MetricProducer;
|
||||
import openconsensus.metrics.export.MetricProducerManager;
|
||||
import openconsensus.metrics.data.LabelKey;
|
||||
import openconsensus.metrics.data.Metric;
|
||||
import openconsensus.metrics.producer.MetricProducer;
|
||||
|
||||
/**
|
||||
* Creates and manages your application's set of metrics. The default implementation of this creates
|
||||
* a {@link MetricProducer} and registers it to the global {@link MetricProducerManager}.
|
||||
* Creates and manages your application's set of metrics.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@ExperimentalApi
|
||||
public abstract class MetricRegistry {
|
||||
public abstract class MetricRegistry extends MetricProducer {
|
||||
/**
|
||||
* Builds a new long gauge to be added to the registry. This is more convenient form when you want
|
||||
* to manually increase and decrease values as per your service requirements.
|
||||
|
@ -153,5 +155,10 @@ public abstract class MetricRegistry {
|
|||
Utils.checkNotNull(unit, "unit"),
|
||||
labelKeys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Metric> getMetrics() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
package openconsensus.metrics;
|
||||
|
||||
import openconsensus.common.ExperimentalApi;
|
||||
import openconsensus.metrics.export.ExportComponent;
|
||||
import openconsensus.metrics.export.MetricProducerManager;
|
||||
|
||||
/**
|
||||
* Class for accessing the default {@link MetricsComponent}.
|
||||
|
@ -27,23 +25,12 @@ import openconsensus.metrics.export.MetricProducerManager;
|
|||
*/
|
||||
@ExperimentalApi
|
||||
public final class Metrics {
|
||||
private static final MetricsComponent metricsComponent =MetricsComponent.newNoopMetricsComponent();
|
||||
|
||||
/**
|
||||
* Returns the global {@link ExportComponent}.
|
||||
*
|
||||
* @return the global {@code ExportComponent}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public static ExportComponent getExportComponent() {
|
||||
return metricsComponent.getExportComponent();
|
||||
}
|
||||
private static final MetricsComponent metricsComponent =
|
||||
MetricsComponent.newNoopMetricsComponent();
|
||||
|
||||
/**
|
||||
* Returns the global {@link MetricRegistry}.
|
||||
*
|
||||
* <p>This {@code MetricRegistry} is already added to the global {@link MetricProducerManager}.
|
||||
*
|
||||
* @return the global {@code MetricRegistry}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
|
|
|
@ -17,25 +17,14 @@
|
|||
package openconsensus.metrics;
|
||||
|
||||
import openconsensus.common.ExperimentalApi;
|
||||
import openconsensus.metrics.export.ExportComponent;
|
||||
|
||||
/**
|
||||
* Class that holds the implementation instance for {@link ExportComponent}.
|
||||
* Class that holds the implementation instance for {@link MetricRegistry}.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@ExperimentalApi
|
||||
public abstract class MetricsComponent {
|
||||
|
||||
/**
|
||||
* Returns the {@link ExportComponent} with the provided implementation. If no implementation is
|
||||
* provided then no-op implementations will be used.
|
||||
*
|
||||
* @return the {@link ExportComponent} implementation.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public abstract ExportComponent getExportComponent();
|
||||
|
||||
/**
|
||||
* Returns the {@link MetricRegistry} with the provided implementation.
|
||||
*
|
||||
|
@ -54,15 +43,8 @@ public abstract class MetricsComponent {
|
|||
}
|
||||
|
||||
private static final class NoopMetricsComponent extends MetricsComponent {
|
||||
private static final ExportComponent EXPORT_COMPONENT =
|
||||
ExportComponent.newNoopExportComponent();
|
||||
private static final MetricRegistry METRIC_REGISTRY = MetricRegistry.newNoopMetricRegistry();
|
||||
|
||||
@Override
|
||||
public ExportComponent getExportComponent() {
|
||||
return EXPORT_COMPONENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetricRegistry getMetricRegistry() {
|
||||
return METRIC_REGISTRY;
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package openconsensus.metrics;
|
||||
package openconsensus.metrics.data;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import javax.annotation.concurrent.Immutable;
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package openconsensus.metrics;
|
||||
package openconsensus.metrics.data;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import javax.annotation.Nullable;
|
|
@ -23,7 +23,6 @@ import java.util.List;
|
|||
import javax.annotation.concurrent.Immutable;
|
||||
import openconsensus.common.ExperimentalApi;
|
||||
import openconsensus.internal.Utils;
|
||||
import openconsensus.metrics.LabelKey;
|
||||
|
||||
/**
|
||||
* {@link MetricDescriptor} defines a {@code Metric} type and its schema.
|
||||
|
|
|
@ -25,8 +25,6 @@ import javax.annotation.concurrent.Immutable;
|
|||
import openconsensus.common.ExperimentalApi;
|
||||
import openconsensus.common.Timestamp;
|
||||
import openconsensus.internal.Utils;
|
||||
import openconsensus.metrics.LabelKey;
|
||||
import openconsensus.metrics.LabelValue;
|
||||
|
||||
/**
|
||||
* A collection of data points that describes the time-varying values of a {@code Metric}.
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Copyright 2019, OpenConsensus Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package openconsensus.metrics.export;
|
||||
|
||||
import openconsensus.common.ExperimentalApi;
|
||||
|
||||
/**
|
||||
* Class that holds the implementation instance for {@link MetricProducerManager}.
|
||||
*
|
||||
* <p>Unless otherwise noted all methods (on component) results are cacheable.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@ExperimentalApi
|
||||
public abstract class ExportComponent {
|
||||
/**
|
||||
* Returns the no-op implementation of the {@code ExportComponent}.
|
||||
*
|
||||
* @return the no-op implementation of the {@code ExportComponent}.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public static ExportComponent newNoopExportComponent() {
|
||||
return new NoopExportComponent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the global {@link MetricProducerManager} which can be used to register handlers to
|
||||
* export all the recorded metrics.
|
||||
*
|
||||
* @return the implementation of the {@code MetricExporter} or no-op if no implementation linked
|
||||
* in the binary.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public abstract MetricProducerManager getMetricProducerManager();
|
||||
|
||||
private static final class NoopExportComponent extends ExportComponent {
|
||||
|
||||
private static final MetricProducerManager METRIC_PRODUCER_MANAGER =
|
||||
MetricProducerManager.newNoopMetricProducerManager();
|
||||
|
||||
@Override
|
||||
public MetricProducerManager getMetricProducerManager() {
|
||||
return METRIC_PRODUCER_MANAGER;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
/*
|
||||
* Copyright 2019, OpenConsensus Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package openconsensus.metrics.export;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import javax.annotation.concurrent.ThreadSafe;
|
||||
import openconsensus.common.ExperimentalApi;
|
||||
import openconsensus.internal.Utils;
|
||||
|
||||
/**
|
||||
* Keeps a set of {@link MetricProducer} that is used by exporters to determine the metrics that
|
||||
* need to be exported.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
@ExperimentalApi
|
||||
@ThreadSafe
|
||||
public abstract class MetricProducerManager {
|
||||
|
||||
/**
|
||||
* Adds the {@link MetricProducer} to the manager if it is not already present.
|
||||
*
|
||||
* @param metricProducer the {@code MetricProducer} to be added to the manager.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public abstract void add(MetricProducer metricProducer);
|
||||
|
||||
/**
|
||||
* Removes the {@link MetricProducer} to the manager if it is present.
|
||||
*
|
||||
* @param metricProducer the {@code MetricProducer} to be removed from the manager.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public abstract void remove(MetricProducer metricProducer);
|
||||
|
||||
/**
|
||||
* Returns all registered {@link MetricProducer}s that should be exported.
|
||||
*
|
||||
* <p>This method should be used by any metrics exporter that automatically exports data for
|
||||
* {@code MetricProducer} registered with the {@code MetricProducerManager}.
|
||||
*
|
||||
* @return all registered {@code MetricProducer}s that should be exported.
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public abstract Set<MetricProducer> getAllMetricProducer();
|
||||
|
||||
/**
|
||||
* Returns a no-op implementation for {@link MetricProducerManager}.
|
||||
*
|
||||
* @return a no-op implementation for {@code MetricProducerManager}.
|
||||
*/
|
||||
static MetricProducerManager newNoopMetricProducerManager() {
|
||||
return new NoopMetricProducerManager();
|
||||
}
|
||||
|
||||
private static final class NoopMetricProducerManager extends MetricProducerManager {
|
||||
|
||||
@Override
|
||||
public void add(MetricProducer metricProducer) {
|
||||
Utils.checkNotNull(metricProducer, "metricProducer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(MetricProducer metricProducer) {
|
||||
Utils.checkNotNull(metricProducer, "metricProducer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<MetricProducer> getAllMetricProducer() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,15 +14,14 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package openconsensus.metrics.export;
|
||||
package openconsensus.metrics.producer;
|
||||
|
||||
import java.util.Collection;
|
||||
import openconsensus.common.ExperimentalApi;
|
||||
import openconsensus.metrics.data.Metric;
|
||||
|
||||
/**
|
||||
* A {@link Metric} producer that can be registered for exporting using {@link
|
||||
* MetricProducerManager}.
|
||||
* A {@link Metric} producer that can be registered for exporting.
|
||||
*
|
||||
* <p>All implementation MUST be thread-safe.
|
||||
*
|
Loading…
Reference in New Issue