Skip to content

Commit

Permalink
add TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
mutianf committed Dec 8, 2021
1 parent 74ae744 commit 53e0717
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 211 deletions.
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.cloud.bigtable.data.v2.stub;

import com.google.api.MonitoredResource;
import com.google.api.core.BetaApi;
import com.google.api.core.InternalApi;
import com.google.api.gax.batching.Batcher;
Expand Down Expand Up @@ -151,11 +152,13 @@ public class EnhancedBigtableStub implements AutoCloseable {
public static EnhancedBigtableStub create(EnhancedBigtableStubSettings settings)
throws IOException {
settings = finalizeSettings(settings, Tags.getTagger(), Stats.getStatsRecorder());
// TODO: register monitored resource and move project id, instance id to Monitored resource
if (EnhancedBigtableStub.exporterRegistered.compareAndSet(false, true)) {
BigtableStackdriverStatsExporter.createAndRegister(
StackdriverStatsConfiguration.builder()
.setProjectId(settings.getProjectId())
.setMonitoredResource(
MonitoredResource.newBuilder().setType("bigtable_table").build())
.setMetricNamePrefix("bigtable.googleapis.com/client/")
.setExportInterval(Duration.create(10, 0))
.build());
}
Expand Down

This file was deleted.

Expand Up @@ -21,13 +21,10 @@
import com.google.bigtable.veneer.repackaged.io.opencensus.metrics.LabelKey;
import com.google.bigtable.veneer.repackaged.io.opencensus.metrics.LabelValue;
import com.google.bigtable.veneer.repackaged.io.opencensus.metrics.export.Metric;
import com.google.bigtable.veneer.repackaged.io.opencensus.trace.Span;
import com.google.bigtable.veneer.repackaged.io.opencensus.trace.Status;
import com.google.bigtable.veneer.repackaged.io.opencensus.trace.Tracer;
import com.google.bigtable.veneer.repackaged.io.opencensus.trace.Tracing;
import com.google.cloud.bigtable.data.v2.stub.metrics.builtin.BuiltinMeasureConstants;
import com.google.cloud.monitoring.v3.MetricServiceClient;
import com.google.common.collect.Lists;
import com.google.monitoring.v3.CreateTimeSeriesRequest;
import com.google.monitoring.v3.ProjectName;
import com.google.monitoring.v3.TimeSeries;
Expand Down Expand Up @@ -84,8 +81,10 @@ public void export(Collection<Metric> metrics) {

for (com.google.bigtable.veneer.repackaged.io.opencensus.metrics.export.TimeSeries
timeSeries : metric.getTimeSeriesList()) {
// TODO: filter out timeseries that 's not from bigtble
MonitoredResource.Builder timeSeriesResourceBuilder = this.monitoredResource.toBuilder();
List<LabelValue> labelValues = timeSeries.getLabelValues();
// TODO: add project id and instance id
if (clusterIndex != -1) {
timeSeriesResourceBuilder.putLabels(
clueterLabel, labelValues.get(clusterIndex).getValue());
Expand All @@ -96,6 +95,8 @@ public void export(Collection<Metric> metrics) {
if (tableIndex != -1) {
timeSeriesResourceBuilder.putLabels(tableLabel, labelValues.get(tableIndex).getValue());
}
// TODO add uid as a tag

timeSeriesList.add(
BigtableStackdriverExportUtils.convertTimeSeries(
metric,
Expand All @@ -107,34 +108,17 @@ public void export(Collection<Metric> metrics) {
}
}

Span span = tracer.getCurrentSpan();
for (List<TimeSeries> batchedTimeSeries :
Lists.partition(timeSeriesList, BigtableStackdriverExportUtils.MAX_BATCH_EXPORT_SIZE)) {
span.addAnnotation("Export Stackdriver TimeSeries.");

try {
CreateTimeSeriesRequest request =
CreateTimeSeriesRequest.newBuilder()
.setName(this.projectName.toString())
.addAllTimeSeries(batchedTimeSeries)
.build();
this.metricServiceClient.createTimeSeries(request);
span.addAnnotation("Finish exporting TimeSeries.");
} catch (ApiException e) {
logger.log(Level.WARNING, "ApiException thrown when exporting TimeSeries.", e);
span.setStatus(
Status.CanonicalCode.valueOf(e.getStatusCode().getCode().name())
.toStatus()
.withDescription(
"ApiException thrown when exporting TimeSeries: "
+ BigtableStackdriverExportUtils.exceptionMessage(e)));
} catch (Throwable e) {
logger.log(Level.WARNING, "Exception thrown when exporting TimeSeries.", e);
span.setStatus(
Status.UNKNOWN.withDescription(
"Exception thrown when exporting TimeSeries: "
+ BigtableStackdriverExportUtils.exceptionMessage(e)));
}
try {
CreateTimeSeriesRequest request =
CreateTimeSeriesRequest.newBuilder()
.setName(this.projectName.toString())
.addAllTimeSeries(timeSeriesList)
.build();
this.metricServiceClient.createTimeSeries(request);
} catch (ApiException e) {
logger.log(Level.WARNING, "ApiException thrown when exporting TimeSeries.", e);
} catch (Throwable e) {
logger.log(Level.WARNING, "Exception thrown when exporting TimeSeries.", e);
}
}
}
Expand Up @@ -70,18 +70,12 @@ private BigtableStackdriverStatsExporter(
intervalMetricReaderOptionsBuilder.setExportInterval(exportInterval);
this.intervalMetricReader =
IntervalMetricReader.create(
new BigtableCreateMetricDescriptorExporter(
new BigtableCreateTimeSeriesExporter(
projectId,
metricServiceClient,
monitoredResource,
metricNamePrefix,
displayNamePrefix,
constantLabels,
new BigtableCreateTimeSeriesExporter(
projectId,
metricServiceClient,
monitoredResource,
metricNamePrefix,
constantLabels)),
constantLabels),
MetricReader.create(
com.google.bigtable.veneer.repackaged.io.opencensus.exporter.metrics.util
.MetricReader.Options.builder()
Expand Down

0 comments on commit 53e0717

Please sign in to comment.