Skip to content

Commit c2e838a

Browse files
committed
Merge pull request #47381 from meistermeier
* pr/47381: Polish "Add support for Neo4j Java Driver 6.0.0" Add support for Neo4j Java Driver 6.0.0 Closes gh-47381
2 parents 43b06ca + 6f1bcc4 commit c2e838a

File tree

13 files changed

+153
-155
lines changed

13 files changed

+153
-155
lines changed

documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/actuator/metrics.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,13 @@ management:
10421042

10431043

10441044

1045+
[[actuator.metrics.supported.neo4j]]
1046+
=== Neo4j Metrics
1047+
1048+
Auto-configuration registers a javadoc:org.neo4j.driver.observation.micrometer.MicrometerObservationProvider[] for the auto-configured javadoc:org.neo4j.driver.Driver[].
1049+
1050+
1051+
10451052
[[actuator.metrics.supported.jetty]]
10461053
=== Jetty Metrics
10471054

module/spring-boot-neo4j/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ dependencies {
3535
optional(project(":core:spring-boot-docker-compose"))
3636
optional(project(":core:spring-boot-testcontainers"))
3737
optional(project(":module:spring-boot-health"))
38+
optional(project(":module:spring-boot-micrometer-observation"))
39+
optional("org.neo4j.driver:neo4j-java-driver-observation-micrometer")
3840
optional("org.testcontainers:neo4j")
3941

4042
dockerTestImplementation(project(":core:spring-boot-test"))
@@ -48,6 +50,7 @@ dependencies {
4850
testImplementation(project(":core:spring-boot-test"))
4951
testImplementation(project(":test-support:spring-boot-test-support"))
5052
testImplementation(testFixtures(project(":core:spring-boot-testcontainers")))
53+
testImplementation("io.micrometer:micrometer-observation-test")
5154
testImplementation("io.projectreactor:reactor-test")
5255

5356
testRuntimeOnly("ch.qos.logback:logback-classic")

module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/autoconfigure/Neo4jAutoConfiguration.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.springframework.boot.neo4j.autoconfigure.Neo4jProperties.Pool;
4545
import org.springframework.boot.neo4j.autoconfigure.Neo4jProperties.Security;
4646
import org.springframework.context.annotation.Bean;
47-
import org.springframework.core.env.Environment;
4847
import org.springframework.util.Assert;
4948
import org.springframework.util.StringUtils;
5049

@@ -72,9 +71,8 @@ PropertiesNeo4jConnectionDetails neo4jConnectionDetails(Neo4jProperties properti
7271

7372
@Bean
7473
@ConditionalOnMissingBean
75-
Driver neo4jDriver(Neo4jProperties properties, Environment environment, Neo4jConnectionDetails connectionDetails,
74+
Driver neo4jDriver(Neo4jProperties properties, Neo4jConnectionDetails connectionDetails,
7675
ObjectProvider<ConfigBuilderCustomizer> configBuilderCustomizers) {
77-
7876
Config config = mapDriverConfig(properties, connectionDetails,
7977
configBuilderCustomizers.orderedStream().toList());
8078
AuthTokenManager authTokenManager = connectionDetails.getAuthTokenManager();
@@ -92,20 +90,13 @@ Config mapDriverConfig(Neo4jProperties properties, Neo4jConnectionDetails connec
9290
URI uri = connectionDetails.getUri();
9391
String scheme = (uri != null) ? uri.getScheme() : "bolt";
9492
configureDriverSettings(builder, properties, isSimpleScheme(scheme));
95-
builder.withLogging(new Neo4jSpringJclLogging());
9693
customizers.forEach((customizer) -> customizer.customize(builder));
9794
return builder.build();
9895
}
9996

10097
private boolean isSimpleScheme(String scheme) {
10198
String lowerCaseScheme = scheme.toLowerCase(Locale.ENGLISH);
102-
try {
103-
Scheme.validateScheme(lowerCaseScheme);
104-
}
105-
catch (IllegalArgumentException ex) {
106-
throw new IllegalArgumentException(String.format("'%s' is not a supported scheme.", scheme));
107-
}
108-
return lowerCaseScheme.equals("bolt") || lowerCaseScheme.equals("neo4j");
99+
return !Scheme.isSecurityScheme(lowerCaseScheme);
109100
}
110101

111102
private void configurePoolSettings(Config.ConfigBuilder builder, Pool pool) {
@@ -120,12 +111,6 @@ private void configurePoolSettings(Config.ConfigBuilder builder, Pool pool) {
120111
builder.withMaxConnectionLifetime(pool.getMaxConnectionLifetime().toMillis(), TimeUnit.MILLISECONDS);
121112
builder.withConnectionAcquisitionTimeout(pool.getConnectionAcquisitionTimeout().toMillis(),
122113
TimeUnit.MILLISECONDS);
123-
if (pool.isMetricsEnabled()) {
124-
builder.withDriverMetrics();
125-
}
126-
else {
127-
builder.withoutDriverMetrics();
128-
}
129114
}
130115

131116
private void configureDriverSettings(Config.ConfigBuilder builder, Neo4jProperties properties,

module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/autoconfigure/Neo4jProperties.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,6 @@ public void setKerberosTicket(@Nullable String kerberosTicket) {
150150

151151
public static class Pool {
152152

153-
/**
154-
* Whether to enable metrics.
155-
*/
156-
private boolean metricsEnabled = false;
157-
158153
/**
159154
* Whether to log leaked sessions.
160155
*/
@@ -223,14 +218,6 @@ public void setConnectionAcquisitionTimeout(Duration connectionAcquisitionTimeou
223218
this.connectionAcquisitionTimeout = connectionAcquisitionTimeout;
224219
}
225220

226-
public boolean isMetricsEnabled() {
227-
return this.metricsEnabled;
228-
}
229-
230-
public void setMetricsEnabled(boolean metricsEnabled) {
231-
this.metricsEnabled = metricsEnabled;
232-
}
233-
234221
}
235222

236223
public static class Security {

module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/autoconfigure/Neo4jSpringJclLogging.java

Lines changed: 0 additions & 109 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.neo4j.autoconfigure.observation;
18+
19+
import io.micrometer.observation.Observation;
20+
import io.micrometer.observation.ObservationRegistry;
21+
import org.neo4j.driver.Config.ConfigBuilder;
22+
import org.neo4j.driver.observation.micrometer.MicrometerObservationProvider;
23+
24+
import org.springframework.boot.autoconfigure.AutoConfiguration;
25+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
26+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
27+
import org.springframework.boot.neo4j.autoconfigure.ConfigBuilderCustomizer;
28+
import org.springframework.boot.neo4j.autoconfigure.Neo4jAutoConfiguration;
29+
import org.springframework.context.annotation.Bean;
30+
31+
/**
32+
* Auto-configuration for Neo4j observability.
33+
*
34+
* @author Stephane Nicoll
35+
* @since 4.0.0
36+
*/
37+
@AutoConfiguration(before = Neo4jAutoConfiguration.class,
38+
afterName = "org.springframework.boot.micrometer.observation.autoconfigure.ObservationAutoConfiguration")
39+
@ConditionalOnBean(ObservationRegistry.class)
40+
@ConditionalOnClass({ ConfigBuilder.class, MicrometerObservationProvider.class, Observation.class })
41+
public final class Neo4jObservationAutoConfiguration {
42+
43+
@Bean
44+
@ConditionalOnBean(ObservationRegistry.class)
45+
ConfigBuilderCustomizer neo4jObservationCustomizer(ObservationRegistry registry) {
46+
return (builder) -> builder.withObservationProvider(MicrometerObservationProvider.builder(registry).build());
47+
}
48+
49+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Auto-configuration for Neo4j observation.
19+
*/
20+
@NullMarked
21+
package org.springframework.boot.neo4j.autoconfigure.observation;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-neo4j/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
"description": "Whether to enable Neo4j health check.",
88
"defaultValue": true
99
},
10+
{
11+
"name": "spring.neo4j.pool.metrics-enabled",
12+
"type": "java.lang.Boolean",
13+
"deprecation": {
14+
"reason": "Use 'management.metrics.enable' to restrict certain metrics.",
15+
"level": "error"
16+
}
17+
},
1018
{
1119
"name": "spring.neo4j.uri",
1220
"defaultValue": "bolt://localhost:7687"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
org.springframework.boot.neo4j.autoconfigure.Neo4jAutoConfiguration
22
org.springframework.boot.neo4j.autoconfigure.health.Neo4jHealthContributorAutoConfiguration
3+
org.springframework.boot.neo4j.autoconfigure.observation.Neo4jObservationAutoConfiguration

module/spring-boot-neo4j/src/test/java/org/springframework/boot/neo4j/autoconfigure/Neo4jAutoConfigurationTests.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void uriWithInvalidSchemesAreDetected(String invalidScheme) {
102102
this.contextRunner.withPropertyValues("spring.neo4j.uri=" + invalidScheme + "://localhost:4711")
103103
.run((ctx) -> assertThat(ctx).hasFailed()
104104
.getFailure()
105-
.hasMessageContaining("'%s' is not a supported scheme.", invalidScheme));
105+
.hasMessageContaining("Unsupported scheme: %s", invalidScheme));
106106
}
107107

108108
@Test
@@ -217,13 +217,6 @@ void authenticationWithBothUsernameAndKerberosShouldNotBeAllowed() {
217217
.withMessage("Cannot specify both username ('Farin') and kerberos ticket ('AABBCCDDEE')");
218218
}
219219

220-
@Test
221-
void poolWithMetricsEnabled() {
222-
Neo4jProperties properties = new Neo4jProperties();
223-
properties.getPool().setMetricsEnabled(true);
224-
assertThat(mapDriverConfig(properties).isMetricsEnabled()).isTrue();
225-
}
226-
227220
@Test
228221
void poolWithLogLeakedSessions() {
229222
Neo4jProperties properties = new Neo4jProperties();
@@ -322,11 +315,6 @@ void securityWithTrustSystemCertificates() {
322315
.isEqualTo(Config.TrustStrategy.Strategy.TRUST_SYSTEM_CA_SIGNED_CERTIFICATES);
323316
}
324317

325-
@Test
326-
void driverConfigShouldBeConfiguredToUseUseSpringJclLogging() {
327-
assertThat(mapDriverConfig(new Neo4jProperties()).logging()).isInstanceOf(Neo4jSpringJclLogging.class);
328-
}
329-
330318
private Config mapDriverConfig(Neo4jProperties properties, ConfigBuilderCustomizer... customizers) {
331319
return new Neo4jAutoConfiguration().mapDriverConfig(properties,
332320
new PropertiesNeo4jConnectionDetails(properties, null), Arrays.asList(customizers));

0 commit comments

Comments
 (0)