Skip to content

Commit a297df5

Browse files
Fixed index metrics serialization and tests (Azure#37437)
1 parent 8bae891 commit a297df5

File tree

3 files changed

+13
-25
lines changed

3 files changed

+13
-25
lines changed

sdk/cosmos/azure-cosmos-tests/src/test/java/com/azure/cosmos/CosmosDiagnosticsTest.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.azure.cosmos.implementation.FeedResponseDiagnostics;
1212
import com.azure.cosmos.implementation.GlobalEndpointManager;
1313
import com.azure.cosmos.implementation.HttpConstants;
14-
import com.azure.cosmos.implementation.IndexUtilizationInfo;
1514
import com.azure.cosmos.implementation.InternalObjectNode;
1615
import com.azure.cosmos.implementation.LifeCycleUtils;
1716
import com.azure.cosmos.implementation.OperationCancelledException;
@@ -535,11 +534,11 @@ public void queryMetricsWithIndexMetrics() {
535534
while (iterator.hasNext()) {
536535
FeedResponse<InternalObjectNode> feedResponse = iterator.next();
537536
queryDiagnostics = feedResponse.getCosmosDiagnostics().toString();
538-
logger.info("This is query diagnostics {}", queryDiagnostics);
539-
if (feedResponse.getResponseHeaders().containsKey(HttpConstants.HttpHeaders.INDEX_UTILIZATION)) {
540-
assertThat(feedResponse.getResponseHeaders().get(HttpConstants.HttpHeaders.INDEX_UTILIZATION)).isNotNull();
541-
assertThat(createFromJSONString(Utils.decodeBase64String(feedResponse.getResponseHeaders().get(HttpConstants.HttpHeaders.INDEX_UTILIZATION))).getUtilizedSingleIndexes()).isNotNull();
542-
}
537+
assertThat(queryDiagnostics).contains("\"indexUtilizationInfo\"");
538+
assertThat(queryDiagnostics).contains("\"UtilizedSingleIndexes\"");
539+
assertThat(queryDiagnostics).contains("\"PotentialSingleIndexes\"");
540+
assertThat(queryDiagnostics).contains("\"UtilizedCompositeIndexes\"");
541+
assertThat(queryDiagnostics).contains("\"PotentialCompositeIndexes\"");
543542
}
544543
}
545544
}
@@ -1556,17 +1555,6 @@ private HttpClient httpClient(boolean fakeProxy) {
15561555
return HttpClient.createFixed(httpClientConfig);
15571556
}
15581557

1559-
private IndexUtilizationInfo createFromJSONString(String jsonString) {
1560-
ObjectMapper indexUtilizationInfoObjectMapper = new ObjectMapper();
1561-
IndexUtilizationInfo indexUtilizationInfo = null;
1562-
try {
1563-
indexUtilizationInfo = indexUtilizationInfoObjectMapper.readValue(jsonString, IndexUtilizationInfo.class);
1564-
} catch (JsonProcessingException e) {
1565-
logger.error("Json not correctly formed ", e);
1566-
}
1567-
return indexUtilizationInfo;
1568-
}
1569-
15701558
private void validateRegionContacted(CosmosDiagnostics cosmosDiagnostics, CosmosAsyncClient cosmosAsyncClient) throws Exception {
15711559
RxDocumentClientImpl rxDocumentClient =
15721560
(RxDocumentClientImpl) ReflectionUtils.getAsyncDocumentClient(cosmosAsyncClient);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
public class CompositeIndexUtilizationEntity {
1111

12-
@JsonProperty(value = "IndexSpecs", access = JsonProperty.Access.WRITE_ONLY)
12+
@JsonProperty(value = "IndexSpecs", access = JsonProperty.Access.READ_WRITE)
1313
private List<String> indexDocumentExpressions;
14-
@JsonProperty(value = "IndexPreciseSet", access = JsonProperty.Access.WRITE_ONLY)
14+
@JsonProperty(value = "IndexPreciseSet", access = JsonProperty.Access.READ_WRITE)
1515
private boolean indexPlanFullFidelity;
16-
@JsonProperty(value = "IndexImpactScore", access = JsonProperty.Access.WRITE_ONLY)
16+
@JsonProperty(value = "IndexImpactScore", access = JsonProperty.Access.READ_WRITE)
1717
private String indexImpactScore;
1818

1919
CompositeIndexUtilizationEntity() {}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
public class SingleIndexUtilizationEntity {
99

10-
@JsonProperty(value = "FilterExpression", access = JsonProperty.Access.WRITE_ONLY)
10+
@JsonProperty(value = "FilterExpression", access = JsonProperty.Access.READ_WRITE)
1111
private String filterExpression;
12-
@JsonProperty(value = "IndexSpec", access = JsonProperty.Access.WRITE_ONLY)
12+
@JsonProperty(value = "IndexSpec", access = JsonProperty.Access.READ_WRITE)
1313
private String indexDocumentExpression;
14-
@JsonProperty(value = "FilterPreciseSet", access = JsonProperty.Access.WRITE_ONLY)
14+
@JsonProperty(value = "FilterPreciseSet", access = JsonProperty.Access.READ_WRITE)
1515
private boolean filterExpressionPrecision;
16-
@JsonProperty(value = "IndexPreciseSet", access = JsonProperty.Access.WRITE_ONLY)
16+
@JsonProperty(value = "IndexPreciseSet", access = JsonProperty.Access.READ_WRITE)
1717
private boolean indexPlanFullFidelity;
18-
@JsonProperty(value = "IndexImpactScore", access = JsonProperty.Access.WRITE_ONLY)
18+
@JsonProperty(value = "IndexImpactScore", access = JsonProperty.Access.READ_WRITE)
1919
private String indexImpactScore;
2020

2121
SingleIndexUtilizationEntity() {}

0 commit comments

Comments
 (0)