Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify logging policy in clientcore #43678

Merged
merged 8 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions sdk/clientcore/core/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@
<suppress files="io.clientcore.core.serialization.json.implementation.DefaultJsonWriter.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
<suppress files="io.clientcore.core.serialization.json.implementation.StringBuilderWriter.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
<suppress files="io.clientcore.core.serialization.json.models.JsonNumber.java" checks="com.azure.tools.checkstyle.checks.UseCaughtExceptionCauseCheck" />
<suppress files="io.clientcore.core.http.pipeline.HttpLoggingPolicy" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
</suppressions>
6 changes: 5 additions & 1 deletion sdk/clientcore/core/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
<Class name="io.clientcore.core.shared.HttpClientTests" />
<Class name="io.clientcore.core.shared.HttpClientTestsServer" />
<Class name="io.clientcore.core.util.ClientLoggerTests" />
<Class name="io.clientcore.core.util.HttpLoggingPolicyTests" />
<Class name="io.clientcore.core.util.binarydata.BinaryDataTest" />
<Class name="io.clientcore.core.util.serializer.JsonSerializerTests" />
</Or>
Expand Down Expand Up @@ -238,7 +239,10 @@
</Match>
<Match>
<Bug pattern="OS_OPEN_STREAM" />
<Class name="io.clientcore.core.serialization.json.implementation.StringBuilderWriterTests" />
<Or>
<Class name="io.clientcore.core.serialization.json.implementation.StringBuilderWriterTests" />
<Class name="io.clientcore.core.util.HttpLoggingPolicyTests" />
</Or>
</Match>
<Match>
<Bug pattern="PATH_TRAVERSAL_IN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,6 @@ public boolean equals(Object obj) {
*/
public static final HttpHeaderName CACHE_CONTROL = fromString("Cache-Control");

/**
* {@code client-request-id}
*/
public static final HttpHeaderName REQUEST_ID = fromString("Request-Id");

/**
* {@code client-request-id}
*/
public static final HttpHeaderName CLIENT_REQUEST_ID = fromString("client-request-id");

/**
* {@code traceparent}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

package io.clientcore.core.http.models;

import io.clientcore.core.http.pipeline.HttpRequestLogger;
import io.clientcore.core.http.pipeline.HttpResponseLogger;
import io.clientcore.core.util.configuration.Configuration;

import java.util.Arrays;
Expand All @@ -23,15 +21,13 @@ public final class HttpLogOptions {
private HttpLogDetailLevel logLevel;
private Set<HttpHeaderName> allowedHeaderNames;
private Set<String> allowedQueryParamNames;
private HttpRequestLogger requestLogger;
private HttpResponseLogger responseLogger;
private static final List<HttpHeaderName> DEFAULT_HEADERS_ALLOWLIST
= Arrays.asList(HttpHeaderName.TRACEPARENT, HttpHeaderName.ACCEPT, HttpHeaderName.CACHE_CONTROL,
HttpHeaderName.CONNECTION, HttpHeaderName.CONTENT_LENGTH, HttpHeaderName.CONTENT_TYPE, HttpHeaderName.DATE,
HttpHeaderName.ETAG, HttpHeaderName.EXPIRES, HttpHeaderName.IF_MATCH, HttpHeaderName.IF_MODIFIED_SINCE,
HttpHeaderName.IF_NONE_MATCH, HttpHeaderName.IF_UNMODIFIED_SINCE, HttpHeaderName.LAST_MODIFIED,
HttpHeaderName.PRAGMA, HttpHeaderName.CLIENT_REQUEST_ID, HttpHeaderName.RETRY_AFTER, HttpHeaderName.SERVER,
HttpHeaderName.TRANSFER_ENCODING, HttpHeaderName.USER_AGENT, HttpHeaderName.WWW_AUTHENTICATE);
HttpHeaderName.PRAGMA, HttpHeaderName.RETRY_AFTER, HttpHeaderName.SERVER, HttpHeaderName.TRANSFER_ENCODING,
HttpHeaderName.USER_AGENT, HttpHeaderName.WWW_AUTHENTICATE);

private static final List<String> DEFAULT_QUERY_PARAMS_ALLOWLIST = Collections.singletonList("api-version");

Expand Down Expand Up @@ -149,58 +145,6 @@ public HttpLogOptions addAllowedQueryParamName(final String allowedQueryParamNam
return this;
}

/**
* Gets the {@link HttpRequestLogger} that will be used to log HTTP requests.
*
* <p>A default {@link HttpRequestLogger} will be used if one isn't supplied.
*
* @return The {@link HttpRequestLogger} that will be used to log HTTP requests.
*/
public HttpRequestLogger getRequestLogger() {
return requestLogger;
}

/**
* Sets the {@link HttpRequestLogger} that will be used to log HTTP requests.
*
* <p>A default {@link HttpRequestLogger} will be used if one isn't supplied.
*
* @param requestLogger The {@link HttpRequestLogger} that will be used to log HTTP requests.
*
* @return The updated HttpLogOptions object.
*/
public HttpLogOptions setRequestLogger(HttpRequestLogger requestLogger) {
this.requestLogger = requestLogger;

return this;
}

/**
* Gets the {@link HttpResponseLogger} that will be used to log HTTP responses.
*
* <p>A default {@link HttpResponseLogger} will be used if one isn't supplied.
*
* @return The {@link HttpResponseLogger} that will be used to log HTTP responses.
*/
public HttpResponseLogger getResponseLogger() {
return responseLogger;
}

/**
* Sets the {@link HttpResponseLogger} that will be used to log HTTP responses.
*
* <p>A default {@link HttpResponseLogger} will be used if one isn't supplied.
*
* @param responseLogger The {@link HttpResponseLogger} that will be used to log HTTP responses.
*
* @return The updated HttpLogOptions object.
*/
public HttpLogOptions setResponseLogger(HttpResponseLogger responseLogger) {
this.responseLogger = responseLogger;

return this;
}

/**
* The level of detail to log on HTTP messages.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public class HttpRequest {
static {
HttpRequestAccessHelper.setAccessor(new HttpRequestAccessHelper.HttpRequestAccessor() {
@Override
public int getRetryCount(HttpRequest httpRequest) {
return httpRequest.getRetryCount();
public int getTryCount(HttpRequest httpRequest) {
return httpRequest.getTryCount();
}

@Override
public HttpRequest setRetryCount(HttpRequest httpRequest, int retryCount) {
return httpRequest.setRetryCount(retryCount);
public HttpRequest setTryCount(HttpRequest httpRequest, int tryCount) {
return httpRequest.setTryCount(tryCount);
}
});
}
Expand All @@ -43,7 +43,7 @@ public HttpRequest setRetryCount(HttpRequest httpRequest, int retryCount) {
private BinaryData body;
private ServerSentEventListener serverSentEventListener;
private RequestOptions requestOptions;
private int retryCount;
private int tryCount;

/**
* Create a new {@link HttpRequest} instance.
Expand Down Expand Up @@ -233,22 +233,24 @@ public HttpRequest setServerSentEventListener(ServerSentEventListener serverSent
}

/**
* Gets the number of times the request has been retried.
* Gets the number of times the request has been attempted. It's 0 during the first attempt
* and increments after attempt is made.
*
* @return The number of times the request has been retried.
* @return The number of times the request has been attempted.
*/
private int getRetryCount() {
return retryCount;
private int getTryCount() {
return tryCount;
}

/**
* Sets the number of times the request has been retried.
* Sets the number of times the request has been attempted. It's 0 during the first attempt
* and increments after attempt is made.
*
* @param retryCount The number of times the request has been retried.
* @param tryCount The number of times the request has been attempted.
* @return The updated {@link HttpRequest} object.
*/
private HttpRequest setRetryCount(int retryCount) {
this.retryCount = retryCount;
private HttpRequest setTryCount(int tryCount) {
this.tryCount = tryCount;

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
* &#47;&#47; may already be set if request is created from a client
* .setUri&#40;&quot;https:&#47;&#47;petstore.example.com&#47;pet&quot;&#41;
* .setHttpMethod&#40;HttpMethod.POST&#41;
* .setBody&#40;BinaryData.fromString&#40;requestBodyData&#41;&#41;
* .setBody&#40;requestBodyData&#41;
* .getHeaders&#40;&#41;.set&#40;HttpHeaderName.CONTENT_TYPE, &quot;application&#47;json&quot;&#41;&#41;;
* </pre>
* <!-- end io.clientcore.core.http.rest.requestoptions.postrequest -->
Expand Down
Loading
Loading