- Notifications
You must be signed in to change notification settings - Fork 136
feat: [Internal] open telemetry built in metrics for GRPC #3709
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
Changes from all commits
5806943 4329770 1f87e91 c18fec2 7b6c0a7 01adb67 70ff8bf 80d3017 b2f4293 5b29243 64e02f7 1801433 94e8161 File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -16,8 +16,6 @@ | |
| | ||
| package com.google.cloud.spanner; | ||
| | ||
| import static com.google.cloud.spanner.BuiltInMetricsConstant.SPANNER_METRICS; | ||
| | ||
| import com.google.api.core.ApiFuture; | ||
| import com.google.api.core.ApiFutureCallback; | ||
| import com.google.api.core.ApiFutures; | ||
| | @@ -39,8 +37,8 @@ | |
| import io.opentelemetry.sdk.metrics.InstrumentType; | ||
| import io.opentelemetry.sdk.metrics.data.AggregationTemporality; | ||
| import io.opentelemetry.sdk.metrics.data.MetricData; | ||
| import io.opentelemetry.sdk.metrics.data.PointData; | ||
| import io.opentelemetry.sdk.metrics.export.MetricExporter; | ||
| import io.opentelemetry.sdk.resources.Resource; | ||
| import java.io.IOException; | ||
| import java.time.Duration; | ||
| import java.util.ArrayList; | ||
| | @@ -114,27 +112,19 @@ public CompletableResultCode export(@Nonnull Collection<MetricData> collection) | |
| | ||
| /** Export client built in metrics */ | ||
| private CompletableResultCode exportSpannerClientMetrics(Collection<MetricData> collection) { | ||
| // Filter spanner metrics. Only include metrics that contain a project and instance ID. | ||
| List<MetricData> spannerMetricData = | ||
| collection.stream() | ||
| .filter(md -> SPANNER_METRICS.contains(md.getName())) | ||
| .collect(Collectors.toList()); | ||
| // Filter spanner metrics. Only include metrics that contain a valid project. | ||
| List<MetricData> spannerMetricData = collection.stream().collect(Collectors.toList()); | ||
| | ||
| // Log warnings for metrics that will be skipped. | ||
| boolean mustFilter = false; | ||
| if (spannerMetricData.stream() | ||
| .flatMap(metricData -> metricData.getData().getPoints().stream()) | ||
| .map(metricData -> metricData.getResource()) | ||
| .anyMatch(this::shouldSkipPointDataDueToProjectId)) { | ||
| logger.log( | ||
| Level.WARNING, "Some metric data contain a different projectId. These will be skipped."); | ||
| mustFilter = true; | ||
| } | ||
| if (spannerMetricData.stream() | ||
| .flatMap(metricData -> metricData.getData().getPoints().stream()) | ||
| .anyMatch(this::shouldSkipPointDataDueToMissingInstanceId)) { | ||
| Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious - why are we skipping this. Did we fix the issue that a instance id could be missing (because we will set "unknown" by default?). My concern is that if there is a bug that causes the instance id not to be correctly populated, we won't be able to catch that regression. Contributor Author There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Earlier instance_id was only getting set from We can catch regression by | ||
| logger.log(Level.WARNING, "Some metric data miss instanceId. These will be skipped."); | ||
| mustFilter = true; | ||
| } | ||
| | ||
| if (mustFilter) { | ||
| spannerMetricData = | ||
| spannerMetricData.stream() | ||
| | @@ -198,19 +188,11 @@ public void onSuccess(List<Empty> empty) { | |
| } | ||
| | ||
| private boolean shouldSkipMetricData(MetricData metricData) { | ||
| return metricData.getData().getPoints().stream() | ||
| .anyMatch( | ||
| pd -> | ||
| shouldSkipPointDataDueToProjectId(pd) | ||
| || shouldSkipPointDataDueToMissingInstanceId(pd)); | ||
| } | ||
| | ||
| private boolean shouldSkipPointDataDueToProjectId(PointData pointData) { | ||
| return !spannerProjectId.equals(SpannerCloudMonitoringExporterUtils.getProjectId(pointData)); | ||
| return shouldSkipPointDataDueToProjectId(metricData.getResource()); | ||
| } | ||
| | ||
| private boolean shouldSkipPointDataDueToMissingInstanceId(PointData pointData) { | ||
| return SpannerCloudMonitoringExporterUtils.getInstanceId(pointData) == null; | ||
| private boolean shouldSkipPointDataDueToProjectId(Resource resource) { | ||
| return !spannerProjectId.equals(SpannerCloudMonitoringExporterUtils.getProjectId(resource)); | ||
| } | ||
| | ||
| boolean lastExportSkippedData() { | ||
| | ||
Uh oh!
There was an error while loading. Please reload this page.