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

fix(retrofit): Use the retrofit log level bean from retrofit configuration in kork-web #894

Merged
merged 2 commits into from
Oct 16, 2020
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 @@ -42,7 +42,9 @@ class DockerRegistryConfig {
}

@Bean
ClouddriverService dockerRegistryProxyService(OkHttpClientProvider clientProvider, IgorConfigurationProperties igorConfigurationProperties) {
ClouddriverService dockerRegistryProxyService(OkHttpClientProvider clientProvider,
IgorConfigurationProperties igorConfigurationProperties,
RestAdapter.LogLevel retrofitLogLevel) {
def address = igorConfigurationProperties.services.clouddriver.baseUrl ?: 'none'
if (address == 'none') {
null
Expand All @@ -51,7 +53,7 @@ class DockerRegistryConfig {
new RestAdapter.Builder()
.setEndpoint(Endpoints.newFixedEndpoint(address))
.setClient(new Ok3Client(clientProvider.getClient(new DefaultServiceEndpoint("clouddriver", address))))
.setLogLevel(RestAdapter.LogLevel.BASIC)
.setLogLevel(retrofitLogLevel)
.setLog(new Slf4jRetrofitLogger(ClouddriverService))
.build()
.create(ClouddriverService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ import retrofit.RestAdapter
@Configuration
class EchoConfig {
@Bean
EchoService echoService(OkHttpClientProvider okHttpClientProvider, IgorConfigurationProperties igorConfigurationProperties) {
EchoService echoService(OkHttpClientProvider okHttpClientProvider,
IgorConfigurationProperties igorConfigurationProperties,
RestAdapter.LogLevel retrofitLogLevel) {
String address = igorConfigurationProperties.services.echo.baseUrl ?: 'none'

if (address == 'none') {
Expand All @@ -45,7 +47,7 @@ class EchoConfig {
new RestAdapter.Builder()
.setEndpoint(Endpoints.newFixedEndpoint(address))
.setClient(new Ok3Client(okHttpClientProvider.getClient(new DefaultServiceEndpoint("echo", address))))
.setLogLevel(RestAdapter.LogLevel.NONE)
.setLogLevel(retrofitLogLevel)
.setLog(new Slf4jRetrofitLogger(EchoService))
.build()
.create(EchoService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class JenkinsConfig {
JenkinsOkHttpClientProvider jenkinsOkHttpClientProvider,
JenkinsRetrofitRequestInterceptorProvider jenkinsRetrofitRequestInterceptorProvider,
Registry registry,
CircuitBreakerRegistry circuitBreakerRegistry) {
CircuitBreakerRegistry circuitBreakerRegistry,
RestAdapter.LogLevel retrofitLogLevel) {
log.info "creating jenkinsMasters"
Map<String, JenkinsService> jenkinsMasters = jenkinsProperties?.masters?.collectEntries { JenkinsProperties.JenkinsHost host ->
log.info "bootstrapping ${host.address} as ${host.name}"
Expand All @@ -98,6 +99,7 @@ class JenkinsConfig {
jenkinsOkHttpClientProvider.provide(host),
jenkinsRetrofitRequestInterceptorProvider.provide(host),
registry,
retrofitLogLevel,
igorConfigurationProperties.client.timeout
),
host.csrf,
Expand Down Expand Up @@ -130,6 +132,7 @@ class JenkinsConfig {
OkHttpClient client,
RequestInterceptor requestInterceptor,
Registry registry,
RestAdapter.LogLevel retrofitLogLevel,
int timeout = 30000) {

OkHttpClient.Builder clientBuilder = client.newBuilder().readTimeout(timeout, TimeUnit.MILLISECONDS)
Expand Down Expand Up @@ -185,7 +188,7 @@ class JenkinsConfig {
requestInterceptor.intercept(request)
}
})
.setLogLevel(RestAdapter.LogLevel.BASIC)
.setLogLevel(retrofitLogLevel)
.setClient(new Ok3Client(clientBuilder.build()))
.setConverter(new JacksonConverter(getObjectMapper()))
.setLog(new Slf4jRetrofitLogger(JenkinsClient))
Expand All @@ -205,9 +208,9 @@ class JenkinsConfig {
return trustManagerFactory.trustManagers
}

static JenkinsClient jenkinsClient(JenkinsProperties.JenkinsHost host, Registry registry = null, int timeout = 30000) {
static JenkinsClient jenkinsClient(JenkinsProperties.JenkinsHost host, Registry registry = null, RestAdapter.LogLevel retrofitLogLevel = RestAdapter.LogLevel.BASIC, int timeout = 30000) {
OkHttpClient client = new OkHttpClient()
jenkinsClient(host, client, RequestInterceptor.NONE, registry, timeout)
jenkinsClient(host, client, RequestInterceptor.NONE, registry, retrofitLogLevel, timeout)
}

static class TrustAllTrustManager implements X509TrustManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public PluginCache pluginCache(

@Bean
public PluginReleaseService pluginReleaseService(
OkHttpClientProvider clientProvider, IgorConfigurationProperties properties) {
OkHttpClientProvider clientProvider,
IgorConfigurationProperties properties,
RestAdapter.LogLevel retrofitLogLevel) {
String address = properties.getServices().getFront50().getBaseUrl();

Front50Service front50Service =
Expand All @@ -61,7 +63,7 @@ public PluginReleaseService pluginReleaseService(
.setClient(
new Ok3Client(
clientProvider.getClient(new DefaultServiceEndpoint("front50", address))))
.setLogLevel(RestAdapter.LogLevel.BASIC)
.setLogLevel(retrofitLogLevel)
.setLog(new Slf4jRetrofitLogger(Front50Service.class))
.build()
.create(Front50Service.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,21 @@ import javax.validation.Valid
class StashConfig {

@Bean
StashMaster stashMaster(@Valid StashProperties stashProperties) {
StashMaster stashMaster(@Valid StashProperties stashProperties,
RestAdapter.LogLevel retrofitLogLevel) {
log.info "bootstrapping ${stashProperties.baseUrl} as stash"
new StashMaster(
stashClient: stashClient(stashProperties.baseUrl, stashProperties.username, stashProperties.password),
stashClient: stashClient(stashProperties.baseUrl, stashProperties.username, stashProperties.password, retrofitLogLevel),
baseUrl: stashProperties.baseUrl)
}

StashClient stashClient(String address, String username, String password) {
StashClient stashClient(String address, String username, String password, RestAdapter.LogLevel retrofitLogLevel) {
new RestAdapter.Builder()
.setEndpoint(Endpoints.newFixedEndpoint(address))
.setRequestInterceptor(new BasicAuthRequestInterceptor(username, password))
.setClient(new OkClient())
.setConverter(new JacksonConverter())
.setLogLevel(RestAdapter.LogLevel.BASIC)
.setLogLevel(retrofitLogLevel)
.setLog(new Slf4jRetrofitLogger(StashClient))
.build()
.create(StashClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,24 @@ class WerckerConfig {
WerckerCache cache,
IgorConfigurationProperties igorConfigurationProperties,
OkHttpClientProvider clientProvider,
@Valid WerckerProperties werckerProperties) {
@Valid WerckerProperties werckerProperties,
RestAdapter.LogLevel retrofitLogLevel) {
log.debug "creating werckerMasters"
Map<String, WerckerService> werckerMasters = werckerProperties?.masters?.collectEntries { WerckerHost host ->
log.debug "bootstrapping Wercker ${host.address} as ${host.name}"
[(host.name): new WerckerService(host, cache, werckerClient(host, igorConfigurationProperties.getClient().timeout, clientProvider), host.permissions.build())]
[(host.name): new WerckerService(host, cache, werckerClient(host, igorConfigurationProperties.getClient().timeout, clientProvider, retrofitLogLevel), host.permissions.build())]
}

buildServices.addServices(werckerMasters)
werckerMasters
}

static WerckerClient werckerClient(WerckerHost host, int timeout = 30000, OkHttpClientProvider clientProvider) {
static WerckerClient werckerClient(WerckerHost host, int timeout = 30000, OkHttpClientProvider clientProvider, RestAdapter.LogLevel retrofitLogLevel) {
OkHttpClient client = clientProvider.getClient(new DefaultServiceEndpoint(host.name, host.address, false))
client = client.newBuilder().readTimeout(timeout, TimeUnit.MILLISECONDS).build()
return new RestAdapter.Builder()
.setLog(new Slf4jRetrofitLogger(WerckerService))
.setLogLevel(RestAdapter.LogLevel.BASIC)
.setLogLevel(retrofitLogLevel)
.setEndpoint(Endpoints.newFixedEndpoint(host.address))
.setClient(new Ok3Client(client))
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public TypedOutput toBody(Object object) {
@Bean
HelmAccountsService helmAccountsService(
OkHttpClientConfiguration okHttpClientConfig,
IgorConfigurationProperties igorConfigurationProperties) {
IgorConfigurationProperties igorConfigurationProperties,
RestAdapter.LogLevel retrofitLogLevel) {
String address = igorConfigurationProperties.getServices().getClouddriver().getBaseUrl();

if (StringUtils.isEmpty(address)) {
Expand All @@ -87,7 +88,7 @@ HelmAccountsService helmAccountsService(
.setEndpoint(Endpoints.newFixedEndpoint(address))
.setClient(new OkClient(okHttpClientConfig.create()))
.setConverter(new StringConverter())
.setLogLevel(RestAdapter.LogLevel.BASIC)
.setLogLevel(retrofitLogLevel)
.setLog(new Slf4jRetrofitLogger(HelmAccountsService.class))
.build()
.create(HelmAccountsService.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@
@Configuration
public class KeelConfig {

@Bean
public RestAdapter.LogLevel retrofitLogLevel(
@Value("${retrofit.log-level:BASIC}") String retrofitLogLevel) {
return RestAdapter.LogLevel.valueOf(retrofitLogLevel);
}

@Bean
public Endpoint keelEndpoint(@Value("${services.keel.base-url}") String keelBaseUrl) {
return Endpoints.newFixedEndpoint(keelBaseUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.netflix.spinnaker.igor.scm.stash.client.model.DirectoryListingRespons
import com.netflix.spinnaker.igor.scm.stash.client.model.TextLinesResponse
import com.squareup.okhttp.mockwebserver.MockResponse
import com.squareup.okhttp.mockwebserver.MockWebServer
import retrofit.RestAdapter
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Unroll
Expand Down Expand Up @@ -53,7 +54,7 @@ class StashClientSpec extends Specification {
.setHeader('Content-Type', contentType)
)
server.start()
client = new StashConfig().stashClient(server.getUrl('/').toString(), 'username', 'password')
client = new StashConfig().stashClient(server.getUrl('/').toString(), 'username', 'password', RestAdapter.LogLevel.BASIC)
}

void 'getCompareCommits'() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.netflix.spinnaker.igor.wercker.model.*
import com.squareup.okhttp.mockwebserver.MockResponse
import com.squareup.okhttp.mockwebserver.MockWebServer
import okhttp3.OkHttpClient
import retrofit.RestAdapter
import spock.lang.Shared
import spock.lang.Specification

Expand Down Expand Up @@ -100,7 +101,7 @@ class WerckerClientSpec extends Specification {
)
server.start()
def host = new WerckerHost(name: 'werckerMaster', address: server.url('/').toString())
client = new WerckerConfig().werckerClient(host, 30000, new OkHttpClientProvider([new InsecureOkHttpClientBuilderProvider(new OkHttpClient())]))
client = new WerckerConfig().werckerClient(host, 30000, new OkHttpClientProvider([new InsecureOkHttpClientBuilderProvider(new OkHttpClient())]), RestAdapter.LogLevel.BASIC)
}

String read(String fileName) {
Expand Down