Skip to content

Commit

Permalink
feat: add built-in metric constants (#1243)
Browse files Browse the repository at this point in the history
* feat: add built in metrics measure and views

* remove status from application latency

* Rename methods and add comments

* update based on comments

* add comment for client id

* move dependency

* use SUM for connectivity errors

* update on comments

* update dependencies

* 🦉 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
mutianf and gcf-owl-bot[bot] authored Jun 21, 2022
1 parent 4a3a2c9 commit b1fc00a
Show file tree
Hide file tree
Showing 11 changed files with 1,063 additions and 33 deletions.
5 changes: 5 additions & 0 deletions google-cloud-bigtable-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
<artifactId>proto-google-cloud-bigtable-v2</artifactId>
<version>2.8.1-SNAPSHOT</version><!-- {x-version-update:proto-google-cloud-bigtable-v2:current} -->
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-bigtable-stats</artifactId>
<version>2.8.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-bigtable:current} -->
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
31 changes: 24 additions & 7 deletions google-cloud-bigtable-stats/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,38 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax</artifactId>
</dependency>
<dependency>
<groupId>com.google.api</groupId>
<artifactId>api-common</artifactId>
</dependency>

<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-api</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-exporter-stats-stackdriver</artifactId>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

Expand All @@ -48,6 +69,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -78,11 +100,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<ignoredUnusedDeclaredDependencies>
<ignoredUnusedDeclaredDependency>*</ignoredUnusedDeclaredDependency>
</ignoredUnusedDeclaredDependencies>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* 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 static io.opencensus.stats.Measure.MeasureLong;

import io.opencensus.tags.TagKey;

