Skip to content

Commit 5a02631

Browse files
Address PR review round 2: token dedup, defensive props, GA queryChangeFeed
- Fix dedup: use token-based matching instead of substring contains() to avoid false positives (e.g. 2.28.0 matching 2.28.0-beta.1) - Cache properties map and use getOrDefault() for defensive fallback if properties file is missing at runtime - GA queryChangeFeed in CosmosEncryptionAsyncContainer and CosmosEncryptionContainer (core SDK API is already public) - Update changelog to include queryChangeFeed GA Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 34dfd86 commit 5a02631

5 files changed

Lines changed: 16 additions & 11 deletions

File tree

sdk/cosmos/azure-cosmos-encryption/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#### Features Added
66
* Added user agent tracking for the encryption SDK. The user agent string now includes `azure-cosmos-encryption/{version}` to enable telemetry tracking of encryption SDK adoption and version distribution. - See [PR 48505](https://github.com/Azure/azure-sdk-for-java/pull/48505)
7-
* GA'd `deleteAllItemsByPartitionKey` API in `CosmosEncryptionAsyncContainer` and `CosmosEncryptionContainer`. - See [PR 48505](https://github.com/Azure/azure-sdk-for-java/pull/48505)
7+
* GA'd `deleteAllItemsByPartitionKey` and `queryChangeFeed` APIs in `CosmosEncryptionAsyncContainer` and `CosmosEncryptionContainer`. - See [PR 48505](https://github.com/Azure/azure-sdk-for-java/pull/48505)
88

99
#### Breaking Changes
1010

sdk/cosmos/azure-cosmos-encryption/src/main/java/com/azure/cosmos/encryption/CosmosEncryptionAsyncContainer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,7 @@ public <T> CosmosPagedFlux<T> queryItemsOnEncryptedProperties(SqlQuerySpecWithEn
629629
* @return a {@link CosmosPagedFlux} containing one or several feed response pages of the obtained
630630
* items or an error.
631631
*/
632-
// TODO Make this api public once it is GA in cosmos core library
633-
<T> CosmosPagedFlux<T> queryChangeFeed(CosmosChangeFeedRequestOptions options, Class<T> classType) {
632+
public <T> CosmosPagedFlux<T> queryChangeFeed(CosmosChangeFeedRequestOptions options, Class<T> classType) {
634633
checkNotNull(options, "Argument 'options' must not be null.");
635634
checkNotNull(classType, "Argument 'classType' must not be null.");
636635

sdk/cosmos/azure-cosmos-encryption/src/main/java/com/azure/cosmos/encryption/CosmosEncryptionContainer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ public <T> CosmosPagedIterable<T> queryItemsOnEncryptedProperties(SqlQuerySpecWi
276276
* @param classType the class type.
277277
* @return a {@link CosmosPagedFlux} containing one feed response page
278278
*/
279-
// TODO Make this api public once it is GA in cosmos core library
280-
<T> CosmosPagedIterable<T> queryChangeFeed(
279+
public <T> CosmosPagedIterable<T> queryChangeFeed(
281280
CosmosChangeFeedRequestOptions options,
282281
Class<T> classType) {
283282
checkNotNull(options, "Argument 'options' must not be null.");

sdk/cosmos/azure-cosmos-encryption/src/main/java/com/azure/cosmos/encryption/implementation/Constants.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55

66
import com.azure.core.util.CoreUtils;
77

8+
import java.util.Map;
9+
810
public class Constants {
911
public static final int CACHED_ENCRYPTION_SETTING_DEFAULT_DEFAULT_TTL_IN_MINUTES = 60;
1012

1113
public static final String PROPERTIES_FILE_NAME = "azure-cosmos-encryption.properties";
12-
public static final String CURRENT_VERSION = CoreUtils.getProperties(PROPERTIES_FILE_NAME).get("version");
13-
public static final String CURRENT_NAME = CoreUtils.getProperties(PROPERTIES_FILE_NAME).get("name");
14+
private static final Map<String, String> PROPERTIES = CoreUtils.getProperties(PROPERTIES_FILE_NAME);
15+
public static final String CURRENT_NAME = PROPERTIES.getOrDefault("name", "azure-cosmos-encryption");
16+
public static final String CURRENT_VERSION = PROPERTIES.getOrDefault("version", "unknown");
1417
public static final String USER_AGENT_SUFFIX = CURRENT_NAME + "/" + CURRENT_VERSION;
1518

1619
public static final String INTENDED_COLLECTION_RID_HEADER = "x-ms-cosmos-intended-collection-rid";

sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/RxDocumentClientImpl.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,11 +1089,15 @@ public void appendUserAgentSuffix(String suffix) {
10891089
return;
10901090
}
10911091

1092-
// Check for duplicate to prevent unbounded growth when multiple encryption
1093-
// clients wrap the same CosmosAsyncClient
1092+
// Check for duplicate using token matching to prevent unbounded growth when
1093+
// multiple encryption clients wrap the same CosmosAsyncClient
10941094
String currentSuffix = this.userAgentContainer.getSuffix();
1095-
if (StringUtils.isNotEmpty(currentSuffix) && currentSuffix.contains(trimmedSuffix)) {
1096-
return;
1095+
if (StringUtils.isNotEmpty(currentSuffix)) {
1096+
for (String token : currentSuffix.split("\\s+")) {
1097+
if (trimmedSuffix.equals(token)) {
1098+
return;
1099+
}
1100+
}
10971101
}
10981102

10991103
// Preserve feature flags ("|F...") which are appended to userAgent directly

0 commit comments

Comments
 (0)