-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chore(Datastore): Refactor Datastore Metric classes to inherit from Gax #12361
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 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
03aabb2
chore(datastore): Update generated stubs and native image config
lqiu96 25af60d
chore(datastore): Rename internal metrics recorder hierarchy and fix …
lqiu96 2093485
Merge branch 'main' of github.com:googleapis/google-cloud-java into d…
lqiu96 f2f1e9b
chore: Fix variable names
lqiu96 ae438e8
chore: Fix variable names
lqiu96 6c8def8
chore: Resolve merge conflicts
lqiu96 29f7ce1
chore: Remove metrics sample
lqiu96 0bf197b
chore: Update to remove the extra attributes
lqiu96 5dc702f
chore: Remove duplicate declaration of attempt and operation metrics
lqiu96 c82e1d8
test: update DatastoreImplMetricsTest to expect singular GAX metric n…
lqiu96 b36e61c
chore: Remove unnecessary transaction null check
lqiu96 dcbec55
chore: Remove stale comment
lqiu96 82e91d9
Merge branch 'main' into datastore-csm-impl-1
lqiu96 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
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
72 changes: 72 additions & 0 deletions
72
...oogle-cloud-datastore/src/main/java/com/google/cloud/datastore/samples/MetricsSample.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,72 @@ | ||
| /* | ||
| * Copyright 2026 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 | ||
| * | ||
| * http://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.datastore.samples; | ||
|
|
||
| import com.google.cloud.datastore.Datastore; | ||
| import com.google.cloud.datastore.DatastoreOptions; | ||
| import com.google.cloud.datastore.Entity; | ||
| import com.google.cloud.datastore.Key; | ||
|
|
||
| /** A simple sample to verify that Datastore metrics are being recorded and exported correctly. */ | ||
| public class MetricsSample { | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
| String projectId = System.getenv("GOOGLE_CLOUD_PROJECT"); | ||
| if (projectId == null || projectId.isEmpty()) { | ||
| System.err.println("Error: GOOGLE_CLOUD_PROJECT environment variable is not set."); | ||
| System.exit(1); | ||
| } | ||
|
|
||
| System.out.println("Starting MetricsSample for project: " + projectId); | ||
|
|
||
| // Initialize Datastore client with metrics enabled by default. | ||
| Datastore datastore = | ||
| DatastoreOptions.newBuilder().setProjectId(projectId).build().getService(); | ||
|
|
||
| System.out.println("Executing operations to generate metrics..."); | ||
|
|
||
| // 1. Basic Key Lookup | ||
| Key key = datastore.newKeyFactory().setKind("MetricsTask").newKey("sample-task"); | ||
| datastore.get(key); | ||
| System.out.println("Performed lookup."); | ||
|
|
||
| // 2. Transactional Read/Write | ||
| datastore.runInTransaction( | ||
| tx -> { | ||
| Entity entity = | ||
| Entity.newBuilder(key) | ||
| .set("description", "Recorded via MetricsSample") | ||
| .set("timestamp", System.currentTimeMillis()) | ||
| .build(); | ||
| tx.put(entity); | ||
| return null; | ||
| }); | ||
| System.out.println("Performed transaction."); | ||
|
|
||
| // 3. Batch operation | ||
| datastore.delete(key); | ||
| System.out.println("Performed delete."); | ||
|
|
||
| System.out.println("Waiting 65 seconds for metrics to be flushed to Cloud Monitoring..."); | ||
| // PeriodicMetricReader default interval is 60s. | ||
| Thread.sleep(65000); | ||
|
|
||
| System.out.println("Sample finished. Check the Cloud Monitoring dashboard for:"); | ||
| System.out.println(" - firestore.googleapis.com/internal/client/operation_latency"); | ||
| System.out.println(" - firestore.googleapis.com/internal/client/transaction_latency"); | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.