Skip to content

Commit eaf0860

Browse files
author
Liudmila Molkova
authored
Simplify logging policy in clientcore (#43678)
* simplify HttpLoggingPolicy
1 parent 005ceb4 commit eaf0860

File tree

19 files changed

+976
-472
lines changed

19 files changed

+976
-472
lines changed

sdk/clientcore/core/checkstyle-suppressions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@
3636
<suppress files="io.clientcore.core.serialization.json.implementation.DefaultJsonWriter.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
3737
<suppress files="io.clientcore.core.serialization.json.implementation.StringBuilderWriter.java" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
3838
<suppress files="io.clientcore.core.serialization.json.models.JsonNumber.java" checks="com.azure.tools.checkstyle.checks.UseCaughtExceptionCauseCheck" />
39+
<suppress files="io.clientcore.core.http.pipeline.HttpLoggingPolicy" checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" />
3940
</suppressions>

sdk/clientcore/core/spotbugs-exclude.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
<Class name="io.clientcore.core.shared.HttpClientTests" />
124124
<Class name="io.clientcore.core.shared.HttpClientTestsServer" />
125125
<Class name="io.clientcore.core.util.ClientLoggerTests" />
126+
<Class name="io.clientcore.core.util.HttpLoggingPolicyTests" />
126127
<Class name="io.clientcore.core.util.binarydata.BinaryDataTest" />
127128
<Class name="io.clientcore.core.util.serializer.JsonSerializerTests" />
128129
</Or>
@@ -238,7 +239,10 @@
238239
</Match>
239240
<Match>
240241
<Bug pattern="OS_OPEN_STREAM" />
241-
<Class name="io.clientcore.core.serialization.json.implementation.StringBuilderWriterTests" />
242+
<Or>
243+
<Class name="io.clientcore.core.serialization.json.implementation.StringBuilderWriterTests" />
244+
<Class name="io.clientcore.core.util.HttpLoggingPolicyTests" />
245+
</Or>
242246
</Match>
243247
<Match>
244248
<Bug pattern="PATH_TRAVERSAL_IN" />

sdk/clientcore/core/src/main/java/io/clientcore/core/http/models/HttpHeaderName.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,6 @@ public boolean equals(Object obj) {
191191
*/
192192
public static final HttpHeaderName CACHE_CONTROL = fromString("Cache-Control");
193193

194-
/**
195-
* {@code client-request-id}
196-
*/
197-
public static final HttpHeaderName REQUEST_ID = fromString("Request-Id");
198-
199-
/**
200-
* {@code client-request-id}
201-
*/
202-
public static final HttpHeaderName CLIENT_REQUEST_ID = fromString("client-request-id");
203-
204194
/**
205195
* {@code traceparent}
206196
*/

sdk/clientcore/core/src/main/java/io/clientcore/core/http/models/HttpLogOptions.java

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
package io.clientcore.core.http.models;
55

6-
import io.clientcore.core.http.pipeline.HttpRequestLogger;
7-
import io.clientcore.core.http.pipeline.HttpResponseLogger;
86
import io.clientcore.core.util.configuration.Configuration;
97

108
import java.util.Arrays;
@@ -23,15 +21,13 @@ public final class HttpLogOptions {
2321
private HttpLogDetailLevel logLevel;
2422
private Set<HttpHeaderName> allowedHeaderNames;
2523
private Set<String> allowedQueryParamNames;
26-
private HttpRequestLogger requestLogger;
27-
private HttpResponseLogger responseLogger;
2824
private static final List<HttpHeaderName> DEFAULT_HEADERS_ALLOWLIST
2925
= Arrays.asList(HttpHeaderName.TRACEPARENT, HttpHeaderName.ACCEPT, HttpHeaderName.CACHE_CONTROL,
3026
HttpHeaderName.CONNECTION, HttpHeaderName.CONTENT_LENGTH, HttpHeaderName.CONTENT_TYPE, HttpHeaderName.DATE,
3127
HttpHeaderName.ETAG, HttpHeaderName.EXPIRES, HttpHeaderName.IF_MATCH, HttpHeaderName.IF_MODIFIED_SINCE,
3228
HttpHeaderName.IF_NONE_MATCH, HttpHeaderName.IF_UNMODIFIED_SINCE, HttpHeaderName.LAST_MODIFIED,
33-
HttpHeaderName.PRAGMA, HttpHeaderName.CLIENT_REQUEST_ID, HttpHeaderName.RETRY_AFTER, HttpHeaderName.SERVER,
34-
HttpHeaderName.TRANSFER_ENCODING, HttpHeaderName.USER_AGENT, HttpHeaderName.WWW_AUTHENTICATE);
29+
HttpHeaderName.PRAGMA, HttpHeaderName.RETRY_AFTER, HttpHeaderName.SERVER, HttpHeaderName.TRANSFER_ENCODING,
30+
HttpHeaderName.USER_AGENT, HttpHeaderName.WWW_AUTHENTICATE);
3531

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

@@ -149,58 +145,6 @@ public HttpLogOptions addAllowedQueryParamName(final String allowedQueryParamNam
149145
return this;
150146
}
151147

152-
/**
153-
* Gets the {@link HttpRequestLogger} that will be used to log HTTP requests.
154-
*
155-
* <p>A default {@link HttpRequestLogger} will be used if one isn't supplied.
156-
*
157-
* @return The {@link HttpRequestLogger} that will be used to log HTTP requests.
158-
*/
159-
public HttpRequestLogger getRequestLogger() {
160-
return requestLogger;
161-
}
162-
163-
/**
164-
* Sets the {@link HttpRequestLogger} that will be used to log HTTP requests.
165-
*
166-
* <p>A default {@link HttpRequestLogger} will be used if one isn't supplied.
167-
*
168-
* @param requestLogger The {@link HttpRequestLogger} that will be used to log HTTP requests.
169-
*
170-
* @return The updated HttpLogOptions object.
171-
*/
172-
public HttpLogOptions setRequestLogger(HttpRequestLogger requestLogger) {
173-
this.requestLogger = requestLogger;
174-
175-
return this;
176-
}
177-
178-
/**
179-
* Gets the {@link HttpResponseLogger} that will be used to log HTTP responses.
180-
*
181-
* <p>A default {@link HttpResponseLogger} will be used if one isn't supplied.
182-
*
183-
* @return The {@link HttpResponseLogger} that will be used to log HTTP responses.
184-
*/
185-
public HttpResponseLogger getResponseLogger() {
186-
return responseLogger;
187-
}
188-
189-
/**
190-
* Sets the {@link HttpResponseLogger} that will be used to log HTTP responses.
191-
*
192-
* <p>A default {@link HttpResponseLogger} will be used if one isn't supplied.
193-
*
194-
* @param responseLogger The {@link HttpResponseLogger} that will be used to log HTTP responses.
195-
*
196-
* @return The updated HttpLogOptions object.
197-
*/
198-
public HttpLogOptions setResponseLogger(HttpResponseLogger responseLogger) {
199-
this.responseLogger = responseLogger;
200-
201-
return this;
202-
}
203-
204148
/**
205149
* The level of detail to log on HTTP messages.
206150
*/

sdk/clientcore/core/src/main/java/io/clientcore/core/http/models/HttpRequest.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public class HttpRequest {
2626
static {
2727
HttpRequestAccessHelper.setAccessor(new HttpRequestAccessHelper.HttpRequestAccessor() {
2828
@Override
29-
public int getRetryCount(HttpRequest httpRequest) {
30-
return httpRequest.getRetryCount();
29+
public int getTryCount(HttpRequest httpRequest) {
30+
return httpRequest.getTryCount();
3131
}
3232

3333
@Override
34-
public HttpRequest setRetryCount(HttpRequest httpRequest, int retryCount) {
35-
return httpRequest.setRetryCount(retryCount);
34+
public HttpRequest setTryCount(HttpRequest httpRequest, int tryCount) {
35+
return httpRequest.setTryCount(tryCount);
3636
}
3737
});
3838
}
@@ -43,7 +43,7 @@ public HttpRequest setRetryCount(HttpRequest httpRequest, int retryCount) {
4343
private BinaryData body;
4444
private ServerSentEventListener serverSentEventListener;
4545
private RequestOptions requestOptions;
46-
private int retryCount;
46+
private int tryCount;
4747

4848
/**
4949
* Create a new {@link HttpRequest} instance.
@@ -233,22 +233,24 @@ public HttpRequest setServerSentEventListener(ServerSentEventListener serverSent
233233
}
234234

235235
/**
236-
* Gets the number of times the request has been retried.
236+
* Gets the number of times the request has been attempted. It's 0 during the first attempt
237+
* and increments after attempt is made.
237238
*
238-
* @return The number of times the request has been retried.
239+
* @return The number of times the request has been attempted.
239240
*/
240-
private int getRetryCount() {
241-
return retryCount;
241+
private int getTryCount() {
242+
return tryCount;
242243
}
243244

244245
/**
245-
* Sets the number of times the request has been retried.
246+
* Sets the number of times the request has been attempted. It's 0 during the first attempt
247+
* and increments after attempt is made.
246248
*
247-
* @param retryCount The number of times the request has been retried.
249+
* @param tryCount The number of times the request has been attempted.
248250
* @return The updated {@link HttpRequest} object.
249251
*/
250-
private HttpRequest setRetryCount(int retryCount) {
251-
this.retryCount = retryCount;
252+
private HttpRequest setTryCount(int tryCount) {
253+
this.tryCount = tryCount;
252254

253255
return this;
254256
}

sdk/clientcore/core/src/main/java/io/clientcore/core/http/models/RequestOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
* &#47;&#47; may already be set if request is created from a client
104104
* .setUri&#40;&quot;https:&#47;&#47;petstore.example.com&#47;pet&quot;&#41;
105105
* .setHttpMethod&#40;HttpMethod.POST&#41;
106-
* .setBody&#40;BinaryData.fromString&#40;requestBodyData&#41;&#41;
106+
* .setBody&#40;requestBodyData&#41;
107107
* .getHeaders&#40;&#41;.set&#40;HttpHeaderName.CONTENT_TYPE, &quot;application&#47;json&quot;&#41;&#41;;
108108
* </pre>
109109
* <!-- end io.clientcore.core.http.rest.requestoptions.postrequest -->

0 commit comments

Comments
 (0)