Skip to content

Commit 81ffed8

Browse files
committed
JVMCBC-1560: Add cluster UUID and name to metrics and spans (3/n)
Adding cluster uuid and name config parsing. This will only be sent from fully upgraded 7.7+ clusters. Change-Id: Ied58e6f4cd99d596d07017d0cf1d8b2d81fd554b Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/217015 Tested-by: Build Bot <[email protected]> Reviewed-by: Graham Pople <[email protected]>
1 parent 1f18f02 commit 81ffed8

File tree

6 files changed

+89
-5
lines changed

6 files changed

+89
-5
lines changed

core-io/src/main/java/com/couchbase/client/core/config/GlobalConfig.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.couchbase.client.core.deps.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
2323
import com.couchbase.client.core.deps.com.fasterxml.jackson.annotation.JsonProperty;
2424
import com.couchbase.client.core.service.ServiceType;
25+
import com.couchbase.client.core.topology.ClusterIdentifier;
2526
import com.couchbase.client.core.topology.ClusterTopology;
2627
import reactor.util.annotation.Nullable;
2728

@@ -47,6 +48,7 @@ public class GlobalConfig {
4748
private final ConfigVersion version;
4849
private final List<PortInfo> portInfos;
4950
private final Map<ServiceType, Set<ClusterCapabilities>> clusterCapabilities;
51+
private final @Nullable ClusterIdentifier clusterIdent;
5052

5153
// Null only if the GlobalConfig was created by a legacy config parser
5254
@Nullable private final ClusterTopology clusterTopology;
@@ -56,6 +58,7 @@ public GlobalConfig(ClusterTopology topology) {
5658
this.portInfos = LegacyConfigHelper.getPortInfos(topology);
5759
this.clusterCapabilities = LegacyConfigHelper.getClusterCapabilities(topology);
5860
this.clusterTopology = topology;
61+
this.clusterIdent = topology.id();
5962
}
6063

6164
@JsonCreator
@@ -70,6 +73,7 @@ public GlobalConfig(
7073
this.portInfos = enrichPortInfos(portInfos, origin);
7174
this.clusterCapabilities = AbstractBucketConfig.convertClusterCapabilities(clusterCapabilities);
7275
this.clusterTopology = null;
76+
this.clusterIdent = null;
7377
}
7478

7579
/**
@@ -126,6 +130,10 @@ public Map<ServiceType, Set<ClusterCapabilities>> clusterCapabilities() {
126130
return clusterCapabilities;
127131
}
128132

133+
@Nullable public ClusterIdentifier clusterIdent() {
134+
return clusterIdent;
135+
}
136+
129137
/**
130138
* The node/port infos for each node in the list.
131139
*/
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2024 Couchbase, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.couchbase.client.core.topology;
17+
18+
import com.couchbase.client.core.annotation.Stability;
19+
import com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode;
20+
import com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode;
21+
import reactor.util.annotation.Nullable;
22+
23+
import static com.couchbase.client.core.logging.RedactableArgument.redactMeta;
24+
25+
@Stability.Internal
26+
public class ClusterIdentifier {
27+
private final String clusterUuid;
28+
private final String clusterName;
29+
30+
ClusterIdentifier(String clusterUuid, String clusterName) {
31+
this.clusterUuid = clusterUuid;
32+
this.clusterName = clusterName;
33+
}
34+
35+
public static @Nullable ClusterIdentifier parse(ObjectNode config) {
36+
JsonNode clusterUuid = config.path("clusterUUID");
37+
JsonNode clusterName = config.path("clusterName");
38+
if (clusterUuid.isMissingNode() || clusterName.isMissingNode()) {
39+
return null;
40+
}
41+
return new ClusterIdentifier(clusterUuid.asText(), clusterName.asText());
42+
}
43+
44+
public String clusterUuid() {
45+
return clusterUuid;
46+
}
47+
48+
public String clusterName() {
49+
return clusterName;
50+
}
51+
52+
@Override
53+
public String toString() {
54+
return "ClusterIdent{" +
55+
"clusterUuid='" + clusterUuid + '\'' +
56+
", clusterName='" + redactMeta(clusterName) + '\'' +
57+
'}';
58+
}
59+
}

core-io/src/main/java/com/couchbase/client/core/topology/ClusterTopology.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ public class ClusterTopology {
3636
private final NetworkResolution network;
3737
private final Set<ClusterCapability> capabilities;
3838
private final List<HostAndServicePorts> nodes;
39+
@Nullable private final ClusterIdentifier clusterIdent;
3940

4041
public static ClusterTopology of(
4142
TopologyRevision revision,
43+
@Nullable ClusterIdentifier clusterIdent,
4244
List<HostAndServicePorts> nodes,
4345
Set<ClusterCapability> capabilities,
4446
NetworkResolution network,
@@ -52,7 +54,8 @@ public static ClusterTopology of(
5254
capabilities,
5355
network,
5456
portSelector,
55-
bucket
57+
bucket,
58+
clusterIdent
5659
);
5760
}
5861

@@ -61,7 +64,8 @@ public static ClusterTopology of(
6164
nodes,
6265
capabilities,
6366
network,
64-
portSelector
67+
portSelector,
68+
clusterIdent
6569
);
6670
}
6771

@@ -70,7 +74,8 @@ protected ClusterTopology(
7074
List<HostAndServicePorts> nodes,
7175
Set<ClusterCapability> capabilities,
7276
NetworkResolution network,
73-
PortSelector portSelector
77+
PortSelector portSelector,
78+
@Nullable ClusterIdentifier clusterIdent
7479
) {
7580
if (network.equals(NetworkResolution.AUTO)) {
7681
throw new IllegalArgumentException("Must resolve 'auto' network before creating config.");
@@ -81,6 +86,7 @@ protected ClusterTopology(
8186
this.capabilities = unmodifiableSet(newEnumSet(ClusterCapability.class, capabilities));
8287
this.network = requireNonNull(network);
8388
this.tls = requireNonNull(portSelector) == PortSelector.TLS;
89+
this.clusterIdent = clusterIdent;
8490
}
8591

8692
public TopologyRevision revision() {
@@ -114,12 +120,17 @@ public ClusterTopologyWithBucket requireBucket() {
114120
throw new NoSuchElementException("Bucket topology is absent.");
115121
}
116122

123+
@Nullable public ClusterIdentifier id() {
124+
return clusterIdent;
125+
}
126+
117127
@Override
118128
public String toString() {
119129
String bucket = this instanceof ClusterTopologyWithBucket ? this.requireBucket().bucket().toString() : "<N/A>";
120130

121131
return "ClusterTopology{" +
122132
"revision=" + revision +
133+
", clusterIdent=" + clusterIdent +
123134
", tls=" + tls +
124135
", network=" + network +
125136
", capabilities=" + capabilities +

core-io/src/main/java/com/couchbase/client/core/topology/ClusterTopologyParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ resolvedNetwork, redactSystem(it)
123123

124124
BucketTopology bucket = BucketTopology.parse(clusterConfig, nodesReadyToServiceThisBucket, memcachedHashingStrategy);
125125

126+
ClusterIdentifier clusterIdent = ClusterIdentifier.parse(clusterConfig);
127+
126128
return ClusterTopology.of(
127129
TopologyRevision.parse(clusterConfig),
130+
clusterIdent,
128131
resolvedNodes,
129132
parseCapabilities(clusterConfig),
130133
resolvedNetwork,

core-io/src/main/java/com/couchbase/client/core/topology/ClusterTopologyWithBucket.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.couchbase.client.core.annotation.Stability;
2020
import com.couchbase.client.core.env.NetworkResolution;
21+
import reactor.util.annotation.Nullable;
2122

2223
import java.util.List;
2324
import java.util.Set;
@@ -40,9 +41,10 @@ public class ClusterTopologyWithBucket extends ClusterTopology {
4041
Set<ClusterCapability> capabilities,
4142
NetworkResolution network,
4243
PortSelector portSelector,
43-
BucketTopology bucket
44+
BucketTopology bucket,
45+
@Nullable ClusterIdentifier clusterIdent
4446
) {
45-
super(revision, nodes, capabilities, network, portSelector);
47+
super(revision, nodes, capabilities, network, portSelector, clusterIdent);
4648
this.bucket = requireNonNull(bucket);
4749
}
4850

core-io/src/test/java/com/couchbase/client/core/topology/TopologyTestUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public static NodeInfo nodeInfo(String host, Map<ServiceType, Integer> ports) {
5656
public static ClusterTopology clusterTopology(List<HostAndServicePorts> nodes) {
5757
return ClusterTopology.of(
5858
new TopologyRevision(1, 1),
59+
null,
5960
nodes,
6061
emptySet(),
6162
NetworkResolution.DEFAULT,

0 commit comments

Comments
 (0)