-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the export logic for per-connection error rate metric (#2121)
* Add the metric export logic. * Fix integration test failure by updating set of metrics. * Refactor the creation of MonitoredResource. * Use StackdriverStatsConfiguration to get GCE/GKE monitoring resource. * Use preconditions to check null values. * Remove unnecesary checks.
- Loading branch information
Showing
11 changed files
with
370 additions
and
52 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
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
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
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
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
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
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
57 changes: 57 additions & 0 deletions
57
...igtable-stats/src/main/java/com/google/cloud/bigtable/stats/ConsumerEnvironmentUtils.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,57 @@ | ||
/* | ||
* Copyright 2024 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.common.annotations.VisibleForTesting; | ||
import io.opencensus.contrib.resource.util.CloudResource; | ||
import io.opencensus.contrib.resource.util.ContainerResource; | ||
import io.opencensus.contrib.resource.util.HostResource; | ||
import io.opencensus.contrib.resource.util.ResourceUtils; | ||
import io.opencensus.resource.Resource; | ||
import java.util.Objects; | ||
|
||
/** A class for extracting details about consumer environments (GCE and GKE) for metrics. */ | ||
class ConsumerEnvironmentUtils { | ||
|
||
private static ResourceUtilsWrapper resourceUtilsWrapper = new ResourceUtilsWrapper(); | ||
|
||
@VisibleForTesting | ||
public static void setResourceUtilsWrapper(ResourceUtilsWrapper newResourceUtilsWrapper) { | ||
resourceUtilsWrapper = newResourceUtilsWrapper; | ||
} | ||
|
||
public static boolean isEnvGce() { | ||
Resource resource = resourceUtilsWrapper.detectResource(); | ||
return Objects.equals(resource.getType(), HostResource.TYPE) | ||
&& Objects.equals( | ||
resource.getLabels().get(CloudResource.PROVIDER_KEY), CloudResource.PROVIDER_GCP); | ||
} | ||
|
||
public static boolean isEnvGke() { | ||
Resource resource = resourceUtilsWrapper.detectResource(); | ||
return Objects.equals(resource.getType(), ContainerResource.TYPE) | ||
&& Objects.equals( | ||
resource.getLabels().get(CloudResource.PROVIDER_KEY), CloudResource.PROVIDER_GCP); | ||
} | ||
|
||
// We wrap the static ResourceUtils.detectResource() method in a non-static method for mocking. | ||
@VisibleForTesting | ||
public static class ResourceUtilsWrapper { | ||
public Resource detectResource() { | ||
return ResourceUtils.detectResource(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.