Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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 @@ -119,8 +119,8 @@ public static <T> FeedResponse<T> createFeedResponseWithQueryMetrics(List<T> res
}

@Warning(value = INTERNAL_USE_ONLY_WARNING)
public static FeedResponseDiagnostics createFeedResponseDiagnostics(Map<String, QueryMetrics> queryMetricsMap) {
return new FeedResponseDiagnostics(queryMetricsMap);
public static CosmosDiagnostics createCosmosDiagnostics(Map<String, QueryMetrics> queryMetricsMap) {
return new CosmosDiagnostics(new FeedResponseDiagnostics(queryMetricsMap));
}

@Warning(value = INTERNAL_USE_ONLY_WARNING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Licensed under the MIT License.
package com.azure.cosmos;

import com.azure.cosmos.implementation.apachecommons.lang.StringUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.azure.cosmos.implementation.apachecommons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -18,11 +18,16 @@ public final class CosmosDiagnostics {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

private ClientSideRequestStatistics clientSideRequestStatistics;
private FeedResponseDiagnostics feedResponseDiagnostics;

CosmosDiagnostics() {
this.clientSideRequestStatistics = new ClientSideRequestStatistics();
}

CosmosDiagnostics(FeedResponseDiagnostics feedResponseDiagnostics) {
this.feedResponseDiagnostics = feedResponseDiagnostics;
}

ClientSideRequestStatistics clientSideRequestStatistics() {
return clientSideRequestStatistics;
}
Expand All @@ -39,6 +44,10 @@ CosmosDiagnostics clientSideRequestStatistics(ClientSideRequestStatistics client
*/
@Override
public String toString() {
if (this.feedResponseDiagnostics != null) {
return feedResponseDiagnostics.toString();
Comment thread
simplynaveen20 marked this conversation as resolved.
}

try {
return OBJECT_MAPPER.writeValueAsString(this.clientSideRequestStatistics);
} catch (JsonProcessingException e) {
Expand All @@ -48,12 +57,17 @@ public String toString() {
}

/**
* Retrieves duration related to the completion of the request
* This represents end to end duration of an operation including all the retries
* Retrieves duration related to the completion of the request.
* This represents end to end duration of an operation including all the retries.
* This is meant for point operation only, for query please use toString() to get full query diagnostics.
*
* @return request completion duration
*/
public Duration getDuration() {
if (this.feedResponseDiagnostics != null) {
return null;
}

return this.clientSideRequestStatistics.getDuration();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.azure.core.util.IterableStream;
import com.azure.core.util.paging.ContinuablePage;
import com.azure.cosmos.BridgeInternal;
import com.azure.cosmos.FeedResponseDiagnostics;
import com.azure.cosmos.CosmosDiagnostics;
import com.azure.cosmos.implementation.Constants;
import com.azure.cosmos.implementation.HttpConstants;
import com.azure.cosmos.implementation.QueryMetrics;
Expand Down Expand Up @@ -34,7 +34,7 @@ public class FeedResponse<T> implements ContinuablePage<String, T> {
final boolean nochanges;
private final ConcurrentMap<String, QueryMetrics> queryMetricsMap;
private final static String defaultPartition = "0";
private final FeedResponseDiagnostics feedResponseDiagnostics;
private final CosmosDiagnostics cosmosDiagnostics;

FeedResponse(List<T> results, Map<String, String> headers) {
this(results, headers, false, false, new ConcurrentHashMap<>());
Expand Down Expand Up @@ -63,7 +63,7 @@ private FeedResponse(
this.useEtagAsContinuation = useEtagAsContinuation;
this.nochanges = nochanges;
this.queryMetricsMap = new ConcurrentHashMap<>(queryMetricsMap);
this.feedResponseDiagnostics = BridgeInternal.createFeedResponseDiagnostics(queryMetricsMap);
this.cosmosDiagnostics = BridgeInternal.createCosmosDiagnostics(queryMetricsMap);
}

/**
Expand Down Expand Up @@ -309,8 +309,8 @@ private String getQueryMetricsString() {
*
* @return Feed response diagnostics
*/
public FeedResponseDiagnostics getFeedResponseDiagnostics() {
return this.feedResponseDiagnostics;
public CosmosDiagnostics getCosmosDiagnostics() {
return this.cosmosDiagnostics;
}

ConcurrentMap<String, QueryMetrics> queryMetrics() {
Expand Down