Skip to content

Commit 3657027

Browse files
committed
fix: move mismatch log to client creation path, avoid log spam
Address review feedback: - Move project mismatch log inside the new-client branch so it fires at most once per DatabaseId, not on every getDatabaseClient - equals/hashCode: SpannerOptions inherits from ServiceOptions and does not override these methods; monitoringHost follows the same pattern
1 parent 22141e7 commit 3657027

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

  • java-spanner/google-cloud-spanner/src/main/java/com/google/cloud/spanner

java-spanner/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerImpl.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -296,19 +296,6 @@ public InstanceAdminClient getInstanceAdminClient() {
296296
public DatabaseClient getDatabaseClient(DatabaseId db) {
297297
synchronized (this) {
298298
checkClosed();
299-
SpannerOptions opts = getOptions();
300-
String metricsProject = opts.resolveMetricsProjectId();
301-
if (opts.isEnableBuiltInMetrics()
302-
&& metricsProject != null
303-
&& !metricsProject.equals(db.getInstanceId().getProject())) {
304-
logger.log(
305-
Level.WARNING,
306-
"DatabaseId project ''{0}'' differs from the project used for client-side metrics"
307-
+ " export ''{1}''. Metrics will be exported to ''{1}'', which may cause"
308-
+ " permission errors. Set SpannerOptions.Builder.setMetricsProjectId(\"{0}\")"
309-
+ " to fix this.",
310-
new Object[] {db.getInstanceId().getProject(), metricsProject});
311-
}
312299
String clientId = null;
313300
if (dbClients.containsKey(db) && !dbClients.get(db).isValid()) {
314301
// Close the invalidated client and remove it.
@@ -319,6 +306,17 @@ public DatabaseClient getDatabaseClient(DatabaseId db) {
319306
if (dbClients.containsKey(db)) {
320307
return dbClients.get(db);
321308
} else {
309+
SpannerOptions opts = getOptions();
310+
String metricsProject = opts.resolveMetricsProjectId();
311+
if (opts.isEnableBuiltInMetrics()
312+
&& metricsProject != null
313+
&& !metricsProject.equals(db.getInstanceId().getProject())) {
314+
logger.log(
315+
Level.INFO,
316+
"Built-in metrics project ''{0}'' differs from DatabaseId project ''{1}''."
317+
+ " Use setMetricsProjectId() to override if needed.",
318+
new Object[] {metricsProject, db.getInstanceId().getProject()});
319+
}
322320
if (clientId == null) {
323321
clientId = nextDatabaseClientId(db);
324322
}

0 commit comments

Comments
 (0)