/** Built-in metrics that will be readable under bigtable.googleapis.com/client namespace */
class BuiltinMeasureConstants {
// Monitored resource TagKeys
static final TagKey PROJECT_ID = TagKey.create("project_id");
static final TagKey INSTANCE_ID = TagKey.create("instance_id");
static final TagKey CLUSTER = TagKey.create("cluster");
static final TagKey TABLE = TagKey.create("table");
static final TagKey ZONE = TagKey.create("zone");
// Placeholder TagKey to be used in Stackdriver exporter
static final TagKey CLIENT_ID = TagKey.create("client_id");

// Metrics TagKeys
static final TagKey APP_PROFILE = TagKey.create("app_profile");
static final TagKey METHOD = TagKey.create("method");
static final TagKey STREAMING = TagKey.create("streaming");
static final TagKey STATUS = TagKey.create("status");
static final TagKey CLIENT_NAME = TagKey.create("client_name");

// Units
private static final String COUNT = "1";
private static final String MILLISECOND = "ms";

// Measurements
static final MeasureLong OPERATION_LATENCIES =
MeasureLong.create(
"bigtable.googleapis.com/internal/client/operation_latencies",
"Total time until final operation success or failure, including retries and backoff.",
MILLISECOND);

static final MeasureLong ATTEMPT_LATENCIES =
MeasureLong.create(
"bigtable.googleapis.com/internal/client/attempt_latencies",
"Client observed latency per RPC attempt.",
MILLISECOND);

static final MeasureLong RETRY_COUNT =
MeasureLong.create(
"bigtable.googleapis.com/internal/client/retry_count",
"The number of additional RPCs sent after the initial attempt.",
COUNT);

static final MeasureLong FIRST_RESPONSE_LATENCIES =
MeasureLong.create(
"bigtable.googleapis.com/internal/client/first_response_latencies",
"Latency from operation start until the response headers were received. The publishing of the measurement will be delayed until the attempt response has been received.",
MILLISECOND);

static final MeasureLong SERVER_LATENCIES =
MeasureLong.create(
"bigtable.googleapis.com/internal/client/server_latencies",
"The latency measured from the moment that the RPC entered the Google data center until the RPC was completed.",
MILLISECOND);

static final MeasureLong CONNECTIVITY_ERROR_COUNT =
MeasureLong.create(
"bigtable.googleapis.com/internal/client/connectivity_error_count",
"Number of requests that failed to reach the Google datacenter. (Requests without google response headers).",
COUNT);

static final MeasureLong APPLICATION_LATENCIES =
MeasureLong.create(
"bigtable.googleapis.com/internal/client/application_latencies",
"The latency of the client application consuming available response data.",
MILLISECOND);

static final MeasureLong THROTTLING_LATENCIES =
MeasureLong.create(
"bigtable.googleapis.com/internal/client/throttling_latencies",
"The artificial latency introduced by the client to limit the number of outstanding requests. The publishing of the measurement will be delayed until the attempt trailers have been received.",
MILLISECOND);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/*
* 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 static com.google.cloud.bigtable.stats.BuiltinMeasureConstants.APPLICATION_LATENCIES;
import static com.google.cloud.bigtable.stats.BuiltinMeasureConstants.APP_PROFILE;
import static com.google.cloud.bigtable.stats.BuiltinMeasureConstants.ATTEMPT_LATENCIES;
import static com.google.cloud.bigtable.stats.BuiltinMeasureConstants.CLIENT_NAME;
import static com.google.cloud.bigtable.stats.BuiltinMeasureConstants.CLUSTER;
import static com.google.cloud.bigtable.stats.BuiltinMeasureConstants.CONNECTIVITY_ERROR_COUNT;
import static com.google.cloud.bigtable.stats.BuiltinMeasureConstants.FIRST_RESPONSE_LATENCIES;
import static com.google.cloud.bigtable.stats.BuiltinMeasureConstants.INSTANCE_ID;
import static com.google.cloud.bigtable.stats.BuiltinMeasureConstants.METHOD;
import static com.google.cloud.bigtable.stats.BuiltinMeasureConstants.OPERATION_LATENCIES;
import static com.google.cloud.bigtable.stats.BuiltinMeasureConstants.PROJECT_ID;
import static com.google.cloud.bigtable.stats.BuiltinMeasureConstants.RETRY_COUNT;
import static com.google.cloud.bigtable.stats.BuiltinMeasureConstants.SERVER_LATENCIES;
import static com.google.cloud.bigtable.stats.BuiltinMeasureConstants.STATUS;
import static com.google.cloud.bigtable.stats.BuiltinMeasureConstants.STREAMING;
import static com.google.cloud.bigtable.stats.BuiltinMeasureConstants.TABLE;
import static com.google.cloud.bigtable.stats.BuiltinMeasureConstants.THROTTLING_LATENCIES;
import static com.google.cloud.bigtable.stats.BuiltinMeasureConstants.ZONE;
import static io.opencensus.stats.Aggregation.Distribution;
import static io.opencensus.stats.Aggregation.Sum;

import com.google.common.collect.ImmutableList;
import io.opencensus.stats.Aggregation;
import io.opencensus.stats.BucketBoundaries;
import io.opencensus.stats.View;

/** Create built-in metrics views under bigtable.googleapis.com/internal/client namespace */
class BuiltinViewConstants {
private static final Aggregation AGGREGATION_WITH_MILLIS_HISTOGRAM =
Distribution.create(
BucketBoundaries.create(
ImmutableList.of(
0.0, 0.01, 0.05, 0.1, 0.3, 0.6, 0.8, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0,
13.0, 16.0, 20.0, 25.0, 30.0, 40.0, 50.0, 65.0, 80.0, 100.0, 130.0, 160.0, 200.0,
250.0, 300.0, 400.0, 500.0, 650.0, 800.0, 1000.0, 2000.0, 5000.0, 10000.0,
20000.0, 50000.0, 100000.0)));

private static final Aggregation AGGREGATION_RETRY_COUNT =
Distribution.create(
BucketBoundaries.create(
ImmutableList.of(
1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 15.0, 20.0, 30.0, 40.0, 50.0,
100.0)));

private static final Aggregation AGGREGATION_ERROR_COUNT = Sum.create();

static final View OPERATION_LATENCIES_VIEW =
View.create(
View.Name.create("bigtable.googleapis.com/internal/client/operation_latencies"),
"Total time until final operation success or failure, including retries and backoff.",
OPERATION_LATENCIES,
AGGREGATION_WITH_MILLIS_HISTOGRAM,
ImmutableList.of(
PROJECT_ID,
INSTANCE_ID,
APP_PROFILE,
METHOD,
STREAMING,
STATUS,
CLIENT_NAME,
CLUSTER,
ZONE,
TABLE));

static final View ATTEMPT_LATENCIES_VIEW =
View.create(
View.Name.create("bigtable.googleapis.com/internal/client/attempt_latencies"),
"Client observed latency per RPC attempt.",
ATTEMPT_LATENCIES,
AGGREGATION_WITH_MILLIS_HISTOGRAM,
ImmutableList.of(
PROJECT_ID,
INSTANCE_ID,
APP_PROFILE,
METHOD,
STREAMING,
STATUS,
CLIENT_NAME,
CLUSTER,
ZONE,
TABLE));

static final View RETRY_COUNT_VIEW =
View.create(
View.Name.create("bigtable.googleapis.com/internal/client/retry_count"),
"The number of additional RPCs sent after the initial attempt.",
RETRY_COUNT,
AGGREGATION_RETRY_COUNT,
ImmutableList.of(
PROJECT_ID,
INSTANCE_ID,
APP_PROFILE,
METHOD,
STATUS,
CLIENT_NAME,
CLUSTER,
ZONE,
TABLE));

static final View FIRST_RESPONSE_LATENCIES_VIEW =
View.create(
View.Name.create("bigtable.googleapis.com/internal/client/first_response_latencies"),
"Latency from operation start until the response headers were received. The publishing of the measurement will be delayed until the attempt response has been received.",
FIRST_RESPONSE_LATENCIES,
AGGREGATION_WITH_MILLIS_HISTOGRAM,
ImmutableList.of(
PROJECT_ID,
INSTANCE_ID,
APP_PROFILE,
METHOD,
STATUS,
CLIENT_NAME,
CLUSTER,
ZONE,
TABLE));

static final View SERVER_LATENCIES_VIEW =
View.create(
View.Name.create("bigtable.googleapis.com/internal/client/server_latencies"),
"The latency measured from the moment that the RPC entered the Google data center until the RPC was completed.",
SERVER_LATENCIES,
AGGREGATION_WITH_MILLIS_HISTOGRAM,
ImmutableList.of(
PROJECT_ID,
INSTANCE_ID,
APP_PROFILE,
METHOD,
STATUS,
STREAMING,
CLIENT_NAME,
CLUSTER,
ZONE,
TABLE));

static final View CONNECTIVITY_ERROR_COUNT_VIEW =
View.create(
View.Name.create("bigtable.googleapis.com/internal/client/connectivity_error_count"),
"Number of requests that failed to reach the Google datacenter. (Requests without google response headers).",
CONNECTIVITY_ERROR_COUNT,
AGGREGATION_ERROR_COUNT,
ImmutableList.of(
PROJECT_ID,
INSTANCE_ID,
APP_PROFILE,
METHOD,
STATUS,
CLIENT_NAME,
CLUSTER,
ZONE,
TABLE));

static final View APPLICATION_LATENCIES_VIEW =
View.create(
View.Name.create("bigtable.googleapis.com/internal/client/application_latencies"),
"The latency of the client application consuming available response data.",
APPLICATION_LATENCIES,
AGGREGATION_WITH_MILLIS_HISTOGRAM,
ImmutableList.of(
PROJECT_ID,
INSTANCE_ID,
APP_PROFILE,
METHOD,
STREAMING,
CLIENT_NAME,
CLUSTER,
ZONE,
TABLE));

static final View THROTTLING_LATENCIES_VIEW =
View.create(
View.Name.create("bigtable.googleapis.com/internal/client/throttling_latencies"),
"The artificial latency introduced by the client to limit the number of outstanding requests. The publishing of the measurement will be delayed until the attempt trailers have been received.",
THROTTLING_LATENCIES,
AGGREGATION_WITH_MILLIS_HISTOGRAM,
ImmutableList.of(
PROJECT_ID, INSTANCE_ID, APP_PROFILE, METHOD, CLIENT_NAME, CLUSTER, ZONE, TABLE));
}
Loading

0 comments on commit b1fc00a

Please sign in to comment.