Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
248144d
quorumAckedLSN and currentReplicaSetSize added to diagnostics. replic…
tvaron3 Apr 22, 2024
5e2ad3c
Update sdk/cosmos/azure-cosmos/CHANGELOG.md
tvaron3 Apr 22, 2024
a5dceec
changed tests to mock the new overload primary async method
tvaron3 Apr 23, 2024
89b7b50
Merge branch 'main' into tvaron3/diagnosticsImprovements
tvaron3 Apr 23, 2024
8fa93d9
reacting to comments
tvaron3 Apr 29, 2024
285a996
reacting to comments
tvaron3 Apr 29, 2024
e399d75
reacting to comments
tvaron3 May 2, 2024
e221a20
reacting to comment
tvaron3 May 4, 2024
b7d21c0
removed set.of cause used another package
tvaron3 May 5, 2024
879779c
removed set.of cause used another package
tvaron3 May 5, 2024
6982e4d
Merge branch 'tvaron3/diagnosticsImprovements' of https://github.com/…
tvaron3 May 5, 2024
442a51b
fixed merge conflicts
tvaron3 May 28, 2024
d24f674
Reacted to comments
tvaron3 Jun 3, 2024
a48ff23
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-java in…
tvaron3 Jun 13, 2024
fcdbbb8
addressed comment and updated changelog
tvaron3 Jun 13, 2024
54c3a40
fixed regions contacted issue
tvaron3 Jul 8, 2024
46c72ae
Merge branch 'tvaron3/diagnosticsImprovements' of https://github.com/…
tvaron3 Jul 8, 2024
a77598c
updated changelog
tvaron3 Jul 8, 2024
758e0ca
Update sdk/cosmos/azure-cosmos/CHANGELOG.md
tvaron3 Jul 8, 2024
0407a8c
Update sdk/cosmos/azure-cosmos/CHANGELOG.md
FabianMeiswinkel Jul 8, 2024
877e652
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-java in…
tvaron3 Jul 9, 2024
c7acc04
Merge branch 'tvaron3/diagnosticsImprovements' of https://github.com/…
tvaron3 Jul 9, 2024
76a0b9f
stabilizing live tests
tvaron3 Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@
import java.util.EnumSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -146,7 +144,7 @@ public void beforeTest(
AsyncDocumentClient asyncDocumentClient = ReflectionUtils.getAsyncDocumentClient(this.client.asyncClient());
RxDocumentClientImpl rxDocumentClient = (RxDocumentClientImpl) asyncDocumentClient;

Set<String> writeRegions = this.getAvailableRegionNames(rxDocumentClient, true);
List<String> writeRegions = this.getAvailableWriteRegionNames(rxDocumentClient);
assertThat(writeRegions).isNotNull().isNotEmpty();
this.preferredRegion = writeRegions.iterator().next();

Expand Down Expand Up @@ -1511,7 +1509,7 @@ private void validateMetrics(Tag expectedOperationTag, Tag expectedRequestTag, i
this.assertMetrics(
"cosmos.client.op.regionsContacted",
true,
Tag.of(TagName.RegionName.toString(), this.preferredRegion));
Tag.of(TagName.RegionName.toString(), this.preferredRegion.toLowerCase(Locale.ROOT)));
}

if (this.getEffectiveMetricCategories().contains(MetricCategory.RequestSummary)) {
Expand All @@ -1531,7 +1529,7 @@ private void validateMetrics(Tag expectedOperationTag, Tag expectedRequestTag, i
this.assertMetrics(
"cosmos.client.req.rntbd.latency",
true,
Tag.of(TagName.RegionName.toString(), this.preferredRegion));
Tag.of(TagName.RegionName.toString(), this.preferredRegion.toLowerCase(Locale.ROOT)));
this.assertMetrics("cosmos.client.req.rntbd.backendLatency", true, expectedRequestTag);
this.assertMetrics("cosmos.client.req.rntbd.requests", true, expectedRequestTag);
Meter reportedRntbdRequestCharge =
Expand All @@ -1548,7 +1546,7 @@ private void validateMetrics(Tag expectedOperationTag, Tag expectedRequestTag, i
this.assertMetrics(
"cosmos.client.req.gw.latency",
true,
Tag.of(TagName.RegionName.toString(), this.preferredRegion));
Tag.of(TagName.RegionName.toString(), this.preferredRegion.toLowerCase(Locale.ROOT)));
}
this.assertMetrics("cosmos.client.req.gw.backendLatency", false, expectedRequestTag);
this.assertMetrics("cosmos.client.req.gw.requests", true, expectedRequestTag);
Expand Down Expand Up @@ -1654,7 +1652,7 @@ private Meter assertMetrics(String prefix, boolean expectedToFind, Tag withTag)
}
}

private Set<String> getAvailableRegionNames(RxDocumentClientImpl rxDocumentClient, boolean isWriteRegion) {
private List<String> getAvailableWriteRegionNames(RxDocumentClientImpl rxDocumentClient) {
try {
GlobalEndpointManager globalEndpointManager = ReflectionUtils.getGlobalEndpointManager(rxDocumentClient);
LocationCache locationCache = ReflectionUtils.getLocationCache(globalEndpointManager);
Expand All @@ -1665,22 +1663,13 @@ private Set<String> getAvailableRegionNames(RxDocumentClientImpl rxDocumentClien

Class<?> DatabaseAccountLocationsInfoClass = Class.forName("com.azure.cosmos.implementation.routing" +
".LocationCache$DatabaseAccountLocationsInfo");
Field availableWriteLocations = DatabaseAccountLocationsInfoClass.getDeclaredField(
"availableWriteLocations");
availableWriteLocations.setAccessible(true);
@SuppressWarnings("unchecked")
List<String> list = (List<String>) availableWriteLocations.get(locationInfo);
return list;

if (isWriteRegion) {
Field availableWriteEndpointByLocation = DatabaseAccountLocationsInfoClass.getDeclaredField(
"availableWriteEndpointByLocation");
availableWriteEndpointByLocation.setAccessible(true);
@SuppressWarnings("unchecked")
Map<String, URI> map = (Map<String, URI>) availableWriteEndpointByLocation.get(locationInfo);
return map.keySet();
} else {
Field availableReadEndpointByLocation = DatabaseAccountLocationsInfoClass.getDeclaredField(
"availableReadEndpointByLocation");
availableReadEndpointByLocation.setAccessible(true);
@SuppressWarnings("unchecked")
Map<String, URI> map = (Map<String, URI>) availableReadEndpointByLocation.get(locationInfo);
return map.keySet();
}
} catch (Exception error) {
fail(error.toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1725,13 +1725,13 @@ private void validateRegionContacted(CosmosDiagnostics cosmosDiagnostics, Cosmos

Class<?> DatabaseAccountLocationsInfoClass = Class.forName("com.azure.cosmos.implementation.routing" +
".LocationCache$DatabaseAccountLocationsInfo");
Field availableWriteEndpointByLocation = DatabaseAccountLocationsInfoClass.getDeclaredField(
"availableWriteEndpointByLocation");
availableWriteEndpointByLocation.setAccessible(true);
Field availableWriteLocations = DatabaseAccountLocationsInfoClass.getDeclaredField(
"availableWriteLocations");
availableWriteLocations.setAccessible(true);

@SuppressWarnings("unchecked")
Map<String, URI> map = (Map<String, URI>) availableWriteEndpointByLocation.get(locationInfo);
String regionName = map.keySet().iterator().next();
List<String> list = (List<String>) availableWriteLocations.get(locationInfo);
String regionName = list.get(0);
assertThat(cosmosDiagnostics.getContactedRegionNames().size()).isEqualTo(1);
assertThat(cosmosDiagnostics.getContactedRegionNames().iterator().next()).isEqualTo(regionName.toLowerCase());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@
import reactor.core.publisher.Mono;

import java.lang.reflect.Field;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -354,7 +352,7 @@ public void sessionNotAvailableRetryWithoutPreferredList(OperationType operation
} catch (CosmosException ex) {
assertThat(ex.getStatusCode()).isEqualTo(HttpConstants.StatusCodes.NOTFOUND);
assertThat(ex.getDiagnostics().getContactedRegionNames().size()).isEqualTo(1);
String regionName = getAvailableRegionNames(rxDocumentClient, true).iterator().next();
String regionName = getRegionNames(rxDocumentClient).iterator().next();
assertThat(ex.getDiagnostics().getContactedRegionNames().iterator().next()).isEqualTo(regionName.toLowerCase());
}

Expand Down Expand Up @@ -409,7 +407,7 @@ private Map<String, String> getRegionMap(DatabaseAccount databaseAccount, boolea
return regionMap;
}

private Set<String> getAvailableRegionNames(RxDocumentClientImpl rxDocumentClient, boolean isWriteRegion) throws Exception {
private List<String> getRegionNames(RxDocumentClientImpl rxDocumentClient) throws Exception {
GlobalEndpointManager globalEndpointManager = ReflectionUtils.getGlobalEndpointManager(rxDocumentClient);
LocationCache locationCache = ReflectionUtils.getLocationCache(globalEndpointManager);

Expand All @@ -420,21 +418,12 @@ private Set<String> getAvailableRegionNames(RxDocumentClientImpl rxDocumentClien
Class<?> DatabaseAccountLocationsInfoClass = Class.forName("com.azure.cosmos.implementation.routing" +
".LocationCache$DatabaseAccountLocationsInfo");

if (isWriteRegion) {
Field availableWriteEndpointByLocation = DatabaseAccountLocationsInfoClass.getDeclaredField(
"availableWriteEndpointByLocation");
availableWriteEndpointByLocation.setAccessible(true);
@SuppressWarnings("unchecked")
Map<String, URI> map = (Map<String, URI>) availableWriteEndpointByLocation.get(locationInfo);
return map.keySet();
} else {
Field availableReadEndpointByLocation = DatabaseAccountLocationsInfoClass.getDeclaredField(
"availableReadEndpointByLocation");
availableReadEndpointByLocation.setAccessible(true);
@SuppressWarnings("unchecked")
Map<String, URI> map = (Map<String, URI>) availableReadEndpointByLocation.get(locationInfo);
return map.keySet();
}
Field availableWriteEndpointByLocation = DatabaseAccountLocationsInfoClass.getDeclaredField(
"availableWriteLocations");
availableWriteEndpointByLocation.setAccessible(true);
@SuppressWarnings("unchecked")
List<String> list = (List<String>) availableWriteEndpointByLocation.get(locationInfo);
return list;
}

private class RntbdTransportClientTest extends TransportClient {
Expand Down
1 change: 1 addition & 0 deletions sdk/cosmos/azure-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#### Breaking Changes

#### Bugs Fixed
* Fixed an issue where `contactedRegions` shows the wrong region in a multi region account if no preferred regions are specified. - See [PR 41045](https://github.com/Azure/azure-sdk-for-java/pull/41045)

#### Other Changes
* Added metrics and tracing for ReadMany operations. - See [PR 41042](https://github.com/Azure/azure-sdk-for-java/pull/41042)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public String getRegionName(URI locationEndpoint, com.azure.cosmos.implementatio
}

//If preferred list is not set, locationEndpoint will be default endpoint, so return the hub region
return this.locationInfo.availableWriteEndpointByLocation.keySet().iterator().next();
return this.locationInfo.availableWriteLocations.get(0).toLowerCase(Locale.ROOT);
}

private boolean areEqual(URI url1, URI url2) {
Expand Down