Skip to content

Commit

Permalink
record metrics whenever it's registered
Browse files Browse the repository at this point in the history
  • Loading branch information
mutianf committed Mar 29, 2024
1 parent 21cad39 commit 1f291fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import com.google.cloud.bigtable.data.v2.models.RowMutation;
import com.google.cloud.bigtable.data.v2.stub.metrics.DefaultMetricsProvider;
import com.google.cloud.bigtable.data.v2.stub.metrics.MetricsProvider;
import com.google.cloud.bigtable.data.v2.stub.metrics.NoopMetricsProvider;
import com.google.cloud.bigtable.data.v2.stub.mutaterows.MutateRowsBatchingDescriptor;
import com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsBatchingDescriptor;
import com.google.common.base.MoreObjects;
Expand Down Expand Up @@ -1068,8 +1067,11 @@ public EnhancedBigtableStubSettings build() {

featureFlags.setRoutingCookie(this.getEnableRoutingCookie());
featureFlags.setRetryInfo(this.getEnableRetryInfo());
// client_Side_metrics_enabled feature flag is only set when a user is running with a
// DefaultMetricsProvider. This may cause false negatives when a user registered the
// metrics on their CustomOpenTelemetryMetricsProvider.
featureFlags.setClientSideMetricsEnabled(
!(this.getMetricsProvider() instanceof NoopMetricsProvider));
this.getMetricsProvider() instanceof DefaultMetricsProvider);

// Serialize the web64 encode the bigtable feature flags
ByteArrayOutputStream boas = new ByteArrayOutputStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.Nullable;

/**
Expand All @@ -33,6 +34,8 @@
*/
public class BuiltinMetricsView {

private static final AtomicBoolean BUILTIN_VIEW_REGISTERED = new AtomicBoolean();

private BuiltinMetricsView() {}

/**
Expand All @@ -50,6 +53,7 @@ public static void registerBuiltinMetrics(
String projectId, @Nullable Credentials credentials, SdkMeterProviderBuilder builder)
throws IOException {
MetricExporter metricExporter = BigtableCloudMonitoringExporter.create(projectId, credentials);
BUILTIN_VIEW_REGISTERED.set(true);
for (Map.Entry<InstrumentSelector, View> entry :
BuiltinMetricsConstants.getAllViews().entrySet()) {
builder.registerView(entry.getKey(), entry.getValue());
Expand Down

0 comments on commit 1f291fb

Please sign in to comment.