-
Notifications
You must be signed in to change notification settings - Fork 657
fix(jenkins): fix the issue of Retrofit2EncodeCorrectionInterceptor getting added to Jenkins retrofit1 client #1324
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
Changes from 2 commits
160c8c2
48b240d
f388cc0
3ff78ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright 2025 OpsMx, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.igor | ||
|
||
import com.netflix.spectator.api.NoopRegistry | ||
import com.netflix.spectator.api.Registry | ||
import com.netflix.spinnaker.igor.config.JenkinsConfig | ||
import com.netflix.spinnaker.igor.config.client.JenkinsOkHttpClientProvider | ||
import com.netflix.spinnaker.igor.service.BuildServices | ||
import com.netflix.spinnaker.okhttp.Retrofit2EncodeCorrectionInterceptor | ||
import com.netflix.spinnaker.config.OkHttp3ClientConfiguration | ||
import com.netflix.spinnaker.config.okhttp3.RawOkHttpClientConfiguration; | ||
import com.netflix.spinnaker.igor.config.JenkinsProperties | ||
import com.netflix.spinnaker.config.OkHttpClientComponents | ||
import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry | ||
import io.github.resilience4j.circuitbreaker.internal.InMemoryCircuitBreakerRegistry | ||
import okhttp3.logging.HttpLoggingInterceptor; | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.task.TaskExecutorBuilder; | ||
dbyron-sf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.context.annotation.Bean; | ||
dbyron-sf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import retrofit.RestAdapter | ||
import spock.lang.Specification; | ||
dbyron-sf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@SpringBootTest(classes = [JenkinsConfig, RawOkHttpClientConfiguration, OkHttpClientComponents, TestConfiguration, OkHttp3ClientConfiguration], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is RawOkHttpClientConfiguration still required after the fix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not needed but it shows the real scenario of two OkHttpClient beans available but JenkinsConfig is using the right one. Let me know if you want me remove it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm...this is a tough one. Aren't we getting lucky here? RawOkHttpClientConfiguration uses @ConditionalOnMissingBean. What guarantees do we have that JenkinsConfig doesn't pick that up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed RawOkHttpClientConfiguration and converted the test to java. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great. What about
and specifically
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If RawOkHttpClientConfiguration gets processed first, I guess we end up with two OkHttpClient beans, one named okhttp3Client (from RawOkHttpClientConfiguration) and one named okHttpClient (from JenkinsConfig). And since the rest of the code in JenkinsConfig uses the variable name okHttpClient (and not okhttp3Client) perhaps things "just work." We're gonna go ahead ... |
||
properties = ["jenkins.enabled=true"]) | ||
class JenkinsClientSpec extends Specification { | ||
dbyron-sf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Autowired | ||
JenkinsOkHttpClientProvider jenkinsOkHttpClientProvider | ||
|
||
@Autowired | ||
JenkinsProperties.JenkinsHost jenkinsHost | ||
|
||
def "test if jenkins retrofit1 client has retrofit2 interceptor - Retrofit2EncodeCorrectionInterceptor"() { | ||
when: | ||
def client = jenkinsOkHttpClientProvider.provide(jenkinsHost) | ||
def interceptors = client.interceptors() | ||
|
||
then: | ||
interceptors.size() != 0 | ||
!interceptors.any { it instanceof Retrofit2EncodeCorrectionInterceptor } | ||
} | ||
} | ||
|
||
class TestConfiguration { | ||
@Bean | ||
TaskExecutorBuilder taskExecutorBuilder() { | ||
return new TaskExecutorBuilder() | ||
} | ||
|
||
@Bean | ||
JenkinsProperties.JenkinsHost jenkinsHost() { | ||
def host = new JenkinsProperties.JenkinsHost() | ||
host.address = "http://localhost:8080" | ||
host.name = "jenkins-dev" | ||
return host | ||
} | ||
|
||
@Bean | ||
JenkinsProperties jenkinsProperties(JenkinsProperties.JenkinsHost jenkinsHost) { | ||
def jenkinsProperties = new JenkinsProperties() | ||
jenkinsProperties.masters = [jenkinsHost] | ||
return jenkinsProperties | ||
} | ||
|
||
@Bean | ||
BuildServices buildServices() { | ||
def buildServices = new BuildServices() | ||
return buildServices | ||
} | ||
|
||
@Bean | ||
IgorConfigurationProperties igorConfigurationProperties() { | ||
new IgorConfigurationProperties() | ||
} | ||
|
||
@Bean | ||
Registry registry() { | ||
new NoopRegistry() | ||
} | ||
|
||
@Bean | ||
CircuitBreakerRegistry circuitBreakerRegistry() { | ||
new InMemoryCircuitBreakerRegistry() | ||
} | ||
|
||
@Bean | ||
RestAdapter.LogLevel retrofitLogLevel() { | ||
return RestAdapter.LogLevel.BASIC | ||
} | ||
|
||
@Bean | ||
HttpLoggingInterceptor.Level retrofitInterceptorLogLevel() { | ||
return HttpLoggingInterceptor.Level.BODY | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.