diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/MetricRegistry.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/MetricRegistry.java index 266ac7bc130f..b4caed95ee7a 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/MetricRegistry.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/MetricRegistry.java @@ -53,7 +53,7 @@ * */ public class MetricRegistry { - static final String METER_NAME = "bigtable.googleapis.com/internal/client/"; + public static final String METER_NAME = "bigtable.googleapis.com/internal/client/"; final TableOperationLatency operationLatencyMetric; final TableAttemptLatency attemptLatencyMetric; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/MetricsImpl.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/MetricsImpl.java index c7bf85943166..c149ecf30cf2 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/MetricsImpl.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/MetricsImpl.java @@ -24,13 +24,12 @@ import com.google.cloud.bigtable.data.v2.internal.csm.MetricRegistry.RecorderRegistry; import com.google.cloud.bigtable.data.v2.internal.csm.attributes.ClientInfo; import com.google.cloud.bigtable.data.v2.internal.csm.attributes.EnvInfo; +import com.google.cloud.bigtable.data.v2.internal.csm.opencensus.MetricsTracerFactory; +import com.google.cloud.bigtable.data.v2.internal.csm.opencensus.RpcMeasureConstants; import com.google.cloud.bigtable.data.v2.stub.metrics.BigtableCloudMonitoringExporter; -import com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants; import com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsTracerFactory; import com.google.cloud.bigtable.data.v2.stub.metrics.ChannelPoolMetricsTracer; import com.google.cloud.bigtable.data.v2.stub.metrics.CompositeTracerFactory; -import com.google.cloud.bigtable.data.v2.stub.metrics.MetricsTracerFactory; -import com.google.cloud.bigtable.data.v2.stub.metrics.RpcMeasureConstants; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -42,10 +41,8 @@ import io.opencensus.tags.Tagger; import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.sdk.OpenTelemetrySdk; -import io.opentelemetry.sdk.metrics.InstrumentSelector; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder; -import io.opentelemetry.sdk.metrics.View; import io.opentelemetry.sdk.metrics.export.MetricExporter; import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader; import io.opentelemetry.sdk.metrics.export.PeriodicMetricReaderBuilder; @@ -53,7 +50,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import javax.annotation.Nullable; @@ -100,7 +96,7 @@ public MetricsImpl( // Disable default grpc metrics .disableAllMetrics() // Enable specific grpc metrics - .enableMetrics(BuiltinMetricsConstants.GRPC_METRICS.keySet()) + .enableMetrics(metricRegistry.getGrpcMetricNames()) .build(); } else { this.grpcOtel = null; @@ -185,16 +181,6 @@ public static OpenTelemetrySdk createBuiltinOtel( SdkMeterProviderBuilder meterProvider = SdkMeterProvider.builder(); - for (Map.Entry entry : - BuiltinMetricsConstants.getAllViews().entrySet()) { - meterProvider.registerView(entry.getKey(), entry.getValue()); - } - - for (Map.Entry e : - BuiltinMetricsConstants.getInternalViews().entrySet()) { - meterProvider.registerView(e.getKey(), e.getValue()); - } - MetricExporter publicExporter = BigtableCloudMonitoringExporter.create( metricRegistry, diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/attributes/Util.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/attributes/Util.java index 818e0b885989..493abf8acbab 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/attributes/Util.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/attributes/Util.java @@ -16,12 +16,16 @@ package com.google.cloud.bigtable.data.v2.internal.csm.attributes; +import com.google.api.gax.grpc.GrpcStatusCode; +import com.google.api.gax.rpc.ApiException; import com.google.bigtable.v2.PeerInfo; import com.google.bigtable.v2.PeerInfo.TransportType; import com.google.bigtable.v2.ResponseParams; import com.google.common.annotations.VisibleForTesting; +import io.grpc.Status; import java.util.Locale; import java.util.Optional; +import java.util.concurrent.CancellationException; import javax.annotation.Nullable; public class Util { @@ -100,4 +104,26 @@ public static String formatZoneIdMetricLabel(@Nullable ResponseParams clusterInf .filter(s -> !s.isEmpty()) .orElse("global"); } + + public static Status.Code extractStatus(@Nullable Throwable error) { + if (error == null) { + return Status.Code.OK; + } + // Handle java CancellationException as if it was a gax CancelledException + if (error instanceof CancellationException) { + return Status.Code.CANCELLED; + } + if (error instanceof ApiException) { + ApiException apiException = (ApiException) error; + if (apiException.getStatusCode() instanceof GrpcStatusCode) { + return ((GrpcStatusCode) apiException.getStatusCode()).getTransportCode(); + } + } + + Status s = Status.fromThrowable(error); + if (s != null) { + return s.getCode(); + } + return Status.Code.UNKNOWN; + } } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/ClientBatchWriteFlowControlFactor.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/ClientBatchWriteFlowControlFactor.java index 2c5a989d51f3..c4c6d9711829 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/ClientBatchWriteFlowControlFactor.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/ClientBatchWriteFlowControlFactor.java @@ -25,7 +25,7 @@ import io.opentelemetry.api.metrics.Meter; public class ClientBatchWriteFlowControlFactor extends MetricWrapper { - private static final String NAME = + public static final String NAME = "bigtable.googleapis.com/internal/client/batch_write_flow_control_factor"; public ClientBatchWriteFlowControlFactor() { diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/ClientBatchWriteFlowControlTargetQps.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/ClientBatchWriteFlowControlTargetQps.java index fb6f55894f88..a15189aa4a04 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/ClientBatchWriteFlowControlTargetQps.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/ClientBatchWriteFlowControlTargetQps.java @@ -24,7 +24,7 @@ import io.opentelemetry.api.metrics.Meter; public class ClientBatchWriteFlowControlTargetQps extends MetricWrapper { - private static final String NAME = + public static final String NAME = "bigtable.googleapis.com/internal/client/batch_write_flow_control_target_qps"; public ClientBatchWriteFlowControlTargetQps() { diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/ClientChannelPoolOutstandingRpcs.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/ClientChannelPoolOutstandingRpcs.java index addd28a53382..c5c1589c4fda 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/ClientChannelPoolOutstandingRpcs.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/ClientChannelPoolOutstandingRpcs.java @@ -28,7 +28,7 @@ import java.util.stream.Collectors; public class ClientChannelPoolOutstandingRpcs extends MetricWrapper { - private static final String NAME = + public static final String NAME = "bigtable.googleapis.com/internal/client/connection_pool/outstanding_rpcs"; private static final List BUCKETS = diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/ClientPerConnectionErrorCount.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/ClientPerConnectionErrorCount.java index 25ede477fb50..a6b2e89aaf0c 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/ClientPerConnectionErrorCount.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/ClientPerConnectionErrorCount.java @@ -32,7 +32,7 @@ import java.util.Set; public class ClientPerConnectionErrorCount extends MetricWrapper { - private static final String NAME = + public static final String NAME = "bigtable.googleapis.com/internal/client/per_connection_error_count"; static final List BUCKETS = diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/Constants.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/Constants.java index 768f451e0e59..f0f1a7c839c3 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/Constants.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/Constants.java @@ -54,7 +54,7 @@ private MetricLabels() {} AttributeKey.stringKey("app_profile"); public static final AttributeKey DEBUG_TAG_KEY = AttributeKey.stringKey("tag"); - static final AttributeKey APPLIED_KEY = AttributeKey.booleanKey("applied"); + public static final AttributeKey APPLIED_KEY = AttributeKey.booleanKey("applied"); static final AttributeKey CHANNEL_POOL_LB_POLICY = AttributeKey.stringKey("lb_policy"); static final AttributeKey DP_REASON_KEY = AttributeKey.stringKey("reason"); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableApplicationBlockingLatency.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableApplicationBlockingLatency.java index 05fdefd0be52..9fd5561d0f24 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableApplicationBlockingLatency.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableApplicationBlockingLatency.java @@ -32,8 +32,7 @@ import javax.annotation.Nullable; public class TableApplicationBlockingLatency extends MetricWrapper { - private static final String NAME = - "bigtable.googleapis.com/internal/client/application_latencies"; + public static final String NAME = "bigtable.googleapis.com/internal/client/application_latencies"; public TableApplicationBlockingLatency() { super(TableSchema.INSTANCE, NAME); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableAttemptLatency.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableAttemptLatency.java index 530498fa9a4c..e792cb8eb8d7 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableAttemptLatency.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableAttemptLatency.java @@ -33,7 +33,7 @@ import javax.annotation.Nullable; public class TableAttemptLatency extends MetricWrapper { - private static final String NAME = "bigtable.googleapis.com/internal/client/attempt_latencies"; + public static final String NAME = "bigtable.googleapis.com/internal/client/attempt_latencies"; public TableAttemptLatency() { super(TableSchema.INSTANCE, NAME); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableAttemptLatency2.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableAttemptLatency2.java index 63cb2aa9298c..ca895e0e1bc6 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableAttemptLatency2.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableAttemptLatency2.java @@ -34,7 +34,7 @@ import javax.annotation.Nullable; public class TableAttemptLatency2 extends MetricWrapper { - private static final String NAME = "bigtable.googleapis.com/internal/client/attempt_latencies2"; + public static final String NAME = "bigtable.googleapis.com/internal/client/attempt_latencies2"; public TableAttemptLatency2() { super(TableSchema.INSTANCE, NAME); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableClientBlockingLatency.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableClientBlockingLatency.java index 7f9a584a695f..7fc46c5559d6 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableClientBlockingLatency.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableClientBlockingLatency.java @@ -32,7 +32,7 @@ import javax.annotation.Nullable; public class TableClientBlockingLatency extends MetricWrapper { - private static final String NAME = "bigtable.googleapis.com/internal/client/throttling_latencies"; + public static final String NAME = "bigtable.googleapis.com/internal/client/throttling_latencies"; public TableClientBlockingLatency() { super(TableSchema.INSTANCE, NAME); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableConnectivityErrorCount.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableConnectivityErrorCount.java index 0233b8adefd3..3f99f90248e5 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableConnectivityErrorCount.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableConnectivityErrorCount.java @@ -31,7 +31,7 @@ import javax.annotation.Nullable; public class TableConnectivityErrorCount extends MetricWrapper { - private static final String NAME = + public static final String NAME = "bigtable.googleapis.com/internal/client/connectivity_error_count"; public TableConnectivityErrorCount() { diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableFirstResponseLatency.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableFirstResponseLatency.java index bde5009f6839..6ad09e7798f9 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableFirstResponseLatency.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableFirstResponseLatency.java @@ -33,7 +33,7 @@ import javax.annotation.Nullable; public class TableFirstResponseLatency extends MetricWrapper { - private static final String NAME = + public static final String NAME = "bigtable.googleapis.com/internal/client/first_response_latencies"; public TableFirstResponseLatency() { diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableOperationLatency.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableOperationLatency.java index 4a30d66f20e3..781501100fd4 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableOperationLatency.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableOperationLatency.java @@ -33,7 +33,7 @@ import javax.annotation.Nullable; public class TableOperationLatency extends MetricWrapper { - private static final String NAME = "bigtable.googleapis.com/internal/client/operation_latencies"; + public static final String NAME = "bigtable.googleapis.com/internal/client/operation_latencies"; public TableOperationLatency() { super(TableSchema.INSTANCE, NAME); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableRemainingDeadline.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableRemainingDeadline.java index 3e911d42e62b..314f9874c8b9 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableRemainingDeadline.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableRemainingDeadline.java @@ -32,7 +32,7 @@ import java.time.Duration; public class TableRemainingDeadline extends MetricWrapper { - private static final String NAME = "bigtable.googleapis.com/internal/client/remaining_deadline"; + public static final String NAME = "bigtable.googleapis.com/internal/client/remaining_deadline"; public TableRemainingDeadline() { super(TableSchema.INSTANCE, NAME); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableRetryCount.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableRetryCount.java index a81a4bf903ab..205bf8396284 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableRetryCount.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableRetryCount.java @@ -31,7 +31,7 @@ import javax.annotation.Nullable; public class TableRetryCount extends MetricWrapper { - private static final String NAME = "bigtable.googleapis.com/internal/client/retry_count"; + public static final String NAME = "bigtable.googleapis.com/internal/client/retry_count"; public TableRetryCount() { super(TableSchema.INSTANCE, NAME); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableServerLatency.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableServerLatency.java index 0d8dc0197b6b..cafc0c245e6c 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableServerLatency.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/metrics/TableServerLatency.java @@ -33,7 +33,7 @@ import javax.annotation.Nullable; public class TableServerLatency extends MetricWrapper { - private static final String NAME = "bigtable.googleapis.com/internal/client/server_latencies"; + public static final String NAME = "bigtable.googleapis.com/internal/client/server_latencies"; public TableServerLatency() { super(TableSchema.INSTANCE, NAME); diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracer.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/MetricsTracer.java similarity index 97% rename from google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracer.java rename to google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/MetricsTracer.java index 448d8b442bdf..921d0329ad55 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracer.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/MetricsTracer.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.google.cloud.bigtable.data.v2.stub.metrics; +package com.google.cloud.bigtable.data.v2.internal.csm.opencensus; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; @@ -21,7 +21,9 @@ import com.google.api.gax.retrying.ServerStreamingAttemptException; import com.google.api.gax.tracing.ApiTracerFactory.OperationType; import com.google.api.gax.tracing.SpanName; +import com.google.cloud.bigtable.data.v2.internal.csm.attributes.Util; import com.google.cloud.bigtable.data.v2.stub.MetadataExtractorInterceptor; +import com.google.cloud.bigtable.data.v2.stub.metrics.BigtableTracer; import com.google.common.base.Stopwatch; import io.opencensus.stats.MeasureMap; import io.opencensus.stats.StatsRecorder; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerFactory.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/MetricsTracerFactory.java similarity index 96% rename from google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerFactory.java rename to google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/MetricsTracerFactory.java index e0c173a2be3c..0f557e65366c 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerFactory.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/MetricsTracerFactory.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.google.cloud.bigtable.data.v2.stub.metrics; +package com.google.cloud.bigtable.data.v2.internal.csm.opencensus; import com.google.api.core.InternalApi; import com.google.api.gax.tracing.ApiTracer; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/RpcMeasureConstants.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/RpcMeasureConstants.java similarity index 98% rename from google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/RpcMeasureConstants.java rename to google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/RpcMeasureConstants.java index 560bb084bf3a..39c9bb0e9988 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/RpcMeasureConstants.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/RpcMeasureConstants.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.google.cloud.bigtable.data.v2.stub.metrics; +package com.google.cloud.bigtable.data.v2.internal.csm.opencensus; import com.google.api.core.InternalApi; import io.opencensus.stats.Measure.MeasureLong; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/RpcViewConstants.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/RpcViewConstants.java similarity index 73% rename from google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/RpcViewConstants.java rename to google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/RpcViewConstants.java index 4e21eaf7855e..51af4269adde 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/RpcViewConstants.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/RpcViewConstants.java @@ -13,22 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.google.cloud.bigtable.data.v2.stub.metrics; - -import static com.google.cloud.bigtable.data.v2.stub.metrics.RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID; -import static com.google.cloud.bigtable.data.v2.stub.metrics.RpcMeasureConstants.BIGTABLE_ATTEMPT_LATENCY; -import static com.google.cloud.bigtable.data.v2.stub.metrics.RpcMeasureConstants.BIGTABLE_BATCH_THROTTLED_TIME; -import static com.google.cloud.bigtable.data.v2.stub.metrics.RpcMeasureConstants.BIGTABLE_GFE_HEADER_MISSING_COUNT; -import static com.google.cloud.bigtable.data.v2.stub.metrics.RpcMeasureConstants.BIGTABLE_GFE_LATENCY; -import static com.google.cloud.bigtable.data.v2.stub.metrics.RpcMeasureConstants.BIGTABLE_INSTANCE_ID; -import static com.google.cloud.bigtable.data.v2.stub.metrics.RpcMeasureConstants.BIGTABLE_OP; -import static com.google.cloud.bigtable.data.v2.stub.metrics.RpcMeasureConstants.BIGTABLE_OP_ATTEMPT_COUNT; -import static com.google.cloud.bigtable.data.v2.stub.metrics.RpcMeasureConstants.BIGTABLE_OP_LATENCY; -import static com.google.cloud.bigtable.data.v2.stub.metrics.RpcMeasureConstants.BIGTABLE_PROJECT_ID; -import static com.google.cloud.bigtable.data.v2.stub.metrics.RpcMeasureConstants.BIGTABLE_READ_ROWS_FIRST_ROW_LATENCY; -import static com.google.cloud.bigtable.data.v2.stub.metrics.RpcMeasureConstants.BIGTABLE_STATUS; +package com.google.cloud.bigtable.data.v2.internal.csm.opencensus; +import static com.google.cloud.bigtable.data.v2.internal.csm.opencensus.RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID; +import static com.google.cloud.bigtable.data.v2.internal.csm.opencensus.RpcMeasureConstants.BIGTABLE_ATTEMPT_LATENCY; +import static com.google.cloud.bigtable.data.v2.internal.csm.opencensus.RpcMeasureConstants.BIGTABLE_BATCH_THROTTLED_TIME; +import static com.google.cloud.bigtable.data.v2.internal.csm.opencensus.RpcMeasureConstants.BIGTABLE_GFE_HEADER_MISSING_COUNT; +import static com.google.cloud.bigtable.data.v2.internal.csm.opencensus.RpcMeasureConstants.BIGTABLE_GFE_LATENCY; +import static com.google.cloud.bigtable.data.v2.internal.csm.opencensus.RpcMeasureConstants.BIGTABLE_INSTANCE_ID; +import static com.google.cloud.bigtable.data.v2.internal.csm.opencensus.RpcMeasureConstants.BIGTABLE_OP; +import static com.google.cloud.bigtable.data.v2.internal.csm.opencensus.RpcMeasureConstants.BIGTABLE_OP_ATTEMPT_COUNT; +import static com.google.cloud.bigtable.data.v2.internal.csm.opencensus.RpcMeasureConstants.BIGTABLE_OP_LATENCY; +import static com.google.cloud.bigtable.data.v2.internal.csm.opencensus.RpcMeasureConstants.BIGTABLE_PROJECT_ID; +import static com.google.cloud.bigtable.data.v2.internal.csm.opencensus.RpcMeasureConstants.BIGTABLE_READ_ROWS_FIRST_ROW_LATENCY; +import static com.google.cloud.bigtable.data.v2.internal.csm.opencensus.RpcMeasureConstants.BIGTABLE_STATUS; + +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import io.opencensus.stats.Aggregation; import io.opencensus.stats.Aggregation.Count; import io.opencensus.stats.Aggregation.Distribution; @@ -37,7 +39,7 @@ import io.opencensus.stats.View; import java.util.Arrays; -class RpcViewConstants { +public class RpcViewConstants { // Aggregations private static final Aggregation COUNT = Count.create(); private static final Aggregation SUM = Sum.create(); @@ -167,4 +169,19 @@ class RpcViewConstants { AGGREGATION_WITH_MILLIS_HISTOGRAM, ImmutableList.of( BIGTABLE_INSTANCE_ID, BIGTABLE_PROJECT_ID, BIGTABLE_APP_PROFILE_ID, BIGTABLE_OP)); + + @VisibleForTesting + public static final ImmutableSet BIGTABLE_CLIENT_VIEWS_SET = + ImmutableSet.of( + RpcViewConstants.BIGTABLE_OP_LATENCY_VIEW, + RpcViewConstants.BIGTABLE_COMPLETED_OP_VIEW, + RpcViewConstants.BIGTABLE_READ_ROWS_FIRST_ROW_LATENCY_VIEW, + RpcViewConstants.BIGTABLE_ATTEMPT_LATENCY_VIEW, + RpcViewConstants.BIGTABLE_ATTEMPTS_PER_OP_VIEW, + RpcViewConstants.BIGTABLE_BATCH_THROTTLED_TIME_VIEW); + + public static final ImmutableSet GFE_VIEW_SET = + ImmutableSet.of( + RpcViewConstants.BIGTABLE_GFE_LATENCY_VIEW, + RpcViewConstants.BIGTABLE_GFE_HEADER_MISSING_COUNT_VIEW); } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/RateLimitingServerStreamingCallable.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/RateLimitingServerStreamingCallable.java index c9f9ba06c1d5..4f4f788aac93 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/RateLimitingServerStreamingCallable.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/RateLimitingServerStreamingCallable.java @@ -15,7 +15,7 @@ */ package com.google.cloud.bigtable.data.v2.stub; -import static com.google.cloud.bigtable.data.v2.stub.metrics.Util.extractStatus; +import static com.google.cloud.bigtable.data.v2.internal.csm.attributes.Util.extractStatus; import com.google.api.gax.rpc.ApiCallContext; import com.google.api.gax.rpc.DeadlineExceededException; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableExporterUtils.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableExporterUtils.java deleted file mode 100644 index f27c2b56f887..000000000000 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableExporterUtils.java +++ /dev/null @@ -1,471 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * 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 - * - * https://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 com.google.cloud.bigtable.data.v2.stub.metrics; - -import static com.google.api.Distribution.BucketOptions; -import static com.google.api.Distribution.BucketOptions.Explicit; -import static com.google.api.MetricDescriptor.MetricKind; -import static com.google.api.MetricDescriptor.MetricKind.CUMULATIVE; -import static com.google.api.MetricDescriptor.MetricKind.GAUGE; -import static com.google.api.MetricDescriptor.MetricKind.UNRECOGNIZED; -import static com.google.api.MetricDescriptor.ValueType; -import static com.google.api.MetricDescriptor.ValueType.DISTRIBUTION; -import static com.google.api.MetricDescriptor.ValueType.DOUBLE; -import static com.google.api.MetricDescriptor.ValueType.INT64; -import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.BIGTABLE_PROJECT_ID_KEY; -import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CLIENT_UID_KEY; -import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CLUSTER_ID_KEY; -import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.GRPC_METRICS; -import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.INSTANCE_ID_KEY; -import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.INTERNAL_METRICS; -import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.METER_NAME; -import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.TABLE_ID_KEY; -import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.ZONE_ID_KEY; - -import com.google.api.Distribution; -import com.google.api.Metric; -import com.google.api.MonitoredResource; -import com.google.cloud.bigtable.Version; -import com.google.cloud.bigtable.data.v2.internal.csm.attributes.ClientInfo; -import com.google.cloud.opentelemetry.detection.AttributeKeys; -import com.google.cloud.opentelemetry.detection.DetectedPlatform; -import com.google.cloud.opentelemetry.detection.GCPPlatformDetector; -import com.google.common.base.Preconditions; -import com.google.common.base.Supplier; -import com.google.common.base.Suppliers; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.monitoring.v3.Point; -import com.google.monitoring.v3.ProjectName; -import com.google.monitoring.v3.TimeInterval; -import com.google.monitoring.v3.TimeSeries; -import com.google.monitoring.v3.TypedValue; -import com.google.protobuf.Timestamp; -import com.google.protobuf.util.Timestamps; -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.sdk.metrics.data.AggregationTemporality; -import io.opentelemetry.sdk.metrics.data.DoublePointData; -import io.opentelemetry.sdk.metrics.data.HistogramData; -import io.opentelemetry.sdk.metrics.data.HistogramPointData; -import io.opentelemetry.sdk.metrics.data.LongPointData; -import io.opentelemetry.sdk.metrics.data.MetricData; -import io.opentelemetry.sdk.metrics.data.MetricDataType; -import io.opentelemetry.sdk.metrics.data.PointData; -import io.opentelemetry.sdk.metrics.data.SumData; -import java.lang.management.ManagementFactory; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicLong; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.stream.Collectors; -import javax.annotation.Nullable; - -/** Utils to convert OpenTelemetry types to Google Cloud Monitoring types. */ -class BigtableExporterUtils { - private static final String CLIENT_NAME = "java-bigtable/" + Version.VERSION; - - private static final Logger logger = Logger.getLogger(BigtableExporterUtils.class.getName()); - - private static final String BIGTABLE_RESOURCE_TYPE = "bigtable_client_raw"; - - // These metric labels will be promoted to the bigtable_table monitored resource fields - private static final Set> BIGTABLE_PROMOTED_RESOURCE_LABELS = - ImmutableSet.of( - BIGTABLE_PROJECT_ID_KEY, INSTANCE_ID_KEY, TABLE_ID_KEY, CLUSTER_ID_KEY, ZONE_ID_KEY); - - private static final Map SUPPORTED_PLATFORM_MAP = - ImmutableMap.of( - GCPPlatformDetector.SupportedPlatform.GOOGLE_COMPUTE_ENGINE, "gcp_compute_engine", - GCPPlatformDetector.SupportedPlatform.GOOGLE_KUBERNETES_ENGINE, "gcp_kubernetes_engine"); - - private static final AtomicLong nextUuidSuffix = new AtomicLong(); - - private BigtableExporterUtils() {} - - /** - * In most cases this should look like java-${UUID}@${hostname}. The hostname will be retrieved - * from the jvm name and fallback to the local hostname. - */ - private static String defaultTaskValue = null; - - static final Supplier DEFAULT_TASK_VALUE = - Suppliers.memoize(BigtableExporterUtils::computeDefaultTaskValue); - - private static String computeDefaultTaskValue() { - if (defaultTaskValue != null) { - return defaultTaskValue; - } - // Something like '@' - final String jvmName = ManagementFactory.getRuntimeMXBean().getName(); - // If jvm doesn't have the expected format, fallback to the local hostname - if (jvmName.indexOf('@') < 1) { - String hostname = "localhost"; - try { - hostname = InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException e) { - logger.log(Level.INFO, "Unable to get the hostname.", e); - } - // Generate a random number and use the same format "random_number@hostname". - return "java-" + UUID.randomUUID() + "@" + hostname; - } - return "java-" + UUID.randomUUID() + jvmName; - } - - static ProjectName getProjectName(PointData pointData) { - return ProjectName.of(pointData.getAttributes().get(BIGTABLE_PROJECT_ID_KEY)); - } - - // Returns a list of timeseries by project name - static Map> convertToBigtableTimeSeries( - Collection collection, String taskId) { - Map> allTimeSeries = new HashMap<>(); - - for (MetricData metricData : collection) { - if (!metricData.getInstrumentationScopeInfo().getName().equals(METER_NAME)) { - // Filter out metric data for instruments that are not part of the bigtable builtin metrics - continue; - } - - for (PointData pd : metricData.getData().getPoints()) { - ProjectName projectName = getProjectName(pd); - List current = - allTimeSeries.computeIfAbsent(projectName, ignored -> new ArrayList<>()); - current.add(convertPointToBigtableTimeSeries(metricData, pd, taskId)); - allTimeSeries.put(projectName, current); - } - } - - return allTimeSeries; - } - - static List convertToApplicationResourceTimeSeries( - Collection collection, MonitoredResource applicationResource) { - Preconditions.checkNotNull( - applicationResource, - "convert application metrics is called when the supported resource is not detected"); - List allTimeSeries = new ArrayList<>(); - for (MetricData metricData : collection) { - metricData.getData().getPoints().stream() - .map( - pointData -> - createInternalMetricsTimeSeries(metricData, pointData, applicationResource)) - .filter(Optional::isPresent) - .forEach(ts -> ts.ifPresent(allTimeSeries::add)); - } - return allTimeSeries; - } - - @Nullable - static MonitoredResource createInternalMonitoredResource(ClientInfo clientInfo) { - try { - MonitoredResource monitoredResource = detectResource(clientInfo); - logger.log(Level.FINE, "Internal metrics monitored resource: %s", monitoredResource); - return monitoredResource; - } catch (Exception e) { - logger.log( - Level.WARNING, - "Failed to detect resource, will skip exporting application level metrics ", - e); - return null; - } - } - - @Nullable - private static MonitoredResource detectResource(ClientInfo clientInfo) { - GCPPlatformDetector detector = GCPPlatformDetector.DEFAULT_INSTANCE; - DetectedPlatform detectedPlatform = detector.detectPlatform(); - - @Nullable - String cloud_platform = SUPPORTED_PLATFORM_MAP.get(detectedPlatform.getSupportedPlatform()); - if (cloud_platform == null) { - return null; - } - - Map attrs = detectedPlatform.getAttributes(); - ImmutableList locationKeys = - ImmutableList.of( - AttributeKeys.GCE_CLOUD_REGION, - AttributeKeys.GCE_AVAILABILITY_ZONE, - AttributeKeys.GKE_LOCATION_TYPE_REGION, - AttributeKeys.GKE_CLUSTER_LOCATION); - - String region = - locationKeys.stream().map(attrs::get).filter(Objects::nonNull).findFirst().orElse("global"); - - // Deal with possibility of a zone. Zones are of the form us-east1-c, but we want a region - // which, which is us-east1. - region = Arrays.stream(region.split("-")).limit(2).collect(Collectors.joining("-")); - - String hostname = attrs.get(AttributeKeys.GCE_INSTANCE_HOSTNAME); - // if (hostname == null) { - // hostname = attrs.get(AttributeKeys.SERVERLESS_COMPUTE_NAME); - // } - // if (hostname == null) { - // hostname = attrs.get(AttributeKeys.GAE_MODULE_NAME); - // } - if (hostname == null) { - hostname = System.getenv("HOSTNAME"); - } - if (hostname == null) { - try { - hostname = InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException ignored) { - } - } - if (hostname == null) { - hostname = ""; - } - - return MonitoredResource.newBuilder() - .setType("bigtable_client") - .putLabels("project_id", clientInfo.getInstanceName().getProject()) - .putLabels("instance", clientInfo.getInstanceName().getInstance()) - .putLabels("app_profile", clientInfo.getAppProfileId()) - .putLabels("client_project", detectedPlatform.getProjectId()) - .putLabels("region", region) - .putLabels("cloud_platform", cloud_platform) - .putLabels("host_id", attrs.get(AttributeKeys.GKE_HOST_ID)) - .putLabels("host_name", hostname) - .putLabels("client_name", CLIENT_NAME) - .putLabels("uuid", DEFAULT_TASK_VALUE.get() + "-" + nextUuidSuffix.getAndIncrement()) - .build(); - } - - private static TimeSeries convertPointToBigtableTimeSeries( - MetricData metricData, PointData pointData, String taskId) { - TimeSeries.Builder builder = - TimeSeries.newBuilder() - .setMetricKind(convertMetricKind(metricData)) - .setValueType(convertValueType(metricData.getType())); - Metric.Builder metricBuilder = Metric.newBuilder().setType(metricData.getName()); - - Attributes attributes = pointData.getAttributes(); - MonitoredResource.Builder monitoredResourceBuilder = - MonitoredResource.newBuilder().setType(BIGTABLE_RESOURCE_TYPE); - - for (AttributeKey key : attributes.asMap().keySet()) { - if (BIGTABLE_PROMOTED_RESOURCE_LABELS.contains(key)) { - monitoredResourceBuilder.putLabels(key.getKey(), String.valueOf(attributes.get(key))); - } else { - metricBuilder.putLabels(key.getKey(), String.valueOf(attributes.get(key))); - } - } - - builder.setResource(monitoredResourceBuilder.build()); - - metricBuilder.putLabels(CLIENT_UID_KEY.getKey(), taskId); - builder.setMetric(metricBuilder.build()); - - MetricKind kind = convertMetricKind(metricData); - - Timestamp endTimestamp = Timestamps.fromNanos(pointData.getEpochNanos()); - Timestamp startTimestamp; - - if (kind == GAUGE) { - // GAUGE metrics must have start_time equal to end_time. - startTimestamp = endTimestamp; - } else { - startTimestamp = Timestamps.fromNanos(pointData.getStartEpochNanos()); - } - TimeInterval timeInterval = - TimeInterval.newBuilder().setStartTime(startTimestamp).setEndTime(endTimestamp).build(); - - builder.addPoints(createPoint(metricData.getType(), pointData, timeInterval)); - - return builder.build(); - } - - private static Optional createInternalMetricsTimeSeries( - MetricData metricData, PointData pointData, MonitoredResource applicationResource) { - MetricKind kind = convertMetricKind(metricData); - TimeSeries.Builder builder = - TimeSeries.newBuilder() - .setMetricKind(kind) - .setValueType(convertValueType(metricData.getType())) - .setResource(applicationResource); - - final Metric.Builder metricBuilder; - // TODO: clean this up - // Internal metrics are based on views that include the metric prefix - // gRPC metrics dont have views and are dot encoded - // To unify these: - // - the useless views should be removed - // - internal metrics should use relative metric names w/o the prefix - if (INTERNAL_METRICS.contains(metricData.getName())) { - metricBuilder = newApplicationMetricBuilder(metricData.getName(), pointData.getAttributes()); - } else if (GRPC_METRICS.containsKey(metricData.getName())) { - metricBuilder = newGrpcMetricBuilder(metricData.getName(), pointData.getAttributes()); - } else { - logger.fine("Skipping unexpected internal metric: " + metricData.getName()); - return Optional.empty(); - } - - builder.setMetric(metricBuilder.build()); - - Timestamp endTimestamp = Timestamps.fromNanos(pointData.getEpochNanos()); - Timestamp startTimestamp; - if (kind == GAUGE) { - startTimestamp = endTimestamp; - } else { - startTimestamp = Timestamps.fromNanos(pointData.getStartEpochNanos()); - } - TimeInterval timeInterval = - TimeInterval.newBuilder().setStartTime(startTimestamp).setEndTime(endTimestamp).build(); - - builder.addPoints(createPoint(metricData.getType(), pointData, timeInterval)); - return Optional.of(builder.build()); - } - - private static Metric.Builder newApplicationMetricBuilder( - String metricName, Attributes attributes) { - // TODO: unify handling of metric prefixes - Metric.Builder metricBuilder = Metric.newBuilder().setType(metricName); - for (Map.Entry, Object> e : attributes.asMap().entrySet()) { - metricBuilder.putLabels(e.getKey().getKey(), String.valueOf(e.getValue())); - } - return metricBuilder; - } - - private static Metric.Builder newGrpcMetricBuilder(String grpcMetricName, Attributes attributes) { - Set allowedAttrs = GRPC_METRICS.get(grpcMetricName); - - Metric.Builder metricBuilder = - Metric.newBuilder() - .setType("bigtable.googleapis.com/internal/client/" + grpcMetricName.replace('.', '/')); - for (Map.Entry, Object> e : attributes.asMap().entrySet()) { - String attrKey = e.getKey().getKey(); - Object attrValue = e.getValue(); - - // gRPC metrics are experimental and can change attribute names, to avoid incompatibility with - // the predefined - // metric schemas in stackdriver, filter out unknown keys - if (!allowedAttrs.contains(attrKey)) { - continue; - } - // translate grpc key format to be compatible with cloud monitoring: - // grpc.xds_client.server_failure -> grpc_xds_client_server_failure - String normalizedKey = attrKey.replace('.', '_'); - metricBuilder.putLabels(normalizedKey, String.valueOf(attrValue)); - } - - return metricBuilder; - } - - private static MetricKind convertMetricKind(MetricData metricData) { - switch (metricData.getType()) { - case HISTOGRAM: - case EXPONENTIAL_HISTOGRAM: - return convertHistogramType(metricData.getHistogramData()); - case LONG_GAUGE: - case DOUBLE_GAUGE: - return GAUGE; - case LONG_SUM: - return convertSumDataType(metricData.getLongSumData()); - case DOUBLE_SUM: - return convertSumDataType(metricData.getDoubleSumData()); - default: - return UNRECOGNIZED; - } - } - - private static MetricKind convertHistogramType(HistogramData histogramData) { - if (histogramData.getAggregationTemporality() == AggregationTemporality.CUMULATIVE) { - return CUMULATIVE; - } - return UNRECOGNIZED; - } - - private static MetricKind convertSumDataType(SumData sum) { - if (!sum.isMonotonic()) { - return GAUGE; - } - if (sum.getAggregationTemporality() == AggregationTemporality.CUMULATIVE) { - return CUMULATIVE; - } - return UNRECOGNIZED; - } - - private static ValueType convertValueType(MetricDataType metricDataType) { - switch (metricDataType) { - case LONG_GAUGE: - case LONG_SUM: - return INT64; - case DOUBLE_GAUGE: - case DOUBLE_SUM: - return DOUBLE; - case HISTOGRAM: - case EXPONENTIAL_HISTOGRAM: - return DISTRIBUTION; - default: - return ValueType.UNRECOGNIZED; - } - } - - private static Point createPoint( - MetricDataType type, PointData pointData, TimeInterval timeInterval) { - Point.Builder builder = Point.newBuilder().setInterval(timeInterval); - switch (type) { - case HISTOGRAM: - case EXPONENTIAL_HISTOGRAM: - return builder - .setValue( - TypedValue.newBuilder() - .setDistributionValue(convertHistogramData((HistogramPointData) pointData)) - .build()) - .build(); - case DOUBLE_GAUGE: - case DOUBLE_SUM: - return builder - .setValue( - TypedValue.newBuilder() - .setDoubleValue(((DoublePointData) pointData).getValue()) - .build()) - .build(); - case LONG_GAUGE: - case LONG_SUM: - return builder - .setValue(TypedValue.newBuilder().setInt64Value(((LongPointData) pointData).getValue())) - .build(); - default: - logger.log(Level.WARNING, "unsupported metric type"); - return builder.build(); - } - } - - private static Distribution convertHistogramData(HistogramPointData pointData) { - return Distribution.newBuilder() - .setCount(pointData.getCount()) - .setMean(pointData.getCount() == 0L ? 0.0D : pointData.getSum() / pointData.getCount()) - .setBucketOptions( - BucketOptions.newBuilder() - .setExplicitBuckets(Explicit.newBuilder().addAllBounds(pointData.getBoundaries()))) - .addAllBucketCounts(pointData.getCounts()) - .build(); - } -} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsConstants.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsConstants.java deleted file mode 100644 index 810d555de28c..000000000000 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsConstants.java +++ /dev/null @@ -1,395 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * 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 - * - * https://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 com.google.cloud.bigtable.data.v2.stub.metrics; - -import com.google.api.core.InternalApi; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.sdk.metrics.Aggregation; -import io.opentelemetry.sdk.metrics.InstrumentSelector; -import io.opentelemetry.sdk.metrics.InstrumentType; -import io.opentelemetry.sdk.metrics.View; -import io.opentelemetry.sdk.metrics.ViewBuilder; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; -import javax.annotation.Nullable; - -/** Defining Bigtable builit-in metrics scope, attributes, metric names and views. */ -@InternalApi -public class BuiltinMetricsConstants { - - // Metric attribute keys for monitored resource - public static final AttributeKey BIGTABLE_PROJECT_ID_KEY = - AttributeKey.stringKey("project_id"); - public static final AttributeKey INSTANCE_ID_KEY = AttributeKey.stringKey("instance"); - public static final AttributeKey TABLE_ID_KEY = AttributeKey.stringKey("table"); - public static final AttributeKey CLUSTER_ID_KEY = AttributeKey.stringKey("cluster"); - public static final AttributeKey ZONE_ID_KEY = AttributeKey.stringKey("zone"); - - // Metric attribute keys for labels - // We need to access APP_PROFILE_KEY in EnhancedBigtableStubSettings and STREAMING_KEY in - // IT tests, so they're public. - public static final AttributeKey APP_PROFILE_KEY = AttributeKey.stringKey("app_profile"); - public static final AttributeKey STREAMING_KEY = AttributeKey.booleanKey("streaming"); - public static final AttributeKey CLIENT_NAME_KEY = AttributeKey.stringKey("client_name"); - static final AttributeKey METHOD_KEY = AttributeKey.stringKey("method"); - static final AttributeKey STATUS_KEY = AttributeKey.stringKey("status"); - static final AttributeKey CLIENT_UID_KEY = AttributeKey.stringKey("client_uid"); - static final AttributeKey APPLIED_KEY = AttributeKey.booleanKey("applied"); - - static final AttributeKey TRANSPORT_TYPE = AttributeKey.stringKey("transport_type"); - static final AttributeKey TRANSPORT_REGION = AttributeKey.stringKey("transport_region"); - static final AttributeKey TRANSPORT_ZONE = AttributeKey.stringKey("transport_zone"); - static final AttributeKey TRANSPORT_SUBZONE = AttributeKey.stringKey("transport_subzone"); - - // gRPC attribute keys - // Note that these attributes keys from transformed from - // A.B.C to A_B_C before exporting to Cloud Monitoring. - static final AttributeKey GRPC_LB_BACKEND_SERVICE_KEY = - AttributeKey.stringKey("grpc.lb.backend_service"); - static final AttributeKey GRPC_DISCONNECT_ERROR_KEY = - AttributeKey.stringKey("grpc.disconnect_error"); - static final AttributeKey GRPC_LB_LOCALITY_KEY = - AttributeKey.stringKey("grpc.lb.locality"); - static final AttributeKey GRPC_TARGET_KEY = AttributeKey.stringKey("grpc.target"); - static final AttributeKey GRPC_SECURITY_LEVEL_KEY = - AttributeKey.stringKey("grpc.security_level"); - static final AttributeKey GRPC_METHOD_KEY = AttributeKey.stringKey("grpc.method"); - static final AttributeKey GRPC_STATUS_KEY = AttributeKey.stringKey("grpc.status"); - static final AttributeKey GRPC_LB_RLS_DATA_PLANE_TARGET_KEY = - AttributeKey.stringKey("grpc.lb.rls.data_plane_target"); - static final AttributeKey GRPC_LB_PICK_RESULT_KEY = - AttributeKey.stringKey("grpc.lb.pick_result"); - static final AttributeKey GRPC_LB_RLS_SERVER_TARGET_KEY = - AttributeKey.stringKey("grpc.lb.rls.server_target"); - static final AttributeKey GRPC_XDS_SERVER_KEY = AttributeKey.stringKey("grpc.xds.server"); - static final AttributeKey GRPC_XDS_RESOURCE_TYPE_KEY = - AttributeKey.stringKey("grpc.xds.resource_type"); - - public static final String METER_NAME = "bigtable.googleapis.com/internal/client/"; - - // Metric names - public static final String OPERATION_LATENCIES_NAME = "operation_latencies"; - public static final String ATTEMPT_LATENCIES_NAME = "attempt_latencies"; - // Temporary workaround for not being able to add new labels to ATTEMPT_LATENCIES_NAME - public static final String ATTEMPT_LATENCIES2_NAME = "attempt_latencies2"; - static final String RETRY_COUNT_NAME = "retry_count"; - static final String CONNECTIVITY_ERROR_COUNT_NAME = "connectivity_error_count"; - static final String SERVER_LATENCIES_NAME = "server_latencies"; - static final String FIRST_RESPONSE_LATENCIES_NAME = "first_response_latencies"; - static final String APPLICATION_BLOCKING_LATENCIES_NAME = "application_latencies"; - static final String REMAINING_DEADLINE_NAME = "remaining_deadline"; - static final String CLIENT_BLOCKING_LATENCIES_NAME = "throttling_latencies"; - static final String PER_CONNECTION_ERROR_COUNT_NAME = "per_connection_error_count"; - static final String OUTSTANDING_RPCS_PER_CHANNEL_NAME = "connection_pool/outstanding_rpcs"; - static final String BATCH_WRITE_FLOW_CONTROL_TARGET_QPS_NAME = - "batch_write_flow_control_target_qps"; - static final String BATCH_WRITE_FLOW_CONTROL_FACTOR_NAME = "batch_write_flow_control_factor"; - - // Start allow list of metrics that will be exported as internal - public static final Map> GRPC_METRICS = - ImmutableMap.>builder() - .put( - "grpc.client.attempt.duration", - ImmutableSet.of( - GRPC_LB_LOCALITY_KEY.getKey(), - GRPC_METHOD_KEY.getKey(), - GRPC_TARGET_KEY.getKey(), - GRPC_STATUS_KEY.getKey())) - .put( - "grpc.lb.rls.default_target_picks", - ImmutableSet.of( - GRPC_LB_RLS_DATA_PLANE_TARGET_KEY.getKey(), GRPC_LB_PICK_RESULT_KEY.getKey())) - .put( - "grpc.lb.rls.target_picks", - ImmutableSet.of( - GRPC_TARGET_KEY.getKey(), - GRPC_LB_RLS_SERVER_TARGET_KEY.getKey(), - GRPC_LB_RLS_DATA_PLANE_TARGET_KEY.getKey(), - GRPC_LB_PICK_RESULT_KEY.getKey())) - .put( - "grpc.lb.rls.failed_picks", - ImmutableSet.of(GRPC_TARGET_KEY.getKey(), GRPC_LB_RLS_SERVER_TARGET_KEY.getKey())) - // TODO: "grpc.xds_client.connected" - .put( - "grpc.xds_client.server_failure", - ImmutableSet.of(GRPC_TARGET_KEY.getKey(), GRPC_XDS_SERVER_KEY.getKey())) - // TODO: "grpc.xds_client.resource_updates_valid", - .put( - "grpc.xds_client.resource_updates_invalid", - ImmutableSet.of( - GRPC_TARGET_KEY.getKey(), - GRPC_XDS_SERVER_KEY.getKey(), - GRPC_XDS_RESOURCE_TYPE_KEY.getKey())) - // TODO: "grpc.xds_client.resources" - // gRPC subchannel metrics - .put( - "grpc.subchannel.disconnections", - ImmutableSet.of( - GRPC_LB_BACKEND_SERVICE_KEY.getKey(), - GRPC_DISCONNECT_ERROR_KEY.getKey(), - GRPC_LB_LOCALITY_KEY.getKey(), - GRPC_TARGET_KEY.getKey())) - .put( - "grpc.subchannel.connection_attempts_succeeded", - ImmutableSet.of( - GRPC_LB_BACKEND_SERVICE_KEY.getKey(), - GRPC_LB_LOCALITY_KEY.getKey(), - GRPC_TARGET_KEY.getKey())) - .put( - "grpc.subchannel.connection_attempts_failed", - ImmutableSet.of( - GRPC_LB_BACKEND_SERVICE_KEY.getKey(), - GRPC_LB_LOCALITY_KEY.getKey(), - GRPC_TARGET_KEY.getKey())) - .put( - "grpc.subchannel.open_connections", - ImmutableSet.of( - GRPC_LB_BACKEND_SERVICE_KEY.getKey(), - GRPC_LB_LOCALITY_KEY.getKey(), - GRPC_SECURITY_LEVEL_KEY.getKey(), - GRPC_TARGET_KEY.getKey())) - .build(); - - public static final Set INTERNAL_METRICS = - ImmutableSet.of(PER_CONNECTION_ERROR_COUNT_NAME, OUTSTANDING_RPCS_PER_CHANNEL_NAME).stream() - .map(m -> METER_NAME + m) - .collect(ImmutableSet.toImmutableSet()); - // End allow list of metrics that will be exported - - // Buckets under 100,000 are identical to buckets for server side metrics handler_latencies. - // Extending client side bucket to up to 3,200,000. - private static final Aggregation AGGREGATION_WITH_MILLIS_HISTOGRAM = - Aggregation.explicitBucketHistogram( - ImmutableList.of( - 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0, 13.0, 16.0, 20.0, 25.0, 30.0, 40.0, - 50.0, 65.0, 80.0, 100.0, 130.0, 160.0, 200.0, 250.0, 300.0, 400.0, 500.0, 650.0, - 800.0, 1000.0, 2000.0, 5000.0, 10000.0, 20000.0, 50000.0, 100000.0, 200000.0, - 400000.0, 800000.0, 1600000.0, 3200000.0)); // max is 53.3 minutes - - private static final Aggregation AGGREGATION_PER_CONNECTION_ERROR_COUNT_HISTOGRAM = - Aggregation.explicitBucketHistogram( - ImmutableList.of( - 1.0, - 2.0, - 4.0, - 8.0, - 16.0, - 32.0, - 64.0, - 125.0, - 250.0, - 500.0, - 1_000.0, - 2_000.0, - 4_000.0, - 8_000.0, - 16_000.0, - 32_000.0, - 64_000.0, - 128_000.0, - 250_000.0, - 500_000.0, - 1_000_000.0)); - - // Buckets for outstanding RPCs per channel, max ~100 - private static final Aggregation AGGREGATION_OUTSTANDING_RPCS_HISTOGRAM = - Aggregation.explicitBucketHistogram( - ImmutableList.of( - 0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, - 70.0, 75.0, 80.0, 85.0, 90.0, 95.0, 100.0, 105.0, 110.0, 115.0, 120.0, 125.0, 130.0, - 135.0, 140.0, 145.0, 150.0, 155.0, 160.0, 165.0, 170.0, 175.0, 180.0, 185.0, 190.0, - 195.0, 200.0)); - private static final Aggregation AGGREGATION_BATCH_WRITE_FLOW_CONTROL_FACTOR_HISTOGRAM = - Aggregation.explicitBucketHistogram(ImmutableList.of(0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3)); - - static final Set COMMON_ATTRIBUTES = - ImmutableSet.of( - BIGTABLE_PROJECT_ID_KEY, - INSTANCE_ID_KEY, - TABLE_ID_KEY, - APP_PROFILE_KEY, - CLUSTER_ID_KEY, - ZONE_ID_KEY, - METHOD_KEY, - CLIENT_NAME_KEY); - - static void defineView( - ImmutableMap.Builder viewMap, - String id, - @Nullable Aggregation aggregation, - InstrumentType type, - String unit, - Set attributes) { - InstrumentSelector selector = - InstrumentSelector.builder() - .setName(id) - .setMeterName(METER_NAME) - .setType(type) - .setUnit(unit) - .build(); - Set attributesFilter = - ImmutableSet.builder() - .addAll( - COMMON_ATTRIBUTES.stream().map(AttributeKey::getKey).collect(Collectors.toSet())) - .addAll(attributes.stream().map(AttributeKey::getKey).collect(Collectors.toSet())) - .build(); - ViewBuilder viewBuilder = - View.builder().setName(METER_NAME + id).setAttributeFilter(attributesFilter); - if (aggregation != null) { - viewBuilder.setAggregation(aggregation); - } - viewMap.put(selector, viewBuilder.build()); - } - - // uses cloud.BigtableClient schema - public static Map getInternalViews() { - ImmutableMap.Builder views = ImmutableMap.builder(); - defineView( - views, - PER_CONNECTION_ERROR_COUNT_NAME, - AGGREGATION_PER_CONNECTION_ERROR_COUNT_HISTOGRAM, - InstrumentType.HISTOGRAM, - "1", - ImmutableSet.builder() - .add(BIGTABLE_PROJECT_ID_KEY, INSTANCE_ID_KEY, APP_PROFILE_KEY, CLIENT_NAME_KEY) - .build()); - defineView( - views, - OUTSTANDING_RPCS_PER_CHANNEL_NAME, - AGGREGATION_OUTSTANDING_RPCS_HISTOGRAM, - InstrumentType.HISTOGRAM, - "1", - ImmutableSet.builder() - .add(BIGTABLE_PROJECT_ID_KEY, INSTANCE_ID_KEY, APP_PROFILE_KEY, CLIENT_NAME_KEY) - .build()); - return views.build(); - } - - public static Map getAllViews() { - ImmutableMap.Builder views = ImmutableMap.builder(); - - defineView( - views, - OPERATION_LATENCIES_NAME, - AGGREGATION_WITH_MILLIS_HISTOGRAM, - InstrumentType.HISTOGRAM, - "ms", - ImmutableSet.builder() - .addAll(COMMON_ATTRIBUTES) - .add(STREAMING_KEY, STATUS_KEY) - .build()); - defineView( - views, - ATTEMPT_LATENCIES_NAME, - AGGREGATION_WITH_MILLIS_HISTOGRAM, - InstrumentType.HISTOGRAM, - "ms", - ImmutableSet.builder() - .addAll(COMMON_ATTRIBUTES) - .add(STREAMING_KEY, STATUS_KEY) - .build()); - defineView( - views, - ATTEMPT_LATENCIES2_NAME, - AGGREGATION_WITH_MILLIS_HISTOGRAM, - InstrumentType.HISTOGRAM, - "ms", - ImmutableSet.builder() - .addAll(COMMON_ATTRIBUTES) - .add( - STREAMING_KEY, - STATUS_KEY, - TRANSPORT_TYPE, - TRANSPORT_REGION, - TRANSPORT_ZONE, - TRANSPORT_SUBZONE) - .build()); - defineView( - views, - SERVER_LATENCIES_NAME, - AGGREGATION_WITH_MILLIS_HISTOGRAM, - InstrumentType.HISTOGRAM, - "ms", - ImmutableSet.builder().addAll(COMMON_ATTRIBUTES).add(STATUS_KEY).build()); - defineView( - views, - FIRST_RESPONSE_LATENCIES_NAME, - AGGREGATION_WITH_MILLIS_HISTOGRAM, - InstrumentType.HISTOGRAM, - "ms", - ImmutableSet.builder().addAll(COMMON_ATTRIBUTES).add(STATUS_KEY).build()); - defineView( - views, - APPLICATION_BLOCKING_LATENCIES_NAME, - AGGREGATION_WITH_MILLIS_HISTOGRAM, - InstrumentType.HISTOGRAM, - "ms", - ImmutableSet.builder().addAll(COMMON_ATTRIBUTES).build()); - defineView( - views, - CLIENT_BLOCKING_LATENCIES_NAME, - AGGREGATION_WITH_MILLIS_HISTOGRAM, - InstrumentType.HISTOGRAM, - "ms", - ImmutableSet.builder().addAll(COMMON_ATTRIBUTES).build()); - defineView( - views, - RETRY_COUNT_NAME, - Aggregation.sum(), - InstrumentType.COUNTER, - "1", - ImmutableSet.builder().addAll(COMMON_ATTRIBUTES).add(STATUS_KEY).build()); - defineView( - views, - CONNECTIVITY_ERROR_COUNT_NAME, - Aggregation.sum(), - InstrumentType.COUNTER, - "1", - ImmutableSet.builder().addAll(COMMON_ATTRIBUTES).add(STATUS_KEY).build()); - defineView( - views, - REMAINING_DEADLINE_NAME, - AGGREGATION_WITH_MILLIS_HISTOGRAM, - InstrumentType.HISTOGRAM, - "ms", - ImmutableSet.builder() - .addAll(COMMON_ATTRIBUTES) - .add(STREAMING_KEY, STATUS_KEY) - .build()); - defineView( - views, - BATCH_WRITE_FLOW_CONTROL_TARGET_QPS_NAME, - null, - InstrumentType.GAUGE, - "1", - ImmutableSet.builder().addAll(COMMON_ATTRIBUTES).build()); - defineView( - views, - BATCH_WRITE_FLOW_CONTROL_FACTOR_NAME, - AGGREGATION_BATCH_WRITE_FLOW_CONTROL_FACTOR_HISTOGRAM, - InstrumentType.HISTOGRAM, - "1", - ImmutableSet.builder() - .addAll(COMMON_ATTRIBUTES) - .add(STATUS_KEY, APPLIED_KEY) - .build()); - return views.build(); - } -} diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java index 57181faa3427..44034523abb6 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java @@ -16,7 +16,7 @@ package com.google.cloud.bigtable.data.v2.stub.metrics; import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; -import static com.google.cloud.bigtable.data.v2.stub.metrics.Util.extractStatus; +import static com.google.cloud.bigtable.data.v2.internal.csm.attributes.Util.extractStatus; import com.google.api.core.ObsoleteApi; import com.google.api.gax.retrying.ServerStreamingAttemptException; diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsView.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsView.java index edca9bd53f64..cec15f6221b1 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsView.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsView.java @@ -16,11 +16,8 @@ package com.google.cloud.bigtable.data.v2.stub.metrics; import com.google.auth.Credentials; -import io.opentelemetry.sdk.metrics.InstrumentSelector; import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder; -import io.opentelemetry.sdk.metrics.View; import java.io.IOException; -import java.util.Map; import java.util.concurrent.ScheduledExecutorService; import javax.annotation.Nullable; @@ -37,24 +34,15 @@ private BuiltinMetricsView() {} @Deprecated public static void registerBuiltinMetrics(String projectId, SdkMeterProviderBuilder builder) - throws IOException { - registerBuiltinMetrics(builder); - } + throws IOException {} @Deprecated - public static void registerBuiltinMetrics(SdkMeterProviderBuilder builder) throws IOException { - for (Map.Entry entry : - BuiltinMetricsConstants.getAllViews().entrySet()) { - builder.registerView(entry.getKey(), entry.getValue()); - } - } + public static void registerBuiltinMetrics(SdkMeterProviderBuilder builder) throws IOException {} @Deprecated public static void registerBuiltinMetrics( String projectId, @Nullable Credentials credentials, SdkMeterProviderBuilder builder) - throws IOException { - registerBuiltinMetrics(builder); - } + throws IOException {} @Deprecated public static void registerBuiltinMetrics( @@ -62,16 +50,12 @@ public static void registerBuiltinMetrics( @Nullable Credentials credentials, SdkMeterProviderBuilder builder, @Nullable String endpoint) - throws IOException { - registerBuiltinMetrics(credentials, builder, endpoint); - } + throws IOException {} @Deprecated public static void registerBuiltinMetrics( @Nullable Credentials credentials, SdkMeterProviderBuilder builder, @Nullable String endpoint) - throws IOException { - registerBuiltinMetrics(builder); - } + throws IOException {} @Deprecated public static void registerBuiltinMetrics( @@ -79,9 +63,7 @@ public static void registerBuiltinMetrics( SdkMeterProviderBuilder builder, @Nullable String endpoint, @Nullable ScheduledExecutorService executorService) - throws IOException { - registerBuiltinMetrics(builder); - } + throws IOException {} @Deprecated static void registerBuiltinMetricsWithUniverseDomain( @@ -90,7 +72,5 @@ static void registerBuiltinMetricsWithUniverseDomain( @Nullable String endpoint, String universeDomain, @Nullable ScheduledExecutorService executorService) - throws IOException { - registerBuiltinMetrics(builder); - } + throws IOException {} } diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CustomOpenTelemetryMetricsProvider.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CustomOpenTelemetryMetricsProvider.java index 66f4e25a1761..66041e8aca13 100644 --- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CustomOpenTelemetryMetricsProvider.java +++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/CustomOpenTelemetryMetricsProvider.java @@ -18,11 +18,8 @@ import com.google.auth.Credentials; import com.google.common.base.MoreObjects; import io.opentelemetry.api.OpenTelemetry; -import io.opentelemetry.sdk.metrics.InstrumentSelector; import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder; -import io.opentelemetry.sdk.metrics.View; import java.io.IOException; -import java.util.Map; import java.util.concurrent.ScheduledExecutorService; /** @@ -33,19 +30,6 @@ *
{@code
  * SdkMeterProviderBuilder sdkMeterProvider = SdkMeterProvider.builder();
  *
- * // Set up SdkMeterProvider for client side metrics
- * CustomOpenTelemetryMetricsProvider.setupSdkMeterProvider(sdkMeterProvider);
- *
- * // register other metrics reader and views
- * sdkMeterProvider.registerMetricReader(..);
- * sdkMeterProvider.registerView(..);
- *
- * // create the OTEL instance
- * OpenTelemetry openTelemetry = OpenTelemetrySdk
- *     .builder()
- *     .setMeterProvider(sdkMeterProvider.build())
- *     .build();
- *
  * // Override MetricsProvider in BigtableDataSettings
  * BigtableDataSettings settings = BigtableDataSettings.newBuilder()
  *   .setProjectId("my-project")
@@ -71,45 +55,35 @@ public OpenTelemetry getOpenTelemetry() {
   }
 
   /**
-   * Convenient method to set up SdkMeterProviderBuilder with the default credential and endpoint.
+   * @deprecated this is no longer needed and is now a no-op
    */
-  public static void setupSdkMeterProvider(SdkMeterProviderBuilder builder) throws IOException {
-    for (Map.Entry entry :
-        BuiltinMetricsConstants.getAllViews().entrySet()) {
-      builder.registerView(entry.getKey(), entry.getValue());
-    }
-  }
+  @Deprecated
+  public static void setupSdkMeterProvider(SdkMeterProviderBuilder builder) throws IOException {}
 
   /**
-   * @deprecated Please use {@link #setupSdkMeterProvider(SdkMeterProviderBuilder)}
+   * @deprecated this is no longer needed and is now a no-op
    */
   @Deprecated
   public static void setupSdkMeterProvider(SdkMeterProviderBuilder builder, Credentials credentials)
-      throws IOException {
-    setupSdkMeterProvider(builder);
-  }
+      throws IOException {}
 
   /**
-   * @deprecated Please use {@link #setupSdkMeterProvider(SdkMeterProviderBuilder)}
+   * @deprecated this is no longer needed and is now a no-op
    */
   @Deprecated
   public static void setupSdkMeterProvider(SdkMeterProviderBuilder builder, String endpoint)
-      throws IOException {
-    setupSdkMeterProvider(builder);
-  }
+      throws IOException {}
 
   /**
-   * @deprecated Please use {@link #setupSdkMeterProvider(SdkMeterProviderBuilder)}
+   * @deprecated this is no longer needed and is now a no-op
    */
   @Deprecated
   public static void setupSdkMeterProvider(
       SdkMeterProviderBuilder builder, Credentials credentials, String endpoint)
-      throws IOException {
-    setupSdkMeterProvider(builder);
-  }
+      throws IOException {}
 
   /**
-   * @deprecated Please use {@link #setupSdkMeterProvider(SdkMeterProviderBuilder)}
+   * @deprecated this is no longer needed and is now a no-op
    */
   @Deprecated
   public static void setupSdkMeterProvider(
@@ -117,9 +91,7 @@ public static void setupSdkMeterProvider(
       Credentials credentials,
       String endpoint,
       ScheduledExecutorService executor)
-      throws IOException {
-    setupSdkMeterProvider(builder);
-  }
+      throws IOException {}
 
   @Override
   public String toString() {
diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/RpcViews.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/RpcViews.java
index e8902108aaa4..c4948a20bf14 100644
--- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/RpcViews.java
+++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/RpcViews.java
@@ -15,29 +15,15 @@
  */
 package com.google.cloud.bigtable.data.v2.stub.metrics;
 
+import com.google.api.core.InternalApi;
+import com.google.cloud.bigtable.data.v2.internal.csm.opencensus.RpcViewConstants;
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.ImmutableSet;
 import io.opencensus.stats.Stats;
 import io.opencensus.stats.View;
 import io.opencensus.stats.ViewManager;
 
 @Deprecated
 public class RpcViews {
-  @VisibleForTesting
-  private static final ImmutableSet BIGTABLE_CLIENT_VIEWS_SET =
-      ImmutableSet.of(
-          RpcViewConstants.BIGTABLE_OP_LATENCY_VIEW,
-          RpcViewConstants.BIGTABLE_COMPLETED_OP_VIEW,
-          RpcViewConstants.BIGTABLE_READ_ROWS_FIRST_ROW_LATENCY_VIEW,
-          RpcViewConstants.BIGTABLE_ATTEMPT_LATENCY_VIEW,
-          RpcViewConstants.BIGTABLE_ATTEMPTS_PER_OP_VIEW,
-          RpcViewConstants.BIGTABLE_BATCH_THROTTLED_TIME_VIEW);
-
-  private static final ImmutableSet GFE_VIEW_SET =
-      ImmutableSet.of(
-          RpcViewConstants.BIGTABLE_GFE_LATENCY_VIEW,
-          RpcViewConstants.BIGTABLE_GFE_HEADER_MISSING_COUNT_VIEW);
-
   private static boolean gfeMetricsRegistered = false;
 
   /** Registers all Bigtable specific views. */
@@ -55,16 +41,18 @@ public static void registerBigtableClientGfeViews() {
     registerBigtableClientGfeViews(Stats.getViewManager());
   }
 
+  @InternalApi
   @VisibleForTesting
-  static void registerBigtableClientViews(ViewManager viewManager) {
-    for (View view : BIGTABLE_CLIENT_VIEWS_SET) {
+  public static void registerBigtableClientViews(ViewManager viewManager) {
+    for (View view : RpcViewConstants.BIGTABLE_CLIENT_VIEWS_SET) {
       viewManager.registerView(view);
     }
   }
 
+  @InternalApi
   @VisibleForTesting
-  static void registerBigtableClientGfeViews(ViewManager viewManager) {
-    for (View view : GFE_VIEW_SET) {
+  public static void registerBigtableClientGfeViews(ViewManager viewManager) {
+    for (View view : RpcViewConstants.GFE_VIEW_SET) {
       viewManager.registerView(view);
     }
     gfeMetricsRegistered = true;
diff --git a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/Util.java b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/Util.java
index 4af8abb8693a..db739567e8be 100644
--- a/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/Util.java
+++ b/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/Util.java
@@ -16,9 +16,7 @@
 package com.google.cloud.bigtable.data.v2.stub.metrics;
 
 import com.google.api.core.InternalApi;
-import com.google.api.gax.grpc.GrpcStatusCode;
 import com.google.api.gax.rpc.ApiCallContext;
-import com.google.api.gax.rpc.ApiException;
 import com.google.bigtable.v2.AuthorizedViewName;
 import com.google.bigtable.v2.CheckAndMutateRowRequest;
 import com.google.bigtable.v2.GenerateInitialChangeStreamPartitionsRequest;
@@ -32,14 +30,11 @@
 import com.google.bigtable.v2.TableName;
 import com.google.common.collect.ImmutableMap;
 import io.grpc.Metadata;
-import io.grpc.Status;
 import java.time.Instant;
 import java.time.temporal.ChronoUnit;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.CancellationException;
-import javax.annotation.Nullable;
 
 /** Utilities to help integrating with OpenCensus. */
 @InternalApi("For internal use only")
@@ -49,28 +44,6 @@ public class Util {
   static final Metadata.Key ATTEMPT_EPOCH_KEY =
       Metadata.Key.of("bigtable-client-attempt-epoch-usec", Metadata.ASCII_STRING_MARSHALLER);
 
-  public static Status.Code extractStatus(@Nullable Throwable error) {
-    if (error == null) {
-      return Status.Code.OK;
-    }
-    // Handle java CancellationException as if it was a gax CancelledException
-    if (error instanceof CancellationException) {
-      return Status.Code.CANCELLED;
-    }
-    if (error instanceof ApiException) {
-      ApiException apiException = (ApiException) error;
-      if (apiException.getStatusCode() instanceof GrpcStatusCode) {
-        return ((GrpcStatusCode) apiException.getStatusCode()).getTransportCode();
-      }
-    }
-
-    Status s = Status.fromThrowable(error);
-    if (s != null) {
-      return s.getCode();
-    }
-    return Status.Code.UNKNOWN;
-  }
-
   static String extractTableId(Object request) {
     String tableName = null;
     String authorizedViewName = null;
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/attributes/UtilTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/attributes/UtilTest.java
index 78b6c18b8bf0..782b04928e5c 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/attributes/UtilTest.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/attributes/UtilTest.java
@@ -16,9 +16,14 @@
 
 package com.google.cloud.bigtable.data.v2.internal.csm.attributes;
 
+import static com.google.common.truth.Truth.assertThat;
 import static com.google.common.truth.Truth.assertWithMessage;
 
+import com.google.api.gax.grpc.GrpcStatusCode;
+import com.google.api.gax.rpc.DeadlineExceededException;
 import com.google.bigtable.v2.PeerInfo.TransportType;
+import io.grpc.Status;
+import io.opencensus.tags.TagValue;
 import org.junit.jupiter.api.Test;
 
 class UtilTest {
@@ -30,4 +35,22 @@ void ensureAllTransportTypeHaveExpectedPrefix() {
           .isNotNull();
     }
   }
+
+  @Test
+  public void testOk() {
+    TagValue tagValue =
+        TagValue.create(
+            com.google.cloud.bigtable.data.v2.internal.csm.attributes.Util.extractStatus(null)
+                .name());
+    assertThat(tagValue.asString()).isEqualTo("OK");
+  }
+
+  @Test
+  public void testError() {
+    DeadlineExceededException error =
+        new DeadlineExceededException(
+            "Deadline exceeded", null, GrpcStatusCode.of(Status.Code.DEADLINE_EXCEEDED), true);
+    TagValue tagValue = TagValue.create(Util.extractStatus(error).name());
+    assertThat(tagValue.asString()).isEqualTo("DEADLINE_EXCEEDED");
+  }
 }
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableTracerCallableTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/BigtableTracerCallableTest.java
similarity index 98%
rename from google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableTracerCallableTest.java
rename to google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/BigtableTracerCallableTest.java
index f9b0e56ac527..4eec40a69647 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableTracerCallableTest.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/BigtableTracerCallableTest.java
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.google.cloud.bigtable.data.v2.stub.metrics;
+package com.google.cloud.bigtable.data.v2.internal.csm.opencensus;
 
 import static com.google.common.truth.Truth.assertThat;
 import static org.junit.Assert.fail;
@@ -45,6 +45,8 @@
 import com.google.cloud.bigtable.data.v2.models.TableId;
 import com.google.cloud.bigtable.data.v2.stub.BigtableClientContext;
 import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub;
+import com.google.cloud.bigtable.data.v2.stub.metrics.NoopMetricsProvider;
+import com.google.cloud.bigtable.data.v2.stub.metrics.RpcViews;
 import com.google.common.collect.ImmutableMap;
 import io.grpc.ForwardingServerCall.SimpleForwardingServerCall;
 import io.grpc.Metadata;
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/MetricsTracerTest.java
similarity index 98%
rename from google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java
rename to google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/MetricsTracerTest.java
index da864bf49593..cadd7779835a 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/MetricsTracerTest.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/MetricsTracerTest.java
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.google.cloud.bigtable.data.v2.stub.metrics;
+package com.google.cloud.bigtable.data.v2.internal.csm.opencensus;
 
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.ArgumentMatchers.any;
@@ -39,6 +39,8 @@
 import com.google.cloud.bigtable.data.v2.models.RowMutationEntry;
 import com.google.cloud.bigtable.data.v2.stub.BigtableClientContext;
 import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub;
+import com.google.cloud.bigtable.data.v2.stub.metrics.NoopMetricsProvider;
+import com.google.cloud.bigtable.data.v2.stub.metrics.RpcViews;
 import com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor;
 import com.google.common.base.Stopwatch;
 import com.google.common.collect.ImmutableMap;
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/SimpleStatsComponent.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/SimpleStatsComponent.java
similarity index 93%
rename from google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/SimpleStatsComponent.java
rename to google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/SimpleStatsComponent.java
index 99aed9c3b4f4..bf867989d1b8 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/SimpleStatsComponent.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/SimpleStatsComponent.java
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.google.cloud.bigtable.data.v2.stub.metrics;
+package com.google.cloud.bigtable.data.v2.internal.csm.opencensus;
 
 import io.opencensus.implcore.common.MillisClock;
 import io.opencensus.implcore.internal.SimpleEventQueue;
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/StatsTestUtils.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/StatsTestUtils.java
similarity index 99%
rename from google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/StatsTestUtils.java
rename to google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/StatsTestUtils.java
index e808af8a8488..db86a027fccb 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/StatsTestUtils.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/opencensus/StatsTestUtils.java
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.google.cloud.bigtable.data.v2.stub.metrics;
+package com.google.cloud.bigtable.data.v2.internal.csm.opencensus;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java
index 20555520f6d4..b8e5df44874b 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/BuiltinMetricsIT.java
@@ -29,10 +29,10 @@
 import com.google.cloud.bigtable.admin.v2.models.Table;
 import com.google.cloud.bigtable.data.v2.BigtableDataClient;
 import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.Constants.MetricLabels;
 import com.google.cloud.bigtable.data.v2.models.Query;
 import com.google.cloud.bigtable.data.v2.models.Row;
 import com.google.cloud.bigtable.data.v2.models.RowMutation;
-import com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants;
 import com.google.cloud.bigtable.data.v2.stub.metrics.CustomOpenTelemetryMetricsProvider;
 import com.google.cloud.bigtable.test_helpers.env.CloudEnv;
 import com.google.cloud.bigtable.test_helpers.env.PrefixGenerator;
@@ -339,7 +339,7 @@ private void verifyMetricsWithMetricsReader(
               .putAll(ts.getMetric().getLabelsMap())
               .build();
       AttributesBuilder attributesBuilder = Attributes.builder();
-      String streamingKey = BuiltinMetricsConstants.STREAMING_KEY.getKey();
+      String streamingKey = MetricLabels.STREAMING_KEY.getKey();
       attributesMap.forEach(
           (k, v) -> {
             if (!k.equals(streamingKey)) {
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/MetricsITUtils.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/MetricsITUtils.java
index 56f6bfa476be..5e56d36e724e 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/MetricsITUtils.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/MetricsITUtils.java
@@ -15,7 +15,7 @@
  */
 package com.google.cloud.bigtable.data.v2.it;
 
-import com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants;
+import com.google.cloud.bigtable.data.v2.internal.csm.schema.TableSchema;
 import com.google.common.truth.Correspondence;
 import io.opentelemetry.sdk.metrics.data.MetricData;
 import io.opentelemetry.sdk.metrics.data.PointData;
@@ -27,11 +27,11 @@ public class MetricsITUtils {
 
   static final Correspondence POINT_DATA_CLUSTER_ID_CONTAINS =
       Correspondence.from(
-          (pd, s) -> pd.getAttributes().get(BuiltinMetricsConstants.CLUSTER_ID_KEY).contains(s),
+          (pd, s) -> pd.getAttributes().get(TableSchema.CLUSTER_ID_KEY).contains(s),
           "contains attributes");
 
   static final Correspondence POINT_DATA_ZONE_ID_CONTAINS =
       Correspondence.from(
-          (pd, s) -> pd.getAttributes().get(BuiltinMetricsConstants.ZONE_ID_KEY).contains(s),
+          (pd, s) -> pd.getAttributes().get(TableSchema.ZONE_ID_KEY).contains(s),
           "contains attributes");
 }
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/StreamingMetricsMetadataIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/StreamingMetricsMetadataIT.java
index 1c9245ba39f3..03d9c156c328 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/StreamingMetricsMetadataIT.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/StreamingMetricsMetadataIT.java
@@ -26,9 +26,10 @@
 import com.google.cloud.bigtable.admin.v2.models.Cluster;
 import com.google.cloud.bigtable.data.v2.BigtableDataClient;
 import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.TableOperationLatency;
+import com.google.cloud.bigtable.data.v2.internal.csm.schema.TableSchema;
 import com.google.cloud.bigtable.data.v2.models.Query;
 import com.google.cloud.bigtable.data.v2.models.Row;
-import com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants;
 import com.google.cloud.bigtable.data.v2.stub.metrics.CustomOpenTelemetryMetricsProvider;
 import com.google.cloud.bigtable.test_helpers.env.EmulatorEnv;
 import com.google.cloud.bigtable.test_helpers.env.TestEnvRule;
@@ -105,23 +106,23 @@ public void testSuccess() throws Exception {
     Collection allMetricData = metricReader.collectAllMetrics();
     List metrics =
         metricReader.collectAllMetrics().stream()
-            .filter(m -> m.getName().contains(BuiltinMetricsConstants.OPERATION_LATENCIES_NAME))
+            .filter(m -> m.getName().contains(TableOperationLatency.NAME))
             .collect(Collectors.toList());
 
     assertThat(allMetricData)
         .comparingElementsUsing(METRIC_DATA_NAME_CONTAINS)
-        .contains(BuiltinMetricsConstants.OPERATION_LATENCIES_NAME);
+        .contains(TableOperationLatency.NAME);
     assertThat(metrics).hasSize(1);
 
     MetricData metricData = metrics.get(0);
     List pointData = new ArrayList<>(metricData.getData().getPoints());
     List clusterAttributes =
         pointData.stream()
-            .map(pd -> pd.getAttributes().get(BuiltinMetricsConstants.CLUSTER_ID_KEY))
+            .map(pd -> pd.getAttributes().get(TableSchema.CLUSTER_ID_KEY))
             .collect(Collectors.toList());
     List zoneAttributes =
         pointData.stream()
-            .map(pd -> pd.getAttributes().get(BuiltinMetricsConstants.ZONE_ID_KEY))
+            .map(pd -> pd.getAttributes().get(TableSchema.ZONE_ID_KEY))
             .collect(Collectors.toList());
 
     assertThat(pointData)
@@ -146,23 +147,23 @@ public void testFailure() {
     Collection allMetricData = metricReader.collectAllMetrics();
     List metrics =
         metricReader.collectAllMetrics().stream()
-            .filter(m -> m.getName().contains(BuiltinMetricsConstants.OPERATION_LATENCIES_NAME))
+            .filter(m -> m.getName().contains(TableOperationLatency.NAME))
             .collect(Collectors.toList());
 
     assertThat(allMetricData)
         .comparingElementsUsing(METRIC_DATA_NAME_CONTAINS)
-        .contains(BuiltinMetricsConstants.OPERATION_LATENCIES_NAME);
+        .contains(TableOperationLatency.NAME);
     assertThat(metrics).hasSize(1);
 
     MetricData metricData = metrics.get(0);
     List pointData = new ArrayList<>(metricData.getData().getPoints());
     List clusterAttributes =
         pointData.stream()
-            .map(pd -> pd.getAttributes().get(BuiltinMetricsConstants.CLUSTER_ID_KEY))
+            .map(pd -> pd.getAttributes().get(TableSchema.CLUSTER_ID_KEY))
             .collect(Collectors.toList());
     List zoneAttributes =
         pointData.stream()
-            .map(pd -> pd.getAttributes().get(BuiltinMetricsConstants.ZONE_ID_KEY))
+            .map(pd -> pd.getAttributes().get(TableSchema.ZONE_ID_KEY))
             .collect(Collectors.toList());
 
     assertThat(pointData)
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/UnaryMetricsMetadataIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/UnaryMetricsMetadataIT.java
index 019661429941..50ff7ea6ad98 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/UnaryMetricsMetadataIT.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/UnaryMetricsMetadataIT.java
@@ -26,8 +26,10 @@
 import com.google.cloud.bigtable.admin.v2.models.Cluster;
 import com.google.cloud.bigtable.data.v2.BigtableDataClient;
 import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.TableAttemptLatency;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.TableOperationLatency;
+import com.google.cloud.bigtable.data.v2.internal.csm.schema.TableSchema;
 import com.google.cloud.bigtable.data.v2.models.RowMutation;
-import com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants;
 import com.google.cloud.bigtable.data.v2.stub.metrics.CustomOpenTelemetryMetricsProvider;
 import com.google.cloud.bigtable.test_helpers.env.EmulatorEnv;
 import com.google.cloud.bigtable.test_helpers.env.TestEnvRule;
@@ -110,23 +112,23 @@ public void testSuccess() throws Exception {
     Collection allMetricData = metricReader.collectAllMetrics();
     List metrics =
         allMetricData.stream()
-            .filter(m -> m.getName().contains(BuiltinMetricsConstants.OPERATION_LATENCIES_NAME))
+            .filter(m -> m.getName().contains(TableOperationLatency.NAME))
             .collect(Collectors.toList());
 
     assertThat(allMetricData)
         .comparingElementsUsing(METRIC_DATA_NAME_CONTAINS)
-        .contains(BuiltinMetricsConstants.OPERATION_LATENCIES_NAME);
+        .contains(TableOperationLatency.NAME);
     assertThat(metrics).hasSize(1);
 
     MetricData metricData = metrics.get(0);
     List pointData = new ArrayList<>(metricData.getData().getPoints());
     List clusterAttributes =
         pointData.stream()
-            .map(pd -> pd.getAttributes().get(BuiltinMetricsConstants.CLUSTER_ID_KEY))
+            .map(pd -> pd.getAttributes().get(TableSchema.CLUSTER_ID_KEY))
             .collect(Collectors.toList());
     List zoneAttributes =
         pointData.stream()
-            .map(pd -> pd.getAttributes().get(BuiltinMetricsConstants.ZONE_ID_KEY))
+            .map(pd -> pd.getAttributes().get(TableSchema.ZONE_ID_KEY))
             .collect(Collectors.toList());
 
     assertThat(pointData)
@@ -163,10 +165,7 @@ public void testFailure() throws Exception {
     Collection allMetricData = metricReader.collectAllMetrics();
     MetricData metricData = null;
     for (MetricData md : allMetricData) {
-      if (md.getName()
-          .equals(
-              BuiltinMetricsConstants.METER_NAME
-                  + BuiltinMetricsConstants.ATTEMPT_LATENCIES_NAME)) {
+      if (md.getName().equals(TableAttemptLatency.NAME)) {
         metricData = md;
         break;
       }
@@ -174,7 +173,7 @@ public void testFailure() throws Exception {
 
     assertThat(allMetricData)
         .comparingElementsUsing(METRIC_DATA_NAME_CONTAINS)
-        .contains(BuiltinMetricsConstants.ATTEMPT_LATENCIES_NAME);
+        .contains(TableAttemptLatency.NAME);
     assertThat(metricData).isNotNull();
 
     List pointData = new ArrayList<>(metricData.getData().getPoints());
@@ -185,11 +184,11 @@ public void testFailure() throws Exception {
     assertThat(pointData).comparingElementsUsing(POINT_DATA_ZONE_ID_CONTAINS).contains("global");
     List clusterAttributes =
         pointData.stream()
-            .map(pd -> pd.getAttributes().get(BuiltinMetricsConstants.CLUSTER_ID_KEY))
+            .map(pd -> pd.getAttributes().get(TableSchema.CLUSTER_ID_KEY))
             .collect(Collectors.toList());
     List zoneAttributes =
         pointData.stream()
-            .map(pd -> pd.getAttributes().get(BuiltinMetricsConstants.ZONE_ID_KEY))
+            .map(pd -> pd.getAttributes().get(TableSchema.ZONE_ID_KEY))
             .collect(Collectors.toList());
 
     assertThat(clusterAttributes).contains("");
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableCloudMonitoringExporterTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableCloudMonitoringExporterTest.java
index d9ccad187e46..7df30aa330a4 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableCloudMonitoringExporterTest.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BigtableCloudMonitoringExporterTest.java
@@ -15,14 +15,6 @@
  */
 package com.google.cloud.bigtable.data.v2.stub.metrics;
 
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.APP_PROFILE_KEY;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.BIGTABLE_PROJECT_ID_KEY;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CLIENT_NAME_KEY;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CLIENT_UID_KEY;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CLUSTER_ID_KEY;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.INSTANCE_ID_KEY;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.TABLE_ID_KEY;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.ZONE_ID_KEY;
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
@@ -38,6 +30,9 @@
 import com.google.cloud.bigtable.data.v2.internal.csm.MetricRegistry;
 import com.google.cloud.bigtable.data.v2.internal.csm.attributes.ClientInfo;
 import com.google.cloud.bigtable.data.v2.internal.csm.attributes.EnvInfo;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.Constants.MetricLabels;
+import com.google.cloud.bigtable.data.v2.internal.csm.schema.ClientSchema;
+import com.google.cloud.bigtable.data.v2.internal.csm.schema.TableSchema;
 import com.google.cloud.monitoring.v3.MetricServiceClient;
 import com.google.cloud.monitoring.v3.stub.MetricServiceStub;
 import com.google.common.base.Suppliers;
@@ -122,17 +117,17 @@ public void setUp() {
 
     attributes =
         Attributes.builder()
-            .put(BIGTABLE_PROJECT_ID_KEY, projectId)
-            .put(INSTANCE_ID_KEY, instanceId)
-            .put(TABLE_ID_KEY, tableId)
-            .put(CLUSTER_ID_KEY, cluster)
-            .put(ZONE_ID_KEY, zone)
-            .put(APP_PROFILE_KEY, appProfileId)
+            .put(TableSchema.BIGTABLE_PROJECT_ID_KEY, projectId)
+            .put(TableSchema.INSTANCE_ID_KEY, instanceId)
+            .put(TableSchema.TABLE_ID_KEY, tableId)
+            .put(TableSchema.CLUSTER_ID_KEY, cluster)
+            .put(TableSchema.ZONE_ID_KEY, zone)
+            .put(MetricLabels.APP_PROFILE_KEY, appProfileId)
             .build();
 
     resource = Resource.create(Attributes.empty());
 
-    scope = InstrumentationScopeInfo.create(BuiltinMetricsConstants.METER_NAME);
+    scope = InstrumentationScopeInfo.create(MetricRegistry.METER_NAME);
   }
 
   @After
@@ -175,15 +170,19 @@ public void testExportingSumData() {
 
     assertThat(timeSeries.getResource().getLabelsMap())
         .containsExactly(
-            BIGTABLE_PROJECT_ID_KEY.getKey(), projectId,
-            INSTANCE_ID_KEY.getKey(), instanceId,
-            TABLE_ID_KEY.getKey(), tableId,
-            CLUSTER_ID_KEY.getKey(), cluster,
-            ZONE_ID_KEY.getKey(), zone);
+            TableSchema.BIGTABLE_PROJECT_ID_KEY.getKey(), projectId,
+            TableSchema.INSTANCE_ID_KEY.getKey(), instanceId,
+            TableSchema.TABLE_ID_KEY.getKey(), tableId,
+            TableSchema.CLUSTER_ID_KEY.getKey(), cluster,
+            TableSchema.ZONE_ID_KEY.getKey(), zone);
 
     assertThat(timeSeries.getMetric().getLabelsMap()).hasSize(2);
     assertThat(timeSeries.getMetric().getLabelsMap())
-        .containsAtLeast(APP_PROFILE_KEY.getKey(), appProfileId, CLIENT_UID_KEY.getKey(), taskId);
+        .containsAtLeast(
+            MetricLabels.APP_PROFILE_KEY.getKey(),
+            appProfileId,
+            MetricLabels.CLIENT_UID.getKey(),
+            taskId);
     assertThat(timeSeries.getPoints(0).getValue().getInt64Value()).isEqualTo(fakeValue);
     assertThat(timeSeries.getPoints(0).getInterval().getStartTime().getNanos())
         .isEqualTo(startEpoch);
@@ -235,15 +234,19 @@ public void testExportingHistogramData() {
 
     assertThat(timeSeries.getResource().getLabelsMap())
         .containsExactly(
-            BIGTABLE_PROJECT_ID_KEY.getKey(), projectId,
-            INSTANCE_ID_KEY.getKey(), instanceId,
-            TABLE_ID_KEY.getKey(), tableId,
-            CLUSTER_ID_KEY.getKey(), cluster,
-            ZONE_ID_KEY.getKey(), zone);
+            TableSchema.BIGTABLE_PROJECT_ID_KEY.getKey(), projectId,
+            TableSchema.INSTANCE_ID_KEY.getKey(), instanceId,
+            TableSchema.TABLE_ID_KEY.getKey(), tableId,
+            TableSchema.CLUSTER_ID_KEY.getKey(), cluster,
+            TableSchema.ZONE_ID_KEY.getKey(), zone);
 
     assertThat(timeSeries.getMetric().getLabelsMap()).hasSize(2);
     assertThat(timeSeries.getMetric().getLabelsMap())
-        .containsAtLeast(APP_PROFILE_KEY.getKey(), appProfileId, CLIENT_UID_KEY.getKey(), taskId);
+        .containsAtLeast(
+            MetricLabels.APP_PROFILE_KEY.getKey(),
+            appProfileId,
+            MetricLabels.CLIENT_UID.getKey(),
+            taskId);
     Distribution distribution = timeSeries.getPoints(0).getValue().getDistributionValue();
     assertThat(distribution.getCount()).isEqualTo(3);
     assertThat(timeSeries.getPoints(0).getInterval().getStartTime().getNanos())
@@ -268,12 +271,12 @@ public void testExportingSumDataInBatches() {
     for (int i = 0; i < 250; i++) {
       Attributes testAttributes =
           Attributes.builder()
-              .put(BIGTABLE_PROJECT_ID_KEY, projectId)
-              .put(INSTANCE_ID_KEY, instanceId)
-              .put(TABLE_ID_KEY, tableId + i)
-              .put(CLUSTER_ID_KEY, cluster)
-              .put(ZONE_ID_KEY, zone)
-              .put(APP_PROFILE_KEY, appProfileId)
+              .put(TableSchema.BIGTABLE_PROJECT_ID_KEY, projectId)
+              .put(TableSchema.INSTANCE_ID_KEY, instanceId)
+              .put(TableSchema.TABLE_ID_KEY, tableId + i)
+              .put(TableSchema.CLUSTER_ID_KEY, cluster)
+              .put(TableSchema.ZONE_ID_KEY, zone)
+              .put(MetricLabels.APP_PROFILE_KEY, appProfileId)
               .build();
       LongPointData longPointData =
           ImmutableLongPointData.create(startEpoch, endEpoch, testAttributes, i);
@@ -309,15 +312,19 @@ public void testExportingSumDataInBatches() {
 
       assertThat(timeSeries.getResource().getLabelsMap())
           .containsExactly(
-              BIGTABLE_PROJECT_ID_KEY.getKey(), projectId,
-              INSTANCE_ID_KEY.getKey(), instanceId,
-              TABLE_ID_KEY.getKey(), tableId + i,
-              CLUSTER_ID_KEY.getKey(), cluster,
-              ZONE_ID_KEY.getKey(), zone);
+              TableSchema.BIGTABLE_PROJECT_ID_KEY.getKey(), projectId,
+              TableSchema.INSTANCE_ID_KEY.getKey(), instanceId,
+              TableSchema.TABLE_ID_KEY.getKey(), tableId + i,
+              TableSchema.CLUSTER_ID_KEY.getKey(), cluster,
+              TableSchema.ZONE_ID_KEY.getKey(), zone);
 
       assertThat(timeSeries.getMetric().getLabelsMap()).hasSize(2);
       assertThat(timeSeries.getMetric().getLabelsMap())
-          .containsAtLeast(APP_PROFILE_KEY.getKey(), appProfileId, CLIENT_UID_KEY.getKey(), taskId);
+          .containsAtLeast(
+              MetricLabels.APP_PROFILE_KEY.getKey(),
+              appProfileId,
+              MetricLabels.CLIENT_UID.getKey(),
+              taskId);
       assertThat(timeSeries.getPoints(0).getValue().getInt64Value()).isEqualTo(i);
       assertThat(timeSeries.getPoints(0).getInterval().getStartTime().getNanos())
           .isEqualTo(startEpoch);
@@ -348,13 +355,13 @@ public void testTimeSeriesForMetricWithGceOrGkeResource() {
             startEpoch,
             endEpoch,
             Attributes.of(
-                BIGTABLE_PROJECT_ID_KEY,
+                ClientSchema.BIGTABLE_PROJECT_ID_KEY,
                 projectId,
-                INSTANCE_ID_KEY,
+                ClientSchema.INSTANCE_ID_KEY,
                 instanceId,
-                APP_PROFILE_KEY,
+                ClientSchema.APP_PROFILE_KEY,
                 appProfileId,
-                CLIENT_NAME_KEY,
+                ClientSchema.CLIENT_NAME,
                 clientName),
             3d,
             true,
@@ -401,10 +408,10 @@ public void testTimeSeriesForMetricWithGceOrGkeResource() {
     assertThat(timeSeries.getMetric().getLabelsMap())
         .isEqualTo(
             ImmutableMap.builder()
-                .put(BIGTABLE_PROJECT_ID_KEY.getKey(), projectId)
-                .put(INSTANCE_ID_KEY.getKey(), instanceId)
-                .put(APP_PROFILE_KEY.getKey(), appProfileId)
-                .put(CLIENT_NAME_KEY.getKey(), clientName)
+                .put(ClientSchema.BIGTABLE_PROJECT_ID_KEY.getKey(), projectId)
+                .put(ClientSchema.INSTANCE_ID_KEY.getKey(), instanceId)
+                .put(ClientSchema.APP_PROFILE_KEY.getKey(), appProfileId)
+                .put(ClientSchema.CLIENT_NAME.getKey(), clientName)
                 .build());
   }
 
@@ -447,7 +454,9 @@ public void testExportingToMultipleProjects() {
         ImmutableHistogramPointData.create(
             startEpoch,
             endEpoch,
-            attributes.toBuilder().put(BIGTABLE_PROJECT_ID_KEY, "another-project").build(),
+            attributes.toBuilder()
+                .put(TableSchema.BIGTABLE_PROJECT_ID_KEY, "another-project")
+                .build(),
             50d,
             true,
             5d, // min
@@ -492,26 +501,26 @@ public void testExportingToMultipleProjects() {
     assertThat(labelsMap)
         .containsExactly(
             ImmutableMap.of(
-                BIGTABLE_PROJECT_ID_KEY.getKey(),
+                TableSchema.BIGTABLE_PROJECT_ID_KEY.getKey(),
                 projectId,
-                INSTANCE_ID_KEY.getKey(),
+                TableSchema.INSTANCE_ID_KEY.getKey(),
                 instanceId,
-                TABLE_ID_KEY.getKey(),
+                TableSchema.TABLE_ID_KEY.getKey(),
                 tableId,
-                CLUSTER_ID_KEY.getKey(),
+                TableSchema.CLUSTER_ID_KEY.getKey(),
                 cluster,
-                ZONE_ID_KEY.getKey(),
+                TableSchema.ZONE_ID_KEY.getKey(),
                 zone),
             ImmutableMap.of(
-                BIGTABLE_PROJECT_ID_KEY.getKey(),
+                TableSchema.BIGTABLE_PROJECT_ID_KEY.getKey(),
                 "another-project",
-                INSTANCE_ID_KEY.getKey(),
+                TableSchema.INSTANCE_ID_KEY.getKey(),
                 instanceId,
-                TABLE_ID_KEY.getKey(),
+                TableSchema.TABLE_ID_KEY.getKey(),
                 tableId,
-                CLUSTER_ID_KEY.getKey(),
+                TableSchema.CLUSTER_ID_KEY.getKey(),
                 cluster,
-                ZONE_ID_KEY.getKey(),
+                TableSchema.ZONE_ID_KEY.getKey(),
                 zone));
     assertThat(counts).containsExactly(3l, 15l);
   }
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTestUtils.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTestUtils.java
index 32453efd7f67..8eee324317ec 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTestUtils.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTestUtils.java
@@ -42,7 +42,7 @@ public class BuiltinMetricsTestUtils {
   private BuiltinMetricsTestUtils() {}
 
   public static MetricData getMetricData(InMemoryMetricReader reader, String metricName) {
-    String fullMetricName = BuiltinMetricsConstants.METER_NAME + metricName;
+    String fullMetricName = metricName;
     Collection allMetricData = Collections.emptyList();
 
     // Fetch the MetricData with retries
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracerTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracerTest.java
index 47d1078b9d09..b6afa752264a 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracerTest.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracerTest.java
@@ -15,25 +15,6 @@
  */
 package com.google.cloud.bigtable.data.v2.stub.metrics;
 
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.APPLICATION_BLOCKING_LATENCIES_NAME;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.APPLIED_KEY;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.ATTEMPT_LATENCIES_NAME;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.BATCH_WRITE_FLOW_CONTROL_FACTOR_NAME;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.BATCH_WRITE_FLOW_CONTROL_TARGET_QPS_NAME;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CLIENT_BLOCKING_LATENCIES_NAME;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CLIENT_NAME_KEY;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CLUSTER_ID_KEY;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.CONNECTIVITY_ERROR_COUNT_NAME;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.FIRST_RESPONSE_LATENCIES_NAME;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.METHOD_KEY;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.OPERATION_LATENCIES_NAME;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.REMAINING_DEADLINE_NAME;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.RETRY_COUNT_NAME;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.SERVER_LATENCIES_NAME;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.STATUS_KEY;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.STREAMING_KEY;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.TABLE_ID_KEY;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.ZONE_ID_KEY;
 import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsTestUtils.getAggregatedDoubleValue;
 import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsTestUtils.getAggregatedValue;
 import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsTestUtils.getMetricData;
@@ -67,6 +48,19 @@
 import com.google.cloud.bigtable.data.v2.FakeServiceBuilder;
 import com.google.cloud.bigtable.data.v2.internal.csm.MetricRegistry;
 import com.google.cloud.bigtable.data.v2.internal.csm.attributes.ClientInfo;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.ClientBatchWriteFlowControlFactor;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.ClientBatchWriteFlowControlTargetQps;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.Constants.MetricLabels;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.TableApplicationBlockingLatency;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.TableAttemptLatency;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.TableClientBlockingLatency;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.TableConnectivityErrorCount;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.TableFirstResponseLatency;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.TableOperationLatency;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.TableRemainingDeadline;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.TableRetryCount;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.TableServerLatency;
+import com.google.cloud.bigtable.data.v2.internal.csm.schema.TableSchema;
 import com.google.cloud.bigtable.data.v2.models.AuthorizedViewId;
 import com.google.cloud.bigtable.data.v2.models.Query;
 import com.google.cloud.bigtable.data.v2.models.Row;
@@ -103,10 +97,8 @@
 import io.grpc.stub.StreamObserver;
 import io.opentelemetry.api.common.Attributes;
 import io.opentelemetry.sdk.OpenTelemetrySdk;
-import io.opentelemetry.sdk.metrics.InstrumentSelector;
 import io.opentelemetry.sdk.metrics.SdkMeterProvider;
 import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder;
-import io.opentelemetry.sdk.metrics.View;
 import io.opentelemetry.sdk.metrics.data.HistogramPointData;
 import io.opentelemetry.sdk.metrics.data.MetricData;
 import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
@@ -120,7 +112,6 @@
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -173,9 +164,9 @@ public class BuiltinMetricsTracerTest {
           .build();
   private Attributes expectedBaseAttributes =
       Attributes.builder()
-          .put(BuiltinMetricsConstants.BIGTABLE_PROJECT_ID_KEY, PROJECT_ID)
-          .put(BuiltinMetricsConstants.INSTANCE_ID_KEY, INSTANCE_ID)
-          .put(BuiltinMetricsConstants.APP_PROFILE_KEY, APP_PROFILE_ID)
+          .put(TableSchema.BIGTABLE_PROJECT_ID_KEY, PROJECT_ID)
+          .put(TableSchema.INSTANCE_ID_KEY, INSTANCE_ID)
+          .put(MetricLabels.APP_PROFILE_KEY, APP_PROFILE_ID)
           .build();
 
   private InMemoryMetricReader metricReader;
@@ -191,11 +182,6 @@ public void setUp() throws Exception {
     SdkMeterProviderBuilder meterProvider =
         SdkMeterProvider.builder().registerMetricReader(metricReader);
 
-    for (Map.Entry entry :
-        BuiltinMetricsConstants.getAllViews().entrySet()) {
-      meterProvider.registerView(entry.getKey(), entry.getValue());
-    }
-
     OpenTelemetrySdk otel =
         OpenTelemetrySdk.builder().setMeterProvider(meterProvider.build()).build();
     MetricRegistry mr = new MetricRegistry();
@@ -313,16 +299,16 @@ public void testReadRowsOperationLatencies() {
 
     Attributes expectedAttributes =
         expectedBaseAttributes.toBuilder()
-            .put(STATUS_KEY, "OK")
-            .put(TABLE_ID_KEY, TABLE)
-            .put(ZONE_ID_KEY, ZONE)
-            .put(CLUSTER_ID_KEY, CLUSTER)
-            .put(METHOD_KEY, "Bigtable.ReadRows")
-            .put(STREAMING_KEY, true)
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
+            .put(MetricLabels.STATUS_KEY, "OK")
+            .put(TableSchema.TABLE_ID_KEY, TABLE)
+            .put(TableSchema.ZONE_ID_KEY, ZONE)
+            .put(TableSchema.CLUSTER_ID_KEY, CLUSTER)
+            .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows")
+            .put(MetricLabels.STREAMING_KEY, true)
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
             .build();
 
-    MetricData metricData = getMetricData(metricReader, OPERATION_LATENCIES_NAME);
+    MetricData metricData = getMetricData(metricReader, TableOperationLatency.NAME);
 
     long value = getAggregatedValue(metricData, expectedAttributes);
     assertThat(value).isIn(Range.closed(SERVER_LATENCY, elapsed));
@@ -338,16 +324,16 @@ public void testReadRowsOperationLatenciesOnAuthorizedView() {
 
     Attributes expectedAttributes =
         expectedBaseAttributes.toBuilder()
-            .put(STATUS_KEY, "OK")
-            .put(TABLE_ID_KEY, TABLE)
-            .put(ZONE_ID_KEY, ZONE)
-            .put(CLUSTER_ID_KEY, CLUSTER)
-            .put(METHOD_KEY, "Bigtable.ReadRows")
-            .put(STREAMING_KEY, true)
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
+            .put(MetricLabels.STATUS_KEY, "OK")
+            .put(TableSchema.TABLE_ID_KEY, TABLE)
+            .put(TableSchema.ZONE_ID_KEY, ZONE)
+            .put(TableSchema.CLUSTER_ID_KEY, CLUSTER)
+            .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows")
+            .put(MetricLabels.STREAMING_KEY, true)
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
             .build();
 
-    MetricData metricData = getMetricData(metricReader, OPERATION_LATENCIES_NAME);
+    MetricData metricData = getMetricData(metricReader, TableOperationLatency.NAME);
     long value = getAggregatedValue(metricData, expectedAttributes);
     assertThat(value).isIn(Range.closed(SERVER_LATENCY, elapsed));
   }
@@ -383,15 +369,15 @@ public void onComplete() {}
 
     Attributes expectedAttributes =
         expectedBaseAttributes.toBuilder()
-            .put(STATUS_KEY, "OK")
-            .put(TABLE_ID_KEY, FIRST_RESPONSE_TABLE_ID)
-            .put(ZONE_ID_KEY, ZONE)
-            .put(CLUSTER_ID_KEY, CLUSTER)
-            .put(METHOD_KEY, "Bigtable.ReadRows")
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
+            .put(MetricLabels.STATUS_KEY, "OK")
+            .put(TableSchema.TABLE_ID_KEY, FIRST_RESPONSE_TABLE_ID)
+            .put(TableSchema.ZONE_ID_KEY, ZONE)
+            .put(TableSchema.CLUSTER_ID_KEY, CLUSTER)
+            .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows")
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
             .build();
 
-    MetricData metricData = getMetricData(metricReader, FIRST_RESPONSE_LATENCIES_NAME);
+    MetricData metricData = getMetricData(metricReader, TableFirstResponseLatency.NAME);
 
     long value = getAggregatedValue(metricData, expectedAttributes);
     assertThat(value).isAtMost(firstResponseTimer.elapsed(TimeUnit.MILLISECONDS));
@@ -403,38 +389,38 @@ public void testGfeMetrics() {
 
     Attributes expectedAttributes =
         expectedBaseAttributes.toBuilder()
-            .put(STATUS_KEY, "OK")
-            .put(TABLE_ID_KEY, TABLE)
-            .put(ZONE_ID_KEY, ZONE)
-            .put(CLUSTER_ID_KEY, CLUSTER)
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
-            .put(METHOD_KEY, "Bigtable.ReadRows")
+            .put(MetricLabels.STATUS_KEY, "OK")
+            .put(TableSchema.TABLE_ID_KEY, TABLE)
+            .put(TableSchema.ZONE_ID_KEY, ZONE)
+            .put(TableSchema.CLUSTER_ID_KEY, CLUSTER)
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
+            .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows")
             .build();
 
-    MetricData serverLatenciesMetricData = getMetricData(metricReader, SERVER_LATENCIES_NAME);
+    MetricData serverLatenciesMetricData = getMetricData(metricReader, TableServerLatency.NAME);
 
     long serverLatencies = getAggregatedValue(serverLatenciesMetricData, expectedAttributes);
     assertThat(serverLatencies).isEqualTo(FAKE_SERVER_TIMING);
 
     MetricData connectivityErrorCountMetricData =
-        getMetricData(metricReader, CONNECTIVITY_ERROR_COUNT_NAME);
+        getMetricData(metricReader, TableConnectivityErrorCount.NAME);
     Attributes expected1 =
         expectedBaseAttributes.toBuilder()
-            .put(STATUS_KEY, "UNAVAILABLE")
-            .put(TABLE_ID_KEY, TABLE)
-            .put(ZONE_ID_KEY, "global")
-            .put(CLUSTER_ID_KEY, "")
-            .put(METHOD_KEY, "Bigtable.ReadRows")
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
+            .put(MetricLabels.STATUS_KEY, "UNAVAILABLE")
+            .put(TableSchema.TABLE_ID_KEY, TABLE)
+            .put(TableSchema.ZONE_ID_KEY, "global")
+            .put(TableSchema.CLUSTER_ID_KEY, "")
+            .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows")
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
             .build();
     Attributes expected2 =
         expectedBaseAttributes.toBuilder()
-            .put(STATUS_KEY, "OK")
-            .put(TABLE_ID_KEY, TABLE)
-            .put(ZONE_ID_KEY, ZONE)
-            .put(CLUSTER_ID_KEY, CLUSTER)
-            .put(METHOD_KEY, "Bigtable.ReadRows")
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
+            .put(MetricLabels.STATUS_KEY, "OK")
+            .put(TableSchema.TABLE_ID_KEY, TABLE)
+            .put(TableSchema.ZONE_ID_KEY, ZONE)
+            .put(TableSchema.CLUSTER_ID_KEY, CLUSTER)
+            .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows")
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
             .build();
 
     verifyAttributes(connectivityErrorCountMetricData, expected1);
@@ -480,25 +466,28 @@ public void onComplete() {
     assertThat(counter.get()).isEqualTo(fakeService.getResponseCounter().get());
 
     MetricData applicationLatency =
-        getMetricData(metricReader, APPLICATION_BLOCKING_LATENCIES_NAME);
+        getMetricData(metricReader, TableApplicationBlockingLatency.NAME);
 
     Attributes expectedAttributes =
         expectedBaseAttributes.toBuilder()
-            .put(TABLE_ID_KEY, TABLE)
-            .put(ZONE_ID_KEY, ZONE)
-            .put(CLUSTER_ID_KEY, CLUSTER)
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
-            .put(METHOD_KEY, "Bigtable.ReadRows")
+            .put(TableSchema.TABLE_ID_KEY, TABLE)
+            .put(TableSchema.ZONE_ID_KEY, ZONE)
+            .put(TableSchema.CLUSTER_ID_KEY, CLUSTER)
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
+            .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows")
             .build();
     long value = getAggregatedValue(applicationLatency, expectedAttributes);
 
     assertThat(value).isAtLeast((APPLICATION_LATENCY - SLEEP_VARIABILITY) * counter.get());
 
-    MetricData operationLatency = getMetricData(metricReader, OPERATION_LATENCIES_NAME);
+    MetricData operationLatency = getMetricData(metricReader, TableOperationLatency.NAME);
     long operationLatencyValue =
         getAggregatedValue(
             operationLatency,
-            expectedAttributes.toBuilder().put(STATUS_KEY, "OK").put(STREAMING_KEY, true).build());
+            expectedAttributes.toBuilder()
+                .put(MetricLabels.STATUS_KEY, "OK")
+                .put(MetricLabels.STREAMING_KEY, true)
+                .build());
     assertThat(value).isAtMost(operationLatencyValue - SERVER_LATENCY);
   }
 
@@ -515,15 +504,15 @@ public void testReadRowsApplicationLatencyWithManualFlowControl() throws Excepti
     }
 
     MetricData applicationLatency =
-        getMetricData(metricReader, APPLICATION_BLOCKING_LATENCIES_NAME);
+        getMetricData(metricReader, TableApplicationBlockingLatency.NAME);
 
     Attributes expectedAttributes =
         expectedBaseAttributes.toBuilder()
-            .put(TABLE_ID_KEY, TABLE)
-            .put(ZONE_ID_KEY, ZONE)
-            .put(CLUSTER_ID_KEY, CLUSTER)
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
-            .put(METHOD_KEY, "Bigtable.ReadRows")
+            .put(TableSchema.TABLE_ID_KEY, TABLE)
+            .put(TableSchema.ZONE_ID_KEY, ZONE)
+            .put(TableSchema.CLUSTER_ID_KEY, CLUSTER)
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
+            .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows")
             .build();
 
     long value = getAggregatedValue(applicationLatency, expectedAttributes);
@@ -532,11 +521,14 @@ public void testReadRowsApplicationLatencyWithManualFlowControl() throws Excepti
     assertThat(counter).isEqualTo(fakeService.getResponseCounter().get());
     assertThat(value).isAtLeast(APPLICATION_LATENCY * (counter - 1) - SERVER_LATENCY);
 
-    MetricData operationLatency = getMetricData(metricReader, OPERATION_LATENCIES_NAME);
+    MetricData operationLatency = getMetricData(metricReader, TableOperationLatency.NAME);
     long operationLatencyValue =
         getAggregatedValue(
             operationLatency,
-            expectedAttributes.toBuilder().put(STATUS_KEY, "OK").put(STREAMING_KEY, true).build());
+            expectedAttributes.toBuilder()
+                .put(MetricLabels.STATUS_KEY, "OK")
+                .put(MetricLabels.STREAMING_KEY, true)
+                .build());
     assertThat(value).isAtMost(operationLatencyValue - SERVER_LATENCY);
   }
 
@@ -545,15 +537,15 @@ public void testRetryCount() throws InterruptedException {
     stub.mutateRowCallable()
         .call(RowMutation.create(TABLE, "random-row").setCell("cf", "q", "value"));
 
-    MetricData metricData = getMetricData(metricReader, RETRY_COUNT_NAME);
+    MetricData metricData = getMetricData(metricReader, TableRetryCount.NAME);
     Attributes expectedAttributes =
         expectedBaseAttributes.toBuilder()
-            .put(TABLE_ID_KEY, TABLE)
-            .put(ZONE_ID_KEY, ZONE)
-            .put(CLUSTER_ID_KEY, CLUSTER)
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
-            .put(METHOD_KEY, "Bigtable.MutateRow")
-            .put(STATUS_KEY, "OK")
+            .put(TableSchema.TABLE_ID_KEY, TABLE)
+            .put(TableSchema.ZONE_ID_KEY, ZONE)
+            .put(TableSchema.CLUSTER_ID_KEY, CLUSTER)
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
+            .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRow")
+            .put(MetricLabels.STATUS_KEY, "OK")
             .build();
 
     long value = getAggregatedValue(metricData, expectedAttributes);
@@ -566,28 +558,28 @@ public void testMutateRowAttemptsTagValues() throws InterruptedException {
         .call(RowMutation.create(TABLE, "random-row").setCell("cf", "q", "value"));
 
     outstandingRpcCounter.waitUntilRpcsDone();
-    MetricData metricData = getMetricData(metricReader, ATTEMPT_LATENCIES_NAME);
+    MetricData metricData = getMetricData(metricReader, TableAttemptLatency.NAME);
 
     Attributes expected1 =
         expectedBaseAttributes.toBuilder()
-            .put(STATUS_KEY, "UNAVAILABLE")
-            .put(TABLE_ID_KEY, TABLE)
-            .put(ZONE_ID_KEY, "global")
-            .put(CLUSTER_ID_KEY, "")
-            .put(METHOD_KEY, "Bigtable.MutateRow")
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
-            .put(STREAMING_KEY, false)
+            .put(MetricLabels.STATUS_KEY, "UNAVAILABLE")
+            .put(TableSchema.TABLE_ID_KEY, TABLE)
+            .put(TableSchema.ZONE_ID_KEY, "global")
+            .put(TableSchema.CLUSTER_ID_KEY, "")
+            .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRow")
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
+            .put(MetricLabels.STREAMING_KEY, false)
             .build();
 
     Attributes expected2 =
         expectedBaseAttributes.toBuilder()
-            .put(STATUS_KEY, "OK")
-            .put(TABLE_ID_KEY, TABLE)
-            .put(ZONE_ID_KEY, ZONE)
-            .put(CLUSTER_ID_KEY, CLUSTER)
-            .put(METHOD_KEY, "Bigtable.MutateRow")
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
-            .put(STREAMING_KEY, false)
+            .put(MetricLabels.STATUS_KEY, "OK")
+            .put(TableSchema.TABLE_ID_KEY, TABLE)
+            .put(TableSchema.ZONE_ID_KEY, ZONE)
+            .put(TableSchema.CLUSTER_ID_KEY, CLUSTER)
+            .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRow")
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
+            .put(MetricLabels.STREAMING_KEY, false)
             .build();
 
     verifyAttributes(metricData, expected1);
@@ -605,17 +597,17 @@ public void testMutateRowsPartialError() throws InterruptedException {
 
     Assert.assertThrows(BatchingException.class, batcher::close);
 
-    MetricData metricData = getMetricData(metricReader, ATTEMPT_LATENCIES_NAME);
+    MetricData metricData = getMetricData(metricReader, TableAttemptLatency.NAME);
 
     Attributes expected =
         expectedBaseAttributes.toBuilder()
-            .put(STATUS_KEY, "OK")
-            .put(TABLE_ID_KEY, TABLE)
-            .put(ZONE_ID_KEY, ZONE)
-            .put(CLUSTER_ID_KEY, CLUSTER)
-            .put(METHOD_KEY, "Bigtable.MutateRows")
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
-            .put(STREAMING_KEY, false)
+            .put(MetricLabels.STATUS_KEY, "OK")
+            .put(TableSchema.TABLE_ID_KEY, TABLE)
+            .put(TableSchema.ZONE_ID_KEY, ZONE)
+            .put(TableSchema.CLUSTER_ID_KEY, CLUSTER)
+            .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows")
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
+            .put(MetricLabels.STREAMING_KEY, false)
             .build();
 
     verifyAttributes(metricData, expected);
@@ -633,17 +625,17 @@ public void testMutateRowsRpcError() {
 
     Assert.assertThrows(BatchingException.class, batcher::close);
 
-    MetricData metricData = getMetricData(metricReader, ATTEMPT_LATENCIES_NAME);
+    MetricData metricData = getMetricData(metricReader, TableAttemptLatency.NAME);
 
     Attributes expected =
         expectedBaseAttributes.toBuilder()
-            .put(STATUS_KEY, "NOT_FOUND")
-            .put(TABLE_ID_KEY, BAD_TABLE_ID)
-            .put(ZONE_ID_KEY, "global")
-            .put(CLUSTER_ID_KEY, "")
-            .put(METHOD_KEY, "Bigtable.MutateRows")
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
-            .put(STREAMING_KEY, false)
+            .put(MetricLabels.STATUS_KEY, "NOT_FOUND")
+            .put(TableSchema.TABLE_ID_KEY, BAD_TABLE_ID)
+            .put(TableSchema.ZONE_ID_KEY, "global")
+            .put(TableSchema.CLUSTER_ID_KEY, "")
+            .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows")
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
+            .put(MetricLabels.STREAMING_KEY, false)
             .build();
 
     verifyAttributes(metricData, expected);
@@ -653,28 +645,28 @@ public void testMutateRowsRpcError() {
   public void testReadRowsAttemptsTagValues() {
     Lists.newArrayList(stub.readRowsCallable().call(Query.create("fake-table")).iterator());
 
-    MetricData metricData = getMetricData(metricReader, ATTEMPT_LATENCIES_NAME);
+    MetricData metricData = getMetricData(metricReader, TableAttemptLatency.NAME);
 
     Attributes expected1 =
         expectedBaseAttributes.toBuilder()
-            .put(STATUS_KEY, "UNAVAILABLE")
-            .put(TABLE_ID_KEY, TABLE)
-            .put(ZONE_ID_KEY, "global")
-            .put(CLUSTER_ID_KEY, "")
-            .put(METHOD_KEY, "Bigtable.ReadRows")
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
-            .put(STREAMING_KEY, true)
+            .put(MetricLabels.STATUS_KEY, "UNAVAILABLE")
+            .put(TableSchema.TABLE_ID_KEY, TABLE)
+            .put(TableSchema.ZONE_ID_KEY, "global")
+            .put(TableSchema.CLUSTER_ID_KEY, "")
+            .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows")
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
+            .put(MetricLabels.STREAMING_KEY, true)
             .build();
 
     Attributes expected2 =
         expectedBaseAttributes.toBuilder()
-            .put(STATUS_KEY, "OK")
-            .put(TABLE_ID_KEY, TABLE)
-            .put(ZONE_ID_KEY, ZONE)
-            .put(CLUSTER_ID_KEY, CLUSTER)
-            .put(METHOD_KEY, "Bigtable.ReadRows")
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
-            .put(STREAMING_KEY, true)
+            .put(MetricLabels.STATUS_KEY, "OK")
+            .put(TableSchema.TABLE_ID_KEY, TABLE)
+            .put(TableSchema.ZONE_ID_KEY, ZONE)
+            .put(TableSchema.CLUSTER_ID_KEY, CLUSTER)
+            .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows")
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
+            .put(MetricLabels.STREAMING_KEY, true)
             .build();
 
     verifyAttributes(metricData, expected1);
@@ -693,15 +685,15 @@ public void testBatchBlockingLatencies() throws InterruptedException {
 
       int expectedNumRequests = 6 / batchElementCount;
 
-      MetricData applicationLatency = getMetricData(metricReader, CLIENT_BLOCKING_LATENCIES_NAME);
+      MetricData applicationLatency = getMetricData(metricReader, TableClientBlockingLatency.NAME);
 
       Attributes expectedAttributes =
           expectedBaseAttributes.toBuilder()
-              .put(TABLE_ID_KEY, TABLE)
-              .put(ZONE_ID_KEY, ZONE)
-              .put(CLUSTER_ID_KEY, CLUSTER)
-              .put(METHOD_KEY, "Bigtable.MutateRows")
-              .put(CLIENT_NAME_KEY, CLIENT_NAME)
+              .put(TableSchema.TABLE_ID_KEY, TABLE)
+              .put(TableSchema.ZONE_ID_KEY, ZONE)
+              .put(TableSchema.CLUSTER_ID_KEY, CLUSTER)
+              .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows")
+              .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
               .build();
 
       long value = getAggregatedValue(applicationLatency, expectedAttributes);
@@ -719,15 +711,15 @@ public void testQueuedOnChannelServerStreamLatencies() throws Exception {
     Duration proxyDelayPriorTest = delayProxyDetector.getCurrentDelayUsed();
     f.get();
 
-    MetricData clientLatency = getMetricData(metricReader, CLIENT_BLOCKING_LATENCIES_NAME);
+    MetricData clientLatency = getMetricData(metricReader, TableClientBlockingLatency.NAME);
 
     Attributes attributes =
         expectedBaseAttributes.toBuilder()
-            .put(TABLE_ID_KEY, TABLE)
-            .put(CLUSTER_ID_KEY, CLUSTER)
-            .put(ZONE_ID_KEY, ZONE)
-            .put(METHOD_KEY, "Bigtable.ReadRows")
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
+            .put(TableSchema.TABLE_ID_KEY, TABLE)
+            .put(TableSchema.CLUSTER_ID_KEY, CLUSTER)
+            .put(TableSchema.ZONE_ID_KEY, ZONE)
+            .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows")
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
             .build();
 
     assertThat(Duration.ofMillis(getAggregatedValue(clientLatency, attributes)))
@@ -746,15 +738,15 @@ public void testQueuedOnChannelUnaryLatencies() throws Exception {
     f.get();
 
     outstandingRpcCounter.waitUntilRpcsDone();
-    MetricData clientLatency = getMetricData(metricReader, CLIENT_BLOCKING_LATENCIES_NAME);
+    MetricData clientLatency = getMetricData(metricReader, TableClientBlockingLatency.NAME);
 
     Attributes attributes =
         expectedBaseAttributes.toBuilder()
-            .put(TABLE_ID_KEY, TABLE)
-            .put(CLUSTER_ID_KEY, CLUSTER)
-            .put(ZONE_ID_KEY, ZONE)
-            .put(METHOD_KEY, "Bigtable.MutateRow")
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
+            .put(TableSchema.TABLE_ID_KEY, TABLE)
+            .put(TableSchema.CLUSTER_ID_KEY, CLUSTER)
+            .put(TableSchema.ZONE_ID_KEY, ZONE)
+            .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRow")
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
             .build();
 
     assertThat(Duration.ofMillis(getAggregatedValue(clientLatency, attributes)))
@@ -772,39 +764,39 @@ public void testPermanentFailure() {
     } catch (NotFoundException e) {
     }
 
-    MetricData attemptLatency = getMetricData(metricReader, ATTEMPT_LATENCIES_NAME);
+    MetricData attemptLatency = getMetricData(metricReader, TableAttemptLatency.NAME);
 
     Attributes expected =
         expectedBaseAttributes.toBuilder()
-            .put(STATUS_KEY, "NOT_FOUND")
-            .put(TABLE_ID_KEY, BAD_TABLE_ID)
-            .put(CLUSTER_ID_KEY, "")
-            .put(ZONE_ID_KEY, "global")
-            .put(STREAMING_KEY, true)
-            .put(METHOD_KEY, "Bigtable.ReadRows")
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
+            .put(MetricLabels.STATUS_KEY, "NOT_FOUND")
+            .put(TableSchema.TABLE_ID_KEY, BAD_TABLE_ID)
+            .put(TableSchema.CLUSTER_ID_KEY, "")
+            .put(TableSchema.ZONE_ID_KEY, "global")
+            .put(MetricLabels.STREAMING_KEY, true)
+            .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows")
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
             .build();
 
     verifyAttributes(attemptLatency, expected);
 
-    MetricData opLatency = getMetricData(metricReader, OPERATION_LATENCIES_NAME);
+    MetricData opLatency = getMetricData(metricReader, TableOperationLatency.NAME);
     verifyAttributes(opLatency, expected);
   }
 
   @Test
   public void testRemainingDeadline() {
     stub.readRowsCallable().all().call(Query.create(TABLE));
-    MetricData deadlineMetric = getMetricData(metricReader, REMAINING_DEADLINE_NAME);
+    MetricData deadlineMetric = getMetricData(metricReader, TableRemainingDeadline.NAME);
 
     Attributes retryAttributes =
         expectedBaseAttributes.toBuilder()
-            .put(STATUS_KEY, "UNAVAILABLE")
-            .put(TABLE_ID_KEY, TABLE)
-            .put(METHOD_KEY, "Bigtable.ReadRows")
-            .put(ZONE_ID_KEY, "global")
-            .put(CLUSTER_ID_KEY, "")
-            .put(STREAMING_KEY, true)
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
+            .put(MetricLabels.STATUS_KEY, "UNAVAILABLE")
+            .put(TableSchema.TABLE_ID_KEY, TABLE)
+            .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows")
+            .put(TableSchema.ZONE_ID_KEY, "global")
+            .put(TableSchema.CLUSTER_ID_KEY, "")
+            .put(MetricLabels.STREAMING_KEY, true)
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
             .build();
     HistogramPointData retryHistogramPointData =
         deadlineMetric.getHistogramData().getPoints().stream()
@@ -818,13 +810,13 @@ public void testRemainingDeadline() {
 
     Attributes okAttributes =
         expectedBaseAttributes.toBuilder()
-            .put(STATUS_KEY, "OK")
-            .put(TABLE_ID_KEY, TABLE)
-            .put(ZONE_ID_KEY, ZONE)
-            .put(CLUSTER_ID_KEY, CLUSTER)
-            .put(METHOD_KEY, "Bigtable.ReadRows")
-            .put(STREAMING_KEY, true)
-            .put(CLIENT_NAME_KEY, CLIENT_NAME)
+            .put(MetricLabels.STATUS_KEY, "OK")
+            .put(TableSchema.TABLE_ID_KEY, TABLE)
+            .put(TableSchema.ZONE_ID_KEY, ZONE)
+            .put(TableSchema.CLUSTER_ID_KEY, CLUSTER)
+            .put(MetricLabels.METHOD_KEY, "Bigtable.ReadRows")
+            .put(MetricLabels.STREAMING_KEY, true)
+            .put(MetricLabels.CLIENT_NAME, CLIENT_NAME)
             .build();
     HistogramPointData okHistogramPointData =
         deadlineMetric.getHistogramData().getPoints().stream()
@@ -848,19 +840,21 @@ public void testBatchWriteFlowControlTargetQpsIncreased() throws InterruptedExce
       batcher.close();
 
       MetricData targetQpsMetric =
-          getMetricData(metricReader, BATCH_WRITE_FLOW_CONTROL_TARGET_QPS_NAME);
+          getMetricData(metricReader, ClientBatchWriteFlowControlTargetQps.NAME);
       Attributes targetQpsAttributes =
-          expectedBaseAttributes.toBuilder().put(METHOD_KEY, "Bigtable.MutateRows").build();
+          expectedBaseAttributes.toBuilder()
+              .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows")
+              .build();
       double actual_qps = getAggregatedDoubleValue(targetQpsMetric, targetQpsAttributes);
       double expected_qps = 12;
       assertThat(expected_qps).isEqualTo(actual_qps);
 
-      MetricData factorMetric = getMetricData(metricReader, BATCH_WRITE_FLOW_CONTROL_FACTOR_NAME);
+      MetricData factorMetric = getMetricData(metricReader, ClientBatchWriteFlowControlFactor.NAME);
       Attributes factorAttributes =
           expectedBaseAttributes.toBuilder()
-              .put(METHOD_KEY, "Bigtable.MutateRows")
-              .put(APPLIED_KEY, true)
-              .put(STATUS_KEY, "OK")
+              .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows")
+              .put(MetricLabels.APPLIED_KEY, true)
+              .put(MetricLabels.STATUS_KEY, "OK")
               .build();
       double actual_factor_mean = getAggregatedDoubleValue(factorMetric, factorAttributes);
       double expected_factor_mean = 1.2;
@@ -878,19 +872,21 @@ public void testBatchWriteFlowControlTargetQpsDecreased() throws InterruptedExce
       batcher.close();
 
       MetricData targetQpsMetric =
-          getMetricData(metricReader, BATCH_WRITE_FLOW_CONTROL_TARGET_QPS_NAME);
+          getMetricData(metricReader, ClientBatchWriteFlowControlTargetQps.NAME);
       Attributes targetQpsAttributes =
-          expectedBaseAttributes.toBuilder().put(METHOD_KEY, "Bigtable.MutateRows").build();
+          expectedBaseAttributes.toBuilder()
+              .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows")
+              .build();
       double actual_qps = getAggregatedDoubleValue(targetQpsMetric, targetQpsAttributes);
       double expected_qps = 8.0;
       assertThat(expected_qps).isEqualTo(actual_qps);
 
-      MetricData factorMetric = getMetricData(metricReader, BATCH_WRITE_FLOW_CONTROL_FACTOR_NAME);
+      MetricData factorMetric = getMetricData(metricReader, ClientBatchWriteFlowControlFactor.NAME);
       Attributes factorAttributes =
           expectedBaseAttributes.toBuilder()
-              .put(METHOD_KEY, "Bigtable.MutateRows")
-              .put(APPLIED_KEY, true)
-              .put(STATUS_KEY, "OK")
+              .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows")
+              .put(MetricLabels.APPLIED_KEY, true)
+              .put(MetricLabels.STATUS_KEY, "OK")
               .build();
       double actual_factor_mean = getAggregatedDoubleValue(factorMetric, factorAttributes);
       double expected_factor_mean = 0.8;
@@ -908,20 +904,22 @@ public void testBatchWriteFlowControlTargetQpsCappedOnMaxFactor() throws Interru
       batcher.close();
 
       MetricData targetQpsMetric =
-          getMetricData(metricReader, BATCH_WRITE_FLOW_CONTROL_TARGET_QPS_NAME);
+          getMetricData(metricReader, ClientBatchWriteFlowControlTargetQps.NAME);
       Attributes targetQpsAttributes =
-          expectedBaseAttributes.toBuilder().put(METHOD_KEY, "Bigtable.MutateRows").build();
+          expectedBaseAttributes.toBuilder()
+              .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows")
+              .build();
       double actual_qps = getAggregatedDoubleValue(targetQpsMetric, targetQpsAttributes);
       // Factor is 1.8 but capped at 1.3 so updated QPS is 13.
       double expected_qps = 13;
       assertThat(expected_qps).isEqualTo(actual_qps);
 
-      MetricData factorMetric = getMetricData(metricReader, BATCH_WRITE_FLOW_CONTROL_FACTOR_NAME);
+      MetricData factorMetric = getMetricData(metricReader, ClientBatchWriteFlowControlFactor.NAME);
       Attributes factorAttributes =
           expectedBaseAttributes.toBuilder()
-              .put(METHOD_KEY, "Bigtable.MutateRows")
-              .put(APPLIED_KEY, true)
-              .put(STATUS_KEY, "OK")
+              .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows")
+              .put(MetricLabels.APPLIED_KEY, true)
+              .put(MetricLabels.STATUS_KEY, "OK")
               .build();
       double actual_factor_mean = getAggregatedDoubleValue(factorMetric, factorAttributes);
       // Factor is 1.8 but capped at 1.3
@@ -940,20 +938,22 @@ public void testBatchWriteFlowControlTargetQpsCappedOnMinFactor() throws Interru
       batcher.close();
 
       MetricData targetQpsMetric =
-          getMetricData(metricReader, BATCH_WRITE_FLOW_CONTROL_TARGET_QPS_NAME);
+          getMetricData(metricReader, ClientBatchWriteFlowControlTargetQps.NAME);
       Attributes targetQpsAttributes =
-          expectedBaseAttributes.toBuilder().put(METHOD_KEY, "Bigtable.MutateRows").build();
+          expectedBaseAttributes.toBuilder()
+              .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows")
+              .build();
       double actual_qps = getAggregatedDoubleValue(targetQpsMetric, targetQpsAttributes);
       // Factor is 0.5 but capped at 0.7 so updated QPS is 7.
       double expected_qps = 7;
       assertThat(expected_qps).isEqualTo(actual_qps);
 
-      MetricData factorMetric = getMetricData(metricReader, BATCH_WRITE_FLOW_CONTROL_FACTOR_NAME);
+      MetricData factorMetric = getMetricData(metricReader, ClientBatchWriteFlowControlFactor.NAME);
       Attributes factorAttributes =
           expectedBaseAttributes.toBuilder()
-              .put(METHOD_KEY, "Bigtable.MutateRows")
-              .put(APPLIED_KEY, true)
-              .put(STATUS_KEY, "OK")
+              .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows")
+              .put(MetricLabels.APPLIED_KEY, true)
+              .put(MetricLabels.STATUS_KEY, "OK")
               .build();
       double actual_factor_mean = getAggregatedDoubleValue(factorMetric, factorAttributes);
       // Factor is 0.5 but capped at 0.7
@@ -973,20 +973,22 @@ public void testBatchWriteFlowControlTargetQpsDecreasedForError() throws Interru
       batcher.close();
 
       MetricData targetQpsMetric =
-          getMetricData(metricReader, BATCH_WRITE_FLOW_CONTROL_TARGET_QPS_NAME);
+          getMetricData(metricReader, ClientBatchWriteFlowControlTargetQps.NAME);
       Attributes targetQpsAttributes =
-          expectedBaseAttributes.toBuilder().put(METHOD_KEY, "Bigtable.MutateRows").build();
+          expectedBaseAttributes.toBuilder()
+              .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows")
+              .build();
       double actual_qps = getAggregatedDoubleValue(targetQpsMetric, targetQpsAttributes);
       // On error, min factor is applied.
       double expected_qps = 7;
       assertThat(expected_qps).isEqualTo(actual_qps);
 
-      MetricData factorMetric = getMetricData(metricReader, BATCH_WRITE_FLOW_CONTROL_FACTOR_NAME);
+      MetricData factorMetric = getMetricData(metricReader, ClientBatchWriteFlowControlFactor.NAME);
       Attributes factorAttributes =
           expectedBaseAttributes.toBuilder()
-              .put(METHOD_KEY, "Bigtable.MutateRows")
-              .put(APPLIED_KEY, true)
-              .put(STATUS_KEY, "UNAVAILABLE")
+              .put(MetricLabels.METHOD_KEY, "Bigtable.MutateRows")
+              .put(MetricLabels.APPLIED_KEY, true)
+              .put(MetricLabels.STATUS_KEY, "UNAVAILABLE")
               .build();
       double actual_factor_mean = getAggregatedDoubleValue(factorMetric, factorAttributes);
       // On error, min factor is applied.
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/ChannelPoolMetricsTracerTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/ChannelPoolMetricsTracerTest.java
index e33ffe37e32c..a4da359abdd7 100644
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/ChannelPoolMetricsTracerTest.java
+++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/ChannelPoolMetricsTracerTest.java
@@ -15,8 +15,6 @@
  */
 package com.google.cloud.bigtable.data.v2.stub.metrics;
 
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.OUTSTANDING_RPCS_PER_CHANNEL_NAME;
-import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.PER_CONNECTION_ERROR_COUNT_NAME;
 import static com.google.common.truth.Truth.assertThat;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyLong;
@@ -25,6 +23,8 @@
 import com.google.bigtable.v2.InstanceName;
 import com.google.cloud.bigtable.data.v2.internal.csm.MetricRegistry;
 import com.google.cloud.bigtable.data.v2.internal.csm.attributes.ClientInfo;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.ClientChannelPoolOutstandingRpcs;
+import com.google.cloud.bigtable.data.v2.internal.csm.metrics.ClientPerConnectionErrorCount;
 import com.google.cloud.bigtable.gaxx.grpc.BigtableChannelObserver;
 import com.google.cloud.bigtable.gaxx.grpc.BigtableChannelPoolObserver;
 import com.google.cloud.bigtable.gaxx.grpc.BigtableChannelPoolSettings.LoadBalancingStrategy;
@@ -182,7 +182,7 @@ public void testSingleRun() {
 
     // Assert Outstanding RPCs metric
     Optional rpcMetricDataOpt =
-        getMetricData(metrics, OUTSTANDING_RPCS_PER_CHANNEL_NAME);
+        getMetricData(metrics, ClientChannelPoolOutstandingRpcs.NAME);
     assertThat(rpcMetricDataOpt.isPresent()).isTrue();
     MetricData rpcMetricData = rpcMetricDataOpt.get();
     Collection rpcPoints = rpcMetricData.getHistogramData().getPoints();
@@ -202,7 +202,7 @@ public void testSingleRun() {
 
     // Assert Error Count metric
     Optional errorMetricDataOpt =
-        getMetricData(metrics, PER_CONNECTION_ERROR_COUNT_NAME);
+        getMetricData(metrics, ClientPerConnectionErrorCount.NAME);
     assertThat(errorMetricDataOpt.isPresent()).isTrue();
     MetricData errorMetricData = errorMetricDataOpt.get();
     Collection errorPoints = errorMetricData.getHistogramData().getPoints();
@@ -249,7 +249,7 @@ public void testMultipleRuns() {
 
     // Assert Outstanding RPCs
     Optional rpcMetricDataOpt =
-        getMetricData(metrics, OUTSTANDING_RPCS_PER_CHANNEL_NAME);
+        getMetricData(metrics, ClientChannelPoolOutstandingRpcs.NAME);
     assertThat(rpcMetricDataOpt.isPresent()).isTrue();
     Collection rpcPoints =
         rpcMetricDataOpt.get().getHistogramData().getPoints();
@@ -265,7 +265,7 @@ public void testMultipleRuns() {
 
     // Assert Error Counts
     Optional errorMetricDataOpt =
-        getMetricData(metrics, PER_CONNECTION_ERROR_COUNT_NAME);
+        getMetricData(metrics, ClientPerConnectionErrorCount.NAME);
     assertThat(errorMetricDataOpt.isPresent()).isTrue();
     Collection errorPoints =
         errorMetricDataOpt.get().getHistogramData().getPoints();
@@ -294,7 +294,7 @@ public void testErrorMetricsOnlyRecordedForAllChannels() {
 
     Collection metrics = metricReader.collectAllMetrics();
     Optional errorMetricDataOpt =
-        getMetricData(metrics, PER_CONNECTION_ERROR_COUNT_NAME);
+        getMetricData(metrics, ClientPerConnectionErrorCount.NAME);
     assertThat(errorMetricDataOpt.isPresent()).isTrue();
     Collection errorPoints =
         errorMetricDataOpt.get().getHistogramData().getPoints();
@@ -315,7 +315,7 @@ public void testDefaultLbPolicy() {
 
     Collection metrics = metricReader.collectAllMetrics();
     Optional rpcMetricDataOpt =
-        getMetricData(metrics, OUTSTANDING_RPCS_PER_CHANNEL_NAME);
+        getMetricData(metrics, ClientChannelPoolOutstandingRpcs.NAME);
     assertThat(rpcMetricDataOpt.isPresent()).isTrue();
     Collection points = rpcMetricDataOpt.get().getHistogramData().getPoints();
 
diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/UtilTest.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/UtilTest.java
deleted file mode 100644
index f1e98e03a40f..000000000000
--- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/metrics/UtilTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2019 Google LLC
- *
- * 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
- *
- *     https://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 com.google.cloud.bigtable.data.v2.stub.metrics;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import com.google.api.gax.grpc.GrpcStatusCode;
-import com.google.api.gax.rpc.DeadlineExceededException;
-import io.grpc.Status;
-import io.opencensus.tags.TagValue;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-@RunWith(JUnit4.class)
-public class UtilTest {
-  @Test
-  public void testOk() {
-    TagValue tagValue = TagValue.create(Util.extractStatus(null).name());
-    assertThat(tagValue.asString()).isEqualTo("OK");
-  }
-
-  @Test
-  public void testError() {
-    DeadlineExceededException error =
-        new DeadlineExceededException(
-            "Deadline exceeded", null, GrpcStatusCode.of(Status.Code.DEADLINE_EXCEEDED), true);
-    TagValue tagValue = TagValue.create(Util.extractStatus(error).name());
-    assertThat(tagValue.asString()).isEqualTo("DEADLINE_EXCEEDED");
-  }
-}