Skip to content

Commit

Permalink
API review code changes for Diagnostics Logging (#34366)
Browse files Browse the repository at this point in the history
* API review code changes

* Updated docs

* Removed unused files

* Updated server and client test secrets location
  • Loading branch information
kushagraThapar authored Apr 7, 2023
1 parent fa8841f commit b0bb3ca
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 104 deletions.
4 changes: 2 additions & 2 deletions eng/CredScanSuppression.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
{
"file": [
"eng/common/testproxy/dotnet-devcert.pfx",
"sdk/cosmos/azure-cosmos/src/test/resources/server.jks",
"sdk/cosmos/azure-cosmos/src/test/resources/client.jks",
"sdk/cosmos/azure-cosmos-tests/src/test/resources/server.jks",
"sdk/cosmos/azure-cosmos-tests/src/test/resources/client.jks",
"sdk/identity/azure-identity/src/test/resources/cert-chain.pem",
"sdk/identity/azure-identity/src/test/resources/key.pem",
"sdk/identity/azure-identity/src/test/resources/keyStore.pfx",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import com.azure.cosmos.models.TriggerOperation;
import com.azure.cosmos.models.TriggerType;
import com.azure.cosmos.rx.TestSuiteBase;
import com.azure.cosmos.test.faultinjection.CosmosFaultInjectionHelper;
import com.azure.cosmos.test.faultinjection.FaultInjectionCondition;
import com.azure.cosmos.test.faultinjection.FaultInjectionConditionBuilder;
import com.azure.cosmos.test.faultinjection.FaultInjectionConnectionType;
Expand All @@ -55,7 +54,6 @@
import com.azure.cosmos.test.implementation.faultinjection.FaultInjectorProvider;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.assertj.core.api.Assertions;
import org.mockito.Mockito;
Expand All @@ -77,9 +75,6 @@
import java.time.ZoneOffset;
import java.util.Arrays;
import java.util.Collection;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -1648,7 +1643,7 @@ private DiagnosticsProvider createAndInitializeDiagnosticsProvider(TracerUnderTe
.setPointOperationLatencyThreshold(Duration.ofDays(1))
.setNonPointOperationLatencyThreshold(Duration.ofDays(1));

thresholds.setIsFailureHandler ((statusCode, subStatusCode) -> {
thresholds.setFailureHandler((statusCode, subStatusCode) -> {
checkNotNull(statusCode, "Argument 'statusCode' must not be null." );
checkNotNull(subStatusCode, "Argument 'subStatusCode' must not be null." );
if (statusCode >= 500) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public Duration getDuration() {

/**
* A flag indicating whether the operation should be considered failed or not based on the status code handling
* rules in {@link CosmosDiagnosticsThresholds#setIsFailureHandler(BiFunction)}
* rules in {@link CosmosDiagnosticsThresholds#setFailureHandler(java.util.function.BiPredicate)}
* @return a flag indicating whether the operation should be considered failed or not
*/
public boolean isFailure() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.slf4j.LoggerFactory;

import java.time.Duration;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;

import static com.azure.cosmos.implementation.guava25.base.Preconditions.checkNotNull;

Expand Down Expand Up @@ -47,7 +47,7 @@ public final class CosmosDiagnosticsThresholds {
private float requestChargeThreshold;
private int payloadSizeInBytesThreshold;

private BiFunction<Integer, Integer, Boolean> isFailureHandler = (statusCode, subStatusCode) -> {
private BiPredicate<Integer, Integer> isFailureHandler = (statusCode, subStatusCode) -> {
checkNotNull(statusCode, "Argument 'statusCode' must not be null." );
checkNotNull(subStatusCode, "Argument 'subStatusCode' must not be null." );
if (statusCode >= 500) {
Expand Down Expand Up @@ -177,7 +177,7 @@ public CosmosDiagnosticsThresholds setPayloadSizeThreshold(int bytes) {
* tuple should be considered a failure.
* @return current CosmosDiagnosticsThresholds instance
*/
public CosmosDiagnosticsThresholds setIsFailureHandler(BiFunction<Integer, Integer, Boolean> isFailureHandler) {
public CosmosDiagnosticsThresholds setFailureHandler(BiPredicate<Integer, Integer> isFailureHandler) {
checkNotNull(nonPointOperationLatencyThreshold,
"Argument 'isFailureHandler' must not be null.");
this.isFailureHandler = isFailureHandler;
Expand All @@ -202,7 +202,7 @@ int getPayloadSizeThreshold() {

boolean isFailureCondition(int statusCode, int subStatusCode) {
try {
return this.isFailureHandler.apply(statusCode, subStatusCode);
return this.isFailureHandler.test(statusCode, subStatusCode);
} catch (Exception error) {
LOGGER.error("Execution of custom isFailureHandler failed - treating operation as failure.", error);
return false;
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit b0bb3ca

Please sign in to comment.