-
Notifications
You must be signed in to change notification settings - Fork 97
feat: add stackdriver exporter #1247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
ef67fbd
remove status from application latency
mutianf 8c943fb
feat: update tracers to use built in metrics
mutianf 8253a9a
feat: add response protos
mutianf 92b1f48
feat: add response protos
mutianf 50a1eab
feat: add stackdriver exporter
mutianf 07615bd
fix tests
mutianf f499a1b
fix dependency
mutianf 3ea3739
remove unused dependency
mutianf 2032527
clean up code
mutianf fa1756e
udpates on comments
mutianf f5678b4
remove unused setting
mutianf 1d77308
make metrics consistent with cloud monitoring
mutianf 6c92a39
convert undefined to global
mutianf c3afccb
update
mutianf c966671
add bigtable tracer back in the base callable
mutianf aee2e15
fix format
mutianf 8129f02
fix the tag name
mutianf 551cff8
add the link to the form
mutianf da85a10
fix format
mutianf 541feb1
fix dependency conflicts
mutianf d8f6162
fix image tests
mutianf b219200
update undefined cluster to global
mutianf a5530dd
address comments
mutianf 8feaeec
tweak export interval
mutianf e960878
remove unused metric kind
mutianf ca63660
get project id from the metrics
mutianf 5996119
clean up imports
mutianf ee04276
remove unused method and rewrite create timeseries exporter
mutianf 7607480
fix integration test
mutianf 559a168
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.