From b133a668eeb81a3029b749210b666ea0c65368f3 Mon Sep 17 00:00:00 2001 From: David Byron Date: Mon, 14 Dec 2020 14:34:37 -0800 Subject: [PATCH] chore(logs): allow anonymous calls to jenkins to get builds and projects (#912) to clean up warnings like: 2020-12-14 19:20:54.704 WARN 1 --- [ scheduling-1] c.n.s.okhttp.OkHttp3MetricsInterceptor : Request GET:https://jenkins./job//job/master/api/xml?exclude=/*/build/action[not(totalCount)]&tree=builds[number,url,duration,timestamp,result,building,url,fullDisplayName,actions[failCount,skipCount,totalCount]] is missing [X-SPINNAKER-USER, X-SPINNAKER-ACCOUNTS] authentication headers and will be treated as anonymous. Request from: com.netflix.spinnaker.okhttp.MetricsInterceptor.doIntercept(MetricsInterceptor.java:95) at com.netflix.spinnaker.okhttp.OkHttp3MetricsInterceptor.intercept(OkHttp3MetricsInterceptor.java:33) at com.netflix.spinnaker.igor.jenkins.service.JenkinsService.lambda$getBuilds$4(JenkinsService.java:163) at com.netflix.spinnaker.igor.jenkins.service.JenkinsService.getBuilds(JenkinsService.java:163) at com.netflix.spinnaker.igor.service.BuildOperations$getBuilds.call(Unknown Source) at com.netflix.spinnaker.igor.jenkins.JenkinsBuildMonitor.getBuilds(JenkinsBuildMonitor.groovy:174) at com.netflix.spinnaker.igor.jenkins.JenkinsBuildMonitor.processBuildsOfProject(JenkinsBuildMonitor.groovy:138) at com.netflix.spinnaker.igor.jenkins.JenkinsBuildMonitor$_generateDelta_closure2$_closure10.doCall(JenkinsBuildMonitor.groovy:113) at com.netflix.spinnaker.igor.jenkins.JenkinsBuildMonitor$_generateDelta_closure2.doCall(JenkinsBuildMonitor.groovy:113) at com.netflix.spinnaker.igor.jenkins.JenkinsBuildMonitor$_generateDelta_closure2.doCall(JenkinsBuildMonitor.groovy) at com.netflix.spinnaker.igor.jenkins.JenkinsBuildMonitor.generateDelta(JenkinsBuildMonitor.groovy:110) at com.netflix.spinnaker.igor.jenkins.JenkinsBuildMonitor.generateDelta(JenkinsBuildMonitor.groovy) at com.netflix.spinnaker.igor.polling.CommonPollingMonitor.internalPollSingle(CommonPollingMonitor.java:169) at com.netflix.spinnaker.igor.polling.CommonPollingMonitor.lambda$pollSingle$2(CommonPollingMonitor.java:141) at com.netflix.spinnaker.kork.jedis.lock.RedisLockManager.doAcquire(RedisLockManager.java:230) at com.netflix.spinnaker.kork.jedis.lock.RedisLockManager.acquire(RedisLockManager.java:268) at com.netflix.spinnaker.kork.jedis.lock.RedisLockManager.acquireLock(RedisLockManager.java:138) at com.netflix.spinnaker.igor.polling.LockService.acquire(LockService.java:48) at com.netflix.spinnaker.igor.polling.CommonPollingMonitor.pollSingle(CommonPollingMonitor.java:141) at com.netflix.spinnaker.igor.jenkins.JenkinsBuildMonitor$_poll_closure1.doCall(JenkinsBuildMonitor.groovy:96) at com.netflix.spinnaker.igor.jenkins.JenkinsBuildMonitor.poll(JenkinsBuildMonitor.groovy:95) at com.netflix.spinnaker.igor.polling.CommonPollingMonitor.lambda$onApplicationEvent$0(CommonPollingMonitor.java:94) at com.netflix.spinnaker.igor.polling.CommonPollingMonitor.lambda$onApplicationEvent$1(CommonPollingMonitor.java:91) and 2020-12-14 19:21:37.543 WARN 1 --- [ scheduling-1] c.n.s.okhttp.OkHttp3MetricsInterceptor : Request GET:https://jenkins./api/xml?tree=jobs[name,lastBuild[actions[failCount,skipCount,totalCount,urlName],duration,number,timestamp,result,building,url],jobs[name,lastBuild[actions[failCount,skipCount,totalCount,urlName],duration,number,timestamp,result,building,url],jobs[name,lastBuild[actions[failCount,skipCount,totalCount,urlName],duration,number,timestamp,result,building,url],jobs[name,lastBuild[actions[failCount,skipCount,totalCount,urlName],duration,number,timestamp,result,building,url],jobs[name,lastBuild[actions[failCount,skipCount,totalCount,urlName],duration,number,timestamp,result,building,url],jobs[name,lastBuild[actions[failCount,skipCount,totalCount,urlName],duration,number,timestamp,result,building,url],jobs[name,lastBuild[actions[failCount,skipCount,totalCount,urlName],duration,number,timestamp,result,building,url],jobs[name,lastBuild[actions[failCount,skipCount,totalCount,urlName],duration,number,timestamp,result,building,url],jobs[name,lastBuild[actions[failCount,skipCount,totalCount,urlName],duration,number,timestamp,result,building,url],jobs[name,lastBuild[actions[failCount,skipCount,totalCount,urlName],duration,number,timestamp,result,building,url]]]]]]]]]]]&exclude=/*/*/*/action[not(totalCount)] is missing [X-SPINNAKER-USER, X-SPINNAKER-ACCOUNTS] authentication headers and will be treated as anonymous. Request from: com.netflix.spinnaker.okhttp.MetricsInterceptor.doIntercept(MetricsInterceptor.java:95) at com.netflix.spinnaker.okhttp.OkHttp3MetricsInterceptor.intercept(OkHttp3MetricsInterceptor.java:33) at com.netflix.spinnaker.igor.jenkins.service.JenkinsService.lambda$getProjects$1(JenkinsService.java:115) at com.netflix.spinnaker.igor.jenkins.service.JenkinsService.getProjects(JenkinsService.java:113) at com.netflix.spinnaker.igor.jenkins.service.JenkinsService$getProjects.call(Unknown Source) at com.netflix.spinnaker.igor.jenkins.JenkinsBuildMonitor$_generateDelta_closure2.doCall(JenkinsBuildMonitor.groovy:112) at com.netflix.spinnaker.igor.jenkins.JenkinsBuildMonitor$_generateDelta_closure2.doCall(JenkinsBuildMonitor.groovy) at com.netflix.spinnaker.igor.jenkins.JenkinsBuildMonitor.generateDelta(JenkinsBuildMonitor.groovy:110) at com.netflix.spinnaker.igor.jenkins.JenkinsBuildMonitor.generateDelta(JenkinsBuildMonitor.groovy) at com.netflix.spinnaker.igor.polling.CommonPollingMonitor.internalPollSingle(CommonPollingMonitor.java:169) at com.netflix.spinnaker.igor.polling.CommonPollingMonitor.lambda$pollSingle$2(CommonPollingMonitor.java:141) at com.netflix.spinnaker.kork.jedis.lock.RedisLockManager.doAcquire(RedisLockManager.java:230) at com.netflix.spinnaker.kork.jedis.lock.RedisLockManager.acquire(RedisLockManager.java:268) at com.netflix.spinnaker.kork.jedis.lock.RedisLockManager.acquireLock(RedisLockManager.java:138) at com.netflix.spinnaker.igor.polling.LockService.acquire(LockService.java:48) at com.netflix.spinnaker.igor.polling.CommonPollingMonitor.pollSingle(CommonPollingMonitor.java:141) at com.netflix.spinnaker.igor.jenkins.JenkinsBuildMonitor$_poll_closure1.doCall(JenkinsBuildMonitor.groovy:96) at com.netflix.spinnaker.igor.jenkins.JenkinsBuildMonitor.poll(JenkinsBuildMonitor.groovy:95) at com.netflix.spinnaker.igor.polling.CommonPollingMonitor.lambda$onApplicationEvent$0(CommonPollingMonitor.java:94) at com.netflix.spinnaker.igor.polling.CommonPollingMonitor.lambda$onApplicationEvent$1(CommonPollingMonitor.java:91) there are other jenkins calls in this file that could likely benefit from the same treatment, but since I haven't experienced the struggle myself, I'm leaving those alone. Co-authored-by: David Byron --- igor-web/igor-web.gradle | 1 + .../spinnaker/igor/jenkins/service/JenkinsService.java | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/igor-web/igor-web.gradle b/igor-web/igor-web.gradle index 49c4bccca..414d72310 100644 --- a/igor-web/igor-web.gradle +++ b/igor-web/igor-web.gradle @@ -76,6 +76,7 @@ dependencies { implementation "com.netflix.spinnaker.kork:kork-config" implementation "com.netflix.spinnaker.kork:kork-cloud-config-server" implementation "com.netflix.spinnaker.kork:kork-artifacts" + implementation "com.netflix.spinnaker.kork:kork-exceptions" implementation "com.netflix.spinnaker.kork:kork-web" implementation "com.netflix.spinnaker.kork:kork-jedis" implementation "com.netflix.spinnaker.kork:kork-telemetry" diff --git a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/jenkins/service/JenkinsService.java b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/jenkins/service/JenkinsService.java index c73a62bea..6efdf2fd5 100644 --- a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/jenkins/service/JenkinsService.java +++ b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/jenkins/service/JenkinsService.java @@ -44,6 +44,7 @@ import com.netflix.spinnaker.kork.core.RetrySupport; import com.netflix.spinnaker.kork.exceptions.SpinnakerException; import com.netflix.spinnaker.kork.web.exceptions.NotFoundException; +import com.netflix.spinnaker.security.AuthenticatedRequest; import io.github.resilience4j.circuitbreaker.CircuitBreaker; import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig; import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; @@ -112,8 +113,8 @@ private String encode(String uri) { public ProjectsList getProjects() { return circuitBreaker.executeSupplier( () -> { - ProjectsList projectsList = jenkinsClient.getProjects(); - + ProjectsList projectsList = + AuthenticatedRequest.allowAnonymous(() -> jenkinsClient.getProjects()); if (projectsList == null || projectsList.getList() == null) { return new ProjectsList(); } @@ -160,7 +161,10 @@ public String getCrumb() { @Override public List getBuilds(String jobName) { - return circuitBreaker.executeSupplier(() -> jenkinsClient.getBuilds(encode(jobName)).getList()); + return circuitBreaker.executeSupplier( + () -> + AuthenticatedRequest.allowAnonymous(() -> jenkinsClient.getBuilds(encode(jobName))) + .getList()); } public BuildDependencies getDependencies(String jobName) {