Skip to content

Commit

Permalink
chore(dependencies): clean up spectator dependencies
Browse files Browse the repository at this point in the history
- change scope of spectator-web-spring dependencies from api to implementation since
  consumers of neither kork-stackdriver nor kork-web need it at compile time, and exclude
  transitives to keep spectator-web-spring's spring(boot) dependencies from overriding
  what we've defined elsewhere.  Add a test to ensure that the metrics endpoint from
  spectator-web-spring is really available.

- exclude transitive dependencies of spectator-ext-aws in kork-aws for a similar reason --
  to keep spectator-ext-aws' version of the aws sdk (and the aws sdk's transitives) from
  giving us newer versions of the sdk, jackson and kotlin than consumers are ready for.

This paves the way to upgrade to spectator 1.0.5 where a newer version of the spring(boot)
dependencies that spectator-web-spring brings in cause problems.

See Netflix/spectator#920 for background.
  • Loading branch information
dbyron-sf committed Nov 9, 2021
1 parent 1be4962 commit 94c406a
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 7 deletions.
8 changes: 7 additions & 1 deletion kork-aws/kork-aws.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ dependencies {
api "com.jcraft:jsch.agentproxy.jsch"
api "com.jcraft:jsch.agentproxy.connector-factory"

implementation "com.netflix.spectator:spectator-ext-aws"
implementation("com.netflix.spectator:spectator-ext-aws") {
// exclude transitives to keep spectator's version of the aws sdk from
// overriding what we specify elsewhere. It's not so much the aws sdk that
// causes problems, but its transitive dependencies -- jackson and then
// kotlin.
transitive = false
}

testImplementation "org.junit.jupiter:junit-jupiter-api"
testImplementation "org.junit.jupiter:junit-jupiter-params"
Expand Down
7 changes: 6 additions & 1 deletion kork-stackdriver/kork-stackdriver.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ dependencies {

api "io.reactivex:rxjava"
api "com.netflix.spectator:spectator-api"
api "com.netflix.spectator:spectator-web-spring"
api "com.google.apis:google-api-services-monitoring"

implementation("com.netflix.spectator:spectator-web-spring") {
// exclude transitives since this brings in a newer version of spring (boot)
// dependencies than we're compatible with (2.2.x for spring boot and 5.2.x
// for spring as of version 1.0.5 of spectator).
transitive = false
}
implementation "org.slf4j:slf4j-api"

// Force component bringing this in to already support spring boot configure.
Expand Down
15 changes: 10 additions & 5 deletions kork-web/kork-web.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ dependencies {
api "org.springframework.boot:spring-boot-starter-security"
api "org.springframework.security:spring-security-core"
api "com.netflix.spectator:spectator-api"
api("com.netflix.spectator:spectator-web-spring") {
// IMPORTANT: spectator-web-spring is Spring Boot 1.x; but is code compat with Boot 2. Exclude the transitives
transitive = false
}
api "com.fasterxml.jackson.core:jackson-annotations"
api "com.squareup.okhttp:okhttp"
api "com.squareup.okhttp3:okhttp"
api "com.squareup.retrofit:retrofit"

implementation "com.google.guava:guava"
implementation "javax.inject:javax.inject:1"

implementation("com.netflix.spectator:spectator-web-spring") {
// exclude transitives since this brings in a newer version of spring (boot)
// dependencies than we're compatible with (2.2.x for spring boot and 5.2.x
// for spring as of version 1.0.5 of spectator).
transitive = false
}
implementation "io.zipkin.brave:brave-instrumentation-okhttp3"

compileOnly "org.springframework.boot:spring-boot-starter-actuator"
Expand All @@ -42,3 +43,7 @@ dependencies {
testRuntimeOnly "cglib:cglib-nodep"
testRuntimeOnly "org.objenesis:objenesis"
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2021 Salesforce, 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.kork.web.config;

import static org.junit.jupiter.api.Assertions.assertEquals;

import com.netflix.spinnaker.config.MetricsEndpointConfiguration;
import java.net.URI;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
import org.springframework.web.util.UriComponentsBuilder;

@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = {
MetricsEndpointConfigurationTest.TestConfiguration.class,
MetricsEndpointConfiguration.class
})
@TestPropertySource(properties = {"spectator.web-endpoint.enabled = true"})
public class MetricsEndpointConfigurationTest {

@LocalServerPort int port;

@Autowired TestRestTemplate restTemplate;

@Test
public void spectatorMetricsAccess() {
URI uri =
UriComponentsBuilder.fromHttpUrl("http://localhost/spectator/metrics")
.port(port)
.build()
.toUri();

ResponseEntity<String> entity = restTemplate.getForEntity(uri, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
}

@SpringBootApplication
public static class TestConfiguration {}
}

0 comments on commit 94c406a

Please sign in to comment.