Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public BigtableDataClient createDefault() {
try {
BigtableClientContext ctx =
sharedClientContext.createChild(
sharedClientContext.getInstanceName(), sharedClientContext.getAppProfileId());
sharedClientContext.getClientInfo().getInstanceName(),
sharedClientContext.getClientInfo().getAppProfileId());

return new BigtableDataClient(new EnhancedBigtableStub(perOpSettings, ctx));
} catch (IOException e) {
Expand All @@ -130,7 +131,8 @@ public BigtableDataClient createDefault() {
*/
public BigtableDataClient createForAppProfile(@Nonnull String appProfileId) throws IOException {
BigtableClientContext ctx =
sharedClientContext.createChild(sharedClientContext.getInstanceName(), appProfileId);
sharedClientContext.createChild(
sharedClientContext.getClientInfo().getInstanceName(), appProfileId);

return new BigtableDataClient(new EnhancedBigtableStub(perOpSettings, ctx));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.google.api.core.InternalApi;
import com.google.auto.value.AutoValue;
import com.google.cloud.bigtable.data.v2.internal.csm.attributes.ClientInfo;
import java.io.Serializable;

/**
Expand All @@ -33,6 +34,13 @@
@AutoValue
public abstract class RequestContext implements Serializable {

public static RequestContext create(ClientInfo clientInfo) {
return create(
clientInfo.getInstanceName().getProject(),
clientInfo.getInstanceName().getInstance(),
clientInfo.getAppProfileId());
}

/** Creates a new instance of the {@link RequestContext}. */
public static RequestContext create(String projectId, String instanceId, String appProfileId) {
return new AutoValue_RequestContext(projectId, instanceId, appProfileId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.auth.oauth2.ServiceAccountJwtAccessCredentials;
import com.google.bigtable.v2.InstanceName;
import com.google.cloud.bigtable.data.v2.internal.JwtCredentialsWithAudience;
import com.google.cloud.bigtable.data.v2.internal.csm.attributes.ClientInfo;
import com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants;
import com.google.cloud.bigtable.data.v2.stub.metrics.ChannelPoolMetricsTracer;
import com.google.cloud.bigtable.data.v2.stub.metrics.CompositeTracerFactory;
Expand Down Expand Up @@ -63,8 +64,7 @@ public class BigtableClientContext {
private static final Logger logger = Logger.getLogger(BigtableClientContext.class.getName());

private final boolean isChild;
private final InstanceName instanceName;
private final String appProfileId;
private final ClientInfo clientInfo;
private final ApiTracerFactory userTracerFactory;
@Nullable private final OpenTelemetrySdk builtinOpenTelemetry;
@Nullable private final OpenTelemetry userOpenTelemetry;
Expand All @@ -83,8 +83,11 @@ public static BigtableClientContext create(EnhancedBigtableStubSettings settings
public static BigtableClientContext create(
EnhancedBigtableStubSettings settings, Tagger ocTagger, StatsRecorder ocRecorder)
throws IOException {
InstanceName instanceName = InstanceName.of(settings.getProjectId(), settings.getInstanceId());
String appProfileId = settings.getAppProfileId();
ClientInfo clientInfo =
ClientInfo.builder()
.setInstanceName(InstanceName.of(settings.getProjectId(), settings.getInstanceId()))
.setAppProfileId(settings.getAppProfileId())
.build();

EnhancedBigtableStubSettings.Builder builder = settings.toBuilder();

Expand Down Expand Up @@ -184,8 +187,7 @@ public static BigtableClientContext create(

return new BigtableClientContext(
false,
instanceName,
appProfileId,
clientInfo,
clientContext,
userTracerFactory,
builtinOtel,
Expand Down Expand Up @@ -224,8 +226,7 @@ private static void configureGrpcOtel(

private BigtableClientContext(
boolean isChild,
InstanceName instanceName,
String appProfileId,
ClientInfo clientInfo,
ClientContext clientContext,
ApiTracerFactory userTracerFactory,
@Nullable OpenTelemetrySdk builtinOtel,
Expand All @@ -235,8 +236,7 @@ private BigtableClientContext(
ExecutorProvider backgroundExecutorProvider)
throws IOException {
this.isChild = isChild;
this.instanceName = instanceName;
this.appProfileId = appProfileId;
this.clientInfo = clientInfo;

this.userTracerFactory = userTracerFactory;
this.builtinOpenTelemetry = builtinOtel;
Expand All @@ -247,15 +247,15 @@ private BigtableClientContext(

ImmutableList.Builder<ApiTracerFactory> tracerFactories = ImmutableList.builder();
tracerFactories
.add(Util.createOCTracingFactory(instanceName, appProfileId))
.add(Util.createOCMetricsFactory(instanceName, appProfileId, ocTagger, ocRecorder))
.add(Util.createOCTracingFactory(clientInfo))
.add(Util.createOCMetricsFactory(clientInfo, ocTagger, ocRecorder))
.add(userTracerFactory);

if (builtinOtel != null) {
tracerFactories.add(Util.createOtelMetricsFactory(builtinOtel, instanceName, appProfileId));
tracerFactories.add(Util.createOtelMetricsFactory(builtinOtel, clientInfo));
}
if (userOtel != null) {
tracerFactories.add(Util.createOtelMetricsFactory(userOtel, instanceName, appProfileId));
tracerFactories.add(Util.createOtelMetricsFactory(userOtel, clientInfo));
}

this.clientContext =
Expand All @@ -264,12 +264,8 @@ private BigtableClientContext(
.build();
}

public InstanceName getInstanceName() {
return instanceName;
}

public String getAppProfileId() {
return appProfileId;
public ClientInfo getClientInfo() {
return clientInfo;
}

@Nullable
Expand All @@ -290,8 +286,7 @@ public BigtableClientContext createChild(InstanceName instanceName, String appPr
throws IOException {
return new BigtableClientContext(
true,
instanceName,
appProfileId,
clientInfo.toBuilder().setInstanceName(instanceName).setAppProfileId(appProfileId).build(),
clientContext,
userTracerFactory,
builtinOpenTelemetry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,7 @@ public EnhancedBigtableStub(
ClientOperationSettings perOpSettings, BigtableClientContext clientContext) {
this.perOpSettings = perOpSettings;
this.bigtableClientContext = clientContext;
this.requestContext =
RequestContext.create(
clientContext.getInstanceName().getProject(),
clientContext.getInstanceName().getInstance(),
clientContext.getAppProfileId());
this.requestContext = RequestContext.create(clientContext.getClientInfo());
this.bulkMutationFlowController =
new FlowController(perOpSettings.bulkMutateRowsSettings.getDynamicFlowControlSettings());
this.bulkMutationDynamicFlowControlStats = new DynamicFlowControlStats();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
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.APP_PROFILE_KEY;
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.ATTEMPT_LATENCIES2_NAME;
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.BIGTABLE_PROJECT_ID_KEY;
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.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.INSTANCE_ID_KEY;
import static com.google.cloud.bigtable.data.v2.stub.metrics.BuiltinMetricsConstants.METER_NAME;
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;
Expand All @@ -34,6 +38,8 @@
import com.google.api.gax.tracing.ApiTracerFactory;
import com.google.api.gax.tracing.BaseApiTracerFactory;
import com.google.api.gax.tracing.SpanName;
import com.google.cloud.bigtable.Version;
import com.google.cloud.bigtable.data.v2.internal.csm.attributes.ClientInfo;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.DoubleGauge;
Expand Down Expand Up @@ -68,14 +74,24 @@ public class BuiltinMetricsTracerFactory extends BaseApiTracerFactory {
private final DoubleHistogram batchWriteFlowControlFactorHistogram;

public static BuiltinMetricsTracerFactory create(
OpenTelemetry openTelemetry, Attributes attributes) throws IOException {
return new BuiltinMetricsTracerFactory(openTelemetry, attributes);
OpenTelemetry openTelemetry, ClientInfo clientInfo) throws IOException {
return new BuiltinMetricsTracerFactory(openTelemetry, clientInfo);
}

BuiltinMetricsTracerFactory(OpenTelemetry openTelemetry, Attributes attributes) {
this.attributes = attributes;
BuiltinMetricsTracerFactory(OpenTelemetry openTelemetry, ClientInfo clientInfo) {
Meter meter = openTelemetry.getMeter(METER_NAME);

this.attributes =
Attributes.of(
BIGTABLE_PROJECT_ID_KEY,
clientInfo.getInstanceName().getProject(),
INSTANCE_ID_KEY,
clientInfo.getInstanceName().getInstance(),
APP_PROFILE_KEY,
clientInfo.getAppProfileId(),
CLIENT_NAME_KEY,
"bigtable-java/" + Version.VERSION);

operationLatenciesHistogram =
meter
.histogramBuilder(OPERATION_LATENCIES_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +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.INSTANCE_ID_KEY;

import com.google.api.core.InternalApi;
import com.google.api.gax.grpc.GaxGrpcProperties;
import com.google.api.gax.rpc.ApiCallContext;
Expand All @@ -45,6 +40,7 @@
import com.google.bigtable.v2.TableName;
import com.google.cloud.bigtable.Version;
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
import com.google.cloud.bigtable.data.v2.internal.csm.attributes.ClientInfo;
import com.google.cloud.bigtable.data.v2.stub.MetadataExtractorInterceptor;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
Expand All @@ -58,7 +54,6 @@
import io.opencensus.tags.TagValue;
import io.opencensus.tags.Tagger;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.metrics.InstrumentSelector;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
Expand Down Expand Up @@ -241,14 +236,18 @@ public static String formatZoneIdMetricLabel(
.orElse("global");
}

public static ApiTracerFactory createOCTracingFactory(
InstanceName instanceName, String appProfileId) {
public static ApiTracerFactory createOCTracingFactory(ClientInfo clientInfo) {
return new OpencensusTracerFactory(
ImmutableMap.<String, String>builder()
// Annotate traces with the same tags as metrics
.put(RpcMeasureConstants.BIGTABLE_PROJECT_ID.getName(), instanceName.getProject())
.put(RpcMeasureConstants.BIGTABLE_INSTANCE_ID.getName(), instanceName.getInstance())
.put(RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID.getName(), appProfileId)
.put(
RpcMeasureConstants.BIGTABLE_PROJECT_ID.getName(),
clientInfo.getInstanceName().getProject())
.put(
RpcMeasureConstants.BIGTABLE_INSTANCE_ID.getName(),
clientInfo.getInstanceName().getInstance())
.put(
RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID.getName(), clientInfo.getAppProfileId())
// Also annotate traces with library versions
.put("gax", GaxGrpcProperties.getGaxGrpcVersion())
.put("grpc", GaxGrpcProperties.getGrpcVersion())
Expand All @@ -257,32 +256,25 @@ public static ApiTracerFactory createOCTracingFactory(
}

public static ApiTracerFactory createOCMetricsFactory(
InstanceName instanceName, String appProfileId, Tagger tagger, StatsRecorder stats) {
ClientInfo clientInfo, Tagger tagger, StatsRecorder stats) {

ImmutableMap<TagKey, TagValue> attributes =
ImmutableMap.<TagKey, TagValue>builder()
.put(
RpcMeasureConstants.BIGTABLE_PROJECT_ID, TagValue.create(instanceName.getProject()))
RpcMeasureConstants.BIGTABLE_PROJECT_ID,
TagValue.create(clientInfo.getInstanceName().getProject()))
.put(
RpcMeasureConstants.BIGTABLE_INSTANCE_ID,
TagValue.create(instanceName.getInstance()))
.put(RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID, TagValue.create(appProfileId))
TagValue.create(clientInfo.getInstanceName().getInstance()))
.put(
RpcMeasureConstants.BIGTABLE_APP_PROFILE_ID,
TagValue.create(clientInfo.getAppProfileId()))
.build();
return MetricsTracerFactory.create(tagger, stats, attributes);
}

public static BuiltinMetricsTracerFactory createOtelMetricsFactory(
OpenTelemetry otel, InstanceName instanceName, String appProfileId) throws IOException {
Attributes attributes =
Attributes.of(
BIGTABLE_PROJECT_ID_KEY,
instanceName.getProject(),
INSTANCE_ID_KEY,
instanceName.getInstance(),
APP_PROFILE_KEY,
appProfileId,
CLIENT_NAME_KEY,
"bigtable-java/" + Version.VERSION);
return BuiltinMetricsTracerFactory.create(otel, attributes);
OpenTelemetry otel, ClientInfo clientInfo) {
return new BuiltinMetricsTracerFactory(otel, clientInfo);
}
}
Loading
Loading