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

Enable configuration for http log level in Spring Cloud Azure 4.0 #24778

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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.util.Configuration;
import com.azure.data.appconfiguration.ConfigurationClientBuilder;
Expand Down Expand Up @@ -46,6 +47,11 @@ protected BiConsumer<ConfigurationClientBuilder, HttpPipeline> consumeHttpPipeli
return ConfigurationClientBuilder::pipeline;
}

@Override
protected BiConsumer<ConfigurationClientBuilder, HttpLogOptions> consumeHttpLogOptions() {
return ConfigurationClientBuilder::httpLogOptions;
}

@Override
protected ConfigurationClientBuilder createBuilderInstance() {
return new ConfigurationClientBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.util.Configuration;
import com.azure.security.keyvault.certificates.CertificateClientBuilder;
Expand Down Expand Up @@ -50,6 +51,11 @@ protected BiConsumer<CertificateClientBuilder, HttpPipeline> consumeHttpPipeline
return CertificateClientBuilder::pipeline;
}

@Override
protected BiConsumer<CertificateClientBuilder, HttpLogOptions> consumeHttpLogOptions() {
return CertificateClientBuilder::httpLogOptions;
}

@Override
protected CertificateClientBuilder createBuilderInstance() {
return new CertificateClientBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.util.Configuration;
import com.azure.security.keyvault.secrets.SecretClientBuilder;
Expand Down Expand Up @@ -49,6 +50,11 @@ protected BiConsumer<SecretClientBuilder, HttpPipeline> consumeHttpPipeline() {
return SecretClientBuilder::pipeline;
}

@Override
protected BiConsumer<SecretClientBuilder, HttpLogOptions> consumeHttpLogOptions() {
return SecretClientBuilder::httpLogOptions;
}

@Override
protected SecretClientBuilder createBuilderInstance() {
return new SecretClientBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package com.azure.spring.cloud.autoconfigure.properties;

import com.azure.spring.core.properties.client.AmqpClientProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

/**
Expand All @@ -12,10 +11,10 @@
public abstract class AbstractAzureAmqpConfigurationProperties extends AbstractAzureServiceConfigurationProperties {

@NestedConfigurationProperty
protected final AmqpClientProperties client = new AmqpClientProperties();
protected final AmqpClientConfigurationProperties client = new AmqpClientConfigurationProperties();

@Override
public AmqpClientProperties getClient() {
public AmqpClientConfigurationProperties getClient() {
return client;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

package com.azure.spring.cloud.autoconfigure.properties;

import com.azure.spring.core.properties.client.HttpClientProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

/**
Expand All @@ -12,10 +11,10 @@
public abstract class AbstractAzureHttpConfigurationProperties extends AbstractAzureServiceConfigurationProperties {

@NestedConfigurationProperty
protected final HttpClientProperties client = new HttpClientProperties();
protected final HttpClientConfigurationProperties client = new HttpClientConfigurationProperties();

@Override
public HttpClientProperties getClient() {
public HttpClientConfigurationProperties getClient() {
return client;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.autoconfigure.properties;

import com.azure.spring.core.properties.client.AmqpClientProperties;
import com.azure.spring.core.properties.client.ClientProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

/**
* This class is only for configuration-processor to find the sub-namespace of logging. The {@link LoggingProperties} is
* defined as static inner class in {@link ClientProperties} and {@link AmqpClientProperties} extends the
* {@link ClientProperties}, so when the processor process the {@link AmqpClientProperties} class it will skip the
* logging field for it's an external class.
*/
public class AmqpClientConfigurationProperties extends AmqpClientProperties {

@NestedConfigurationProperty
private final LoggingProperties logging = new LoggingProperties();

@Override
public LoggingProperties getLogging() {
return logging;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.autoconfigure.properties;

import com.azure.spring.core.properties.client.ClientProperties;
import com.azure.spring.core.properties.client.HttpClientProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

/**
* This class is only for configuration-processor to find the sub-namespace of logging. The {@link LoggingProperties} is
* defined as static inner class in {@link ClientProperties} and {@link HttpClientProperties} extends the
* {@link ClientProperties}, so when the processor process the {@link HttpClientProperties} class it will skip the
* logging field for it's an external class.
*/
public class HttpClientConfigurationProperties extends HttpClientProperties {

@NestedConfigurationProperty
private final LoggingProperties logging = new LoggingProperties();

@Override
public LoggingProperties getLogging() {
return logging;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package com.azure.spring.cloud.autoconfigure.servicebus.properties;

import com.azure.spring.cloud.autoconfigure.properties.AbstractAzureAmqpConfigurationProperties;
import com.azure.spring.core.properties.client.AmqpClientProperties;

/**
*
Expand All @@ -19,8 +18,6 @@ public abstract class AzureServiceBusCommonProperties extends AbstractAzureAmqpC

protected String connectionString;

private AmqpClientProperties client = new AmqpClientProperties();

public String getFQDN() {
return this.namespace + "." + this.domainName;
}
Expand Down Expand Up @@ -49,15 +46,6 @@ public void setConnectionString(String connectionString) {
this.connectionString = connectionString;
}

@Override
public AmqpClientProperties getClient() {
return client;
}

public void setClient(AmqpClientProperties client) {
this.client = client;
}

// TODO (xiada) we removed these properties, and not mark them as deprecated, should we mention them in the migration docs?
// public AmqpRetryOptions getRetryOptions() {
// return retryOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.util.Configuration;
import com.azure.spring.cloud.autoconfigure.storage.common.credential.StorageSharedKeyAuthenticationDescriptor;
Expand Down Expand Up @@ -67,6 +68,11 @@ protected BiConsumer<BlobServiceClientBuilder, HttpPipeline> consumeHttpPipeline
return BlobServiceClientBuilder::pipeline;
}

@Override
protected BiConsumer<BlobServiceClientBuilder, HttpLogOptions> consumeHttpLogOptions() {
return BlobServiceClientBuilder::httpLogOptions;
}

@Override
protected BiConsumer<BlobServiceClientBuilder, Configuration> consumeConfiguration() {
return BlobServiceClientBuilder::configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.util.Configuration;
import com.azure.spring.cloud.autoconfigure.storage.common.credential.StorageSharedKeyAuthenticationDescriptor;
Expand Down Expand Up @@ -54,6 +55,11 @@ protected BiConsumer<ShareServiceClientBuilder, HttpPipeline> consumeHttpPipelin
return ShareServiceClientBuilder::pipeline;
}

@Override
protected BiConsumer<ShareServiceClientBuilder, HttpLogOptions> consumeHttpLogOptions() {
return ShareServiceClientBuilder::httpLogOptions;
}

@Override
protected ShareServiceClientBuilder createBuilderInstance() {
return new ShareServiceClientBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.util.Configuration;
import com.azure.spring.cloud.autoconfigure.storage.common.credential.StorageSharedKeyAuthenticationDescriptor;
Expand Down Expand Up @@ -52,6 +53,11 @@ protected BiConsumer<QueueServiceClientBuilder, HttpPipeline> consumeHttpPipelin
return QueueServiceClientBuilder::pipeline;
}

@Override
protected BiConsumer<QueueServiceClientBuilder, HttpLogOptions> consumeHttpLogOptions() {
return QueueServiceClientBuilder::httpLogOptions;
}

@Override
protected QueueServiceClientBuilder createBuilderInstance() {
return new QueueServiceClientBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.core.converter;

import com.azure.core.http.policy.HttpLogOptions;
import com.azure.spring.core.properties.client.ClientProperties;
import org.springframework.core.convert.converter.Converter;

/**
* Converts a {@link ClientProperties.LoggingProperties} to a {@link HttpLogOptions}.
*/
public final class AzureHttpLogOptionsConverter implements Converter<ClientProperties.LoggingProperties, HttpLogOptions> {

@Override
public HttpLogOptions convert(ClientProperties.LoggingProperties logging) {
HttpLogOptions logOptions = new HttpLogOptions();

logOptions.setLogLevel(logging.getLevel());
logOptions.setPrettyPrintBody(Boolean.TRUE.equals(logging.getPrettyPrintBody()));
logOptions.setAllowedQueryParamNames(logging.getAllowedQueryParamNames());
logOptions.setAllowedHeaderNames(logging.getAllowedHeaderNames());

return logOptions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpClientProvider;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.util.Header;
import com.azure.core.util.HttpClientOptions;
import com.azure.spring.core.converter.AzureHttpLogOptionsConverter;
import com.azure.spring.core.converter.AzureHttpProxyOptionsConverter;
import com.azure.spring.core.http.DefaultHttpProvider;
import com.azure.spring.core.properties.client.ClientProperties;
Expand All @@ -33,17 +35,21 @@ public abstract class AbstractAzureHttpClientBuilderFactory<T> extends AbstractA
private final List<HttpPipelinePolicy> httpPipelinePolicies = new ArrayList<>();
private HttpPipeline httpPipeline;
private final AzureHttpProxyOptionsConverter proxyOptionsConverter = new AzureHttpProxyOptionsConverter();
private final AzureHttpLogOptionsConverter logOptionsConverter = new AzureHttpLogOptionsConverter();

protected abstract BiConsumer<T, HttpClient> consumeHttpClient();

protected abstract BiConsumer<T, HttpPipelinePolicy> consumeHttpPipelinePolicy();

protected abstract BiConsumer<T, HttpPipeline> consumeHttpPipeline();

protected abstract BiConsumer<T, HttpLogOptions> consumeHttpLogOptions();

@Override
protected void configureCore(T builder) {
super.configureCore(builder);
configureHttpClient(builder);
configureHttpLogOptions(builder);
}

protected void configureHttpClient(T builder) {
Expand Down Expand Up @@ -75,6 +81,12 @@ protected void configureHttpHeaders(T builder) {
this.httpClientOptions.setHeaders(getHeaders());
}

protected void configureHttpLogOptions(T builder) {
ClientProperties client = getAzureProperties().getClient();
HttpLogOptions logOptions = this.logOptionsConverter.convert(client.getLogging());
consumeHttpLogOptions().accept(builder, logOptions);
}

protected void configureHttpTransportProperties(T builder) {
final ClientProperties clientProperties = getAzureProperties().getClient();
if (clientProperties == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.util.Configuration;
import com.azure.identity.CredentialBuilderBase;
Expand Down Expand Up @@ -44,6 +45,11 @@ protected BiConsumer<T, HttpPipeline> consumeHttpPipeline() {
return T::httpPipeline;
}

@Override
protected BiConsumer<T, HttpLogOptions> consumeHttpLogOptions() {
return (a, b) -> { };
}

@Override
protected T createBuilderInstance() {
return builder;
Expand Down
Loading