-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add stackdriver exporter (#1247)
* remove status from application latency * feat: update tracers to use built in metrics * feat: add response protos * feat: add response protos * feat: add stackdriver exporter * fix tests * fix dependency * remove unused dependency * clean up code * udpates on comments * remove unused setting * make metrics consistent with cloud monitoring * convert undefined to global * update * add bigtable tracer back in the base callable * fix format * fix the tag name * add the link to the form * fix format * fix dependency conflicts * fix image tests * update undefined cluster to global * address comments * tweak export interval * remove unused metric kind * get project id from the metrics * clean up imports * remove unused method and rewrite create timeseries exporter * fix integration test * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
b865578
commit 7ce915e
Showing
15 changed files
with
789 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...stats/src/main/java/com/google/cloud/bigtable/stats/BigtableCreateTimeSeriesExporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2022 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.stats; | ||
|
||
import com.google.api.MonitoredResource; | ||
import com.google.cloud.monitoring.v3.MetricServiceClient; | ||
import com.google.monitoring.v3.CreateTimeSeriesRequest; | ||
import com.google.monitoring.v3.ProjectName; | ||
import io.opencensus.exporter.metrics.util.MetricExporter; | ||
import io.opencensus.metrics.export.Metric; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import java.util.stream.Collectors; | ||
|
||
final class BigtableCreateTimeSeriesExporter extends MetricExporter { | ||
private static final Logger logger = | ||
Logger.getLogger(BigtableCreateTimeSeriesExporter.class.getName()); | ||
private final MetricServiceClient metricServiceClient; | ||
private final MonitoredResource monitoredResource; | ||
private final String clientId; | ||
|
||
BigtableCreateTimeSeriesExporter( | ||
MetricServiceClient metricServiceClient, MonitoredResource monitoredResource) { | ||
this.metricServiceClient = metricServiceClient; | ||
this.monitoredResource = monitoredResource; | ||
this.clientId = BigtableStackdriverExportUtils.getDefaultTaskValue(); | ||
} | ||
|
||
public void export(Collection<Metric> metrics) { | ||
Map<String, List<com.google.monitoring.v3.TimeSeries>> projectToTimeSeries = new HashMap<>(); | ||
|
||
for (Metric metric : metrics) { | ||
// only export bigtable metrics | ||
if (!metric.getMetricDescriptor().getName().contains("bigtable")) { | ||
continue; | ||
} | ||
|
||
try { | ||
projectToTimeSeries = | ||
metric.getTimeSeriesList().stream() | ||
.collect( | ||
Collectors.groupingBy( | ||
timeSeries -> | ||
BigtableStackdriverExportUtils.getProjectId( | ||
metric.getMetricDescriptor(), timeSeries), | ||
Collectors.mapping( | ||
timeSeries -> | ||
BigtableStackdriverExportUtils.convertTimeSeries( | ||
metric.getMetricDescriptor(), | ||
timeSeries, | ||
clientId, | ||
monitoredResource), | ||
Collectors.toList()))); | ||
|
||
for (Map.Entry<String, List<com.google.monitoring.v3.TimeSeries>> entry : | ||
projectToTimeSeries.entrySet()) { | ||
ProjectName projectName = ProjectName.of(entry.getKey()); | ||
CreateTimeSeriesRequest request = | ||
CreateTimeSeriesRequest.newBuilder() | ||
.setName(projectName.toString()) | ||
.addAllTimeSeries(entry.getValue()) | ||
.build(); | ||
this.metricServiceClient.createServiceTimeSeries(request); | ||
} | ||
} catch (Throwable e) { | ||
logger.log(Level.WARNING, "Exception thrown when exporting TimeSeries.", e); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.