Skip to content

Commit 786cf3c

Browse files
committed
Polishing.
Add request tracker integration to capture completion/error responses. Add reactive integration. Properly observe prepare requests. Simplify documentation. See #1321 Original pull request: #1322
1 parent a42bc73 commit 786cf3c

27 files changed

+1179
-788
lines changed

spring-data-cassandra-distribution/pom.xml

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,48 +42,30 @@
4242
<artifactId>exec-maven-plugin</artifactId>
4343
<executions>
4444
<execution>
45-
<id>generate-metrics-metadata</id>
45+
<id>generate-docs</id>
4646
<phase>generate-resources</phase>
4747
<goals>
4848
<goal>java</goal>
4949
</goals>
5050
<configuration>
51-
<mainClass>io.micrometer.docs.metrics.DocsFromSources</mainClass>
52-
</configuration>
53-
</execution>
54-
<execution>
55-
<id>generate-tracing-metadata</id>
56-
<phase>generate-resources</phase>
57-
<goals>
58-
<goal>java</goal>
59-
</goals>
60-
<configuration>
61-
<mainClass>io.micrometer.docs.spans.DocsFromSources</mainClass>
51+
<mainClass>io.micrometer.docs.DocsGeneratorCommand</mainClass>
52+
<includePluginDependencies>true</includePluginDependencies>
53+
<arguments>
54+
<argument>${micrometer-docs-generator.inputPath}</argument>
55+
<argument>${micrometer-docs-generator.inclusionPattern}</argument>
56+
<argument>${micrometer-docs-generator.outputPath}</argument>
57+
</arguments>
6258
</configuration>
6359
</execution>
6460
</executions>
6561
<dependencies>
6662
<dependency>
6763
<groupId>io.micrometer</groupId>
68-
<artifactId>micrometer-docs-generator-spans</artifactId>
69-
<version>${micrometer-docs-generator}</version>
70-
<type>jar</type>
71-
</dependency>
72-
<dependency>
73-
<groupId>io.micrometer</groupId>
74-
<artifactId>micrometer-docs-generator-metrics</artifactId>
64+
<artifactId>micrometer-docs-generator</artifactId>
7565
<version>${micrometer-docs-generator}</version>
7666
<type>jar</type>
7767
</dependency>
7868
</dependencies>
79-
<configuration>
80-
<includePluginDependencies>true</includePluginDependencies>
81-
<arguments>
82-
<argument>${micrometer-docs-generator.inputPath}</argument>
83-
<argument>${micrometer-docs-generator.inclusionPattern}</argument>
84-
<argument>${micrometer-docs-generator.outputPath}</argument>
85-
</arguments>
86-
</configuration>
8769
</plugin>
8870
<plugin>
8971
<groupId>org.asciidoctor</groupId>

spring-data-cassandra/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<artifactId>micrometer-observation</artifactId>
7878
<optional>true</optional>
7979
</dependency>
80+
8081
<dependency>
8182
<groupId>io.micrometer</groupId>
8283
<artifactId>micrometer-tracing</artifactId>
@@ -87,6 +88,12 @@
8788
<groupId>io.micrometer</groupId>
8889
<artifactId>micrometer-test</artifactId>
8990
<scope>test</scope>
91+
<exclusions>
92+
<exclusion>
93+
<groupId>com.github.tomakehurst</groupId>
94+
<artifactId>wiremock-jre8-standalone</artifactId>
95+
</exclusion>
96+
</exclusions>
9097
</dependency>
9198

9299
<dependency>

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/AbstractSessionConfiguration.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,14 @@ protected Resource getDriverConfigurationResource() {
256256
}
257257

258258
/**
259-
* Returns the list of CQL scripts to be run on startup after {@link #getKeyspaceCreations() Keyspace creations}
260-
* and after initialization of the {@literal System} Keyspace.
259+
* Returns the list of CQL scripts to be run on startup after {@link #getKeyspaceCreations() Keyspace creations} and
260+
* after initialization of the {@literal System} Keyspace. return super.getSessionBuilderConfigurer();
261261
*
262-
* @return the list of CQL scripts to be run on startup; may be {@link Collections#emptyList() empty}
263-
* but never {@literal null}.
262+
* @return the list of CQL scripts to be run on startup; may be {@link Collections#emptyList() empty} but never
263+
* {@literal null}.
264264
* @deprecated since 3.0; Declare a
265-
* {@link org.springframework.data.cassandra.core.cql.session.init.SessionFactoryInitializer} bean instead.
265+
* {@link org.springframework.data.cassandra.core.cql.session.init.SessionFactoryInitializer} bean
266+
* instead.
266267
*/
267268
@Deprecated
268269
protected List<String> getStartupScripts() {

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/observability/CassandraObservation.java

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2022 the original author or authors.
2+
* Copyright 2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,14 +17,15 @@
1717

1818
import io.micrometer.common.docs.KeyName;
1919
import io.micrometer.observation.docs.ObservationDocumentation;
20+
import io.micrometer.tracing.docs.EventValue;
2021

2122
/**
2223
* Cassandra-based implementation of {@link ObservationDocumentation}.
2324
*
2425
* @author Mark Paluch
2526
* @author Marcin Grzejszczak
2627
* @author Greg Turnquist
27-
* @since 4.0.0
28+
* @since 4.0
2829
*/
2930
enum CassandraObservation implements ObservationDocumentation {
3031

@@ -101,6 +102,20 @@ public String asString() {
101102
}
102103
},
103104

105+
}
106+
107+
enum HighCardinalityKeyNames implements KeyName {
108+
109+
/**
110+
* A key-value containing Cassandra CQL.
111+
*/
112+
CQL_TAG {
113+
@Override
114+
public String asString() {
115+
return "spring.data.cassandra.cql";
116+
}
117+
},
118+
104119
/**
105120
* A tag containing error that occurred for the given node.
106121
*/
@@ -110,18 +125,30 @@ public String asString() {
110125
return "spring.data.cassandra.node[%s].error";
111126
}
112127
}
128+
113129
}
114130

115-
enum HighCardinalityKeyNames implements KeyName {
131+
enum Events implements EventValue {
116132

117133
/**
118-
* A key-value containing Cassandra CQL.
134+
* Set whenever an error occurred for the given node.
119135
*/
120-
CQL_TAG {
136+
NODE_ERROR {
121137
@Override
122-
public String asString() {
123-
return "spring.data.cassandra.cql";
138+
public String getValue() {
139+
return "cassandra.node.error";
140+
}
141+
},
142+
143+
/**
144+
* Set when a success occurred for the session processing.
145+
*/
146+
NODE_SUCCESS {
147+
@Override
148+
public String getValue() {
149+
return "cassandra.node.success";
124150
}
125151
}
152+
126153
}
127154
}

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/observability/CassandraObservationConfiguration.java

Lines changed: 0 additions & 52 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2022 the original author or authors.
2+
* Copyright 2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,43 +15,60 @@
1515
*/
1616
package org.springframework.data.cassandra.observability;
1717

18-
import io.micrometer.observation.Observation;
19-
20-
import org.springframework.lang.Nullable;
21-
2218
import com.datastax.oss.driver.api.core.CqlSession;
2319
import com.datastax.oss.driver.api.core.cql.Statement;
2420

21+
import io.micrometer.observation.Observation;
22+
import io.micrometer.observation.transport.Kind;
23+
import io.micrometer.observation.transport.SenderContext;
24+
2525
/**
2626
* A {@link Observation.Context} for {@link CqlSession}.
2727
*
2828
* @author Greg Turnquist
29-
* @since 4.0.0
29+
* @author Mark Paluch
30+
* @since 4.0
3031
*/
31-
public class CqlSessionContext extends Observation.Context {
32+
public class CassandraObservationContext extends SenderContext<Object> {
33+
34+
private final Statement<?> statement;
3235

33-
private final @Nullable Statement<?> statement;
36+
private final boolean prepare;
3437
private final String methodName;
35-
private final @Nullable CqlSession delegateSession;
38+
private final String sessionName;
39+
private final String keyspaceName;
3640

37-
public CqlSessionContext(@Nullable Statement<?> statement, String methodName, @Nullable CqlSession delegateSession) {
41+
public CassandraObservationContext(Statement<?> statement, String remoteServiceName, boolean prepare,
42+
String methodName, String sessionName, String keyspaceName) {
43+
44+
super((carrier, key, value) -> {}, Kind.CLIENT);
3845

3946
this.statement = statement;
47+
this.prepare = prepare;
4048
this.methodName = methodName;
41-
this.delegateSession = delegateSession;
49+
this.sessionName = sessionName;
50+
this.keyspaceName = keyspaceName;
51+
52+
setRemoteServiceName(remoteServiceName);
4253
}
4354

44-
@Nullable
4555
public Statement<?> getStatement() {
4656
return statement;
4757
}
4858

59+
public boolean isPrepare() {
60+
return prepare;
61+
}
62+
4963
public String getMethodName() {
5064
return methodName;
5165
}
5266

53-
@Nullable
54-
public CqlSession getDelegateSession() {
55-
return delegateSession;
67+
public String getSessionName() {
68+
return sessionName;
69+
}
70+
71+
public String getKeyspaceName() {
72+
return keyspaceName;
5673
}
5774
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2022 the original author or authors.
2+
* Copyright 2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,12 +22,12 @@
2222
* {@link ObservationConvention} for Cassandra.
2323
*
2424
* @author Greg Turnquist
25-
* @since 4.0.0
25+
* @since 4.0
2626
*/
27-
public interface CqlSessionObservationConvention extends ObservationConvention<CqlSessionContext> {
27+
public interface CassandraObservationConvention extends ObservationConvention<CassandraObservationContext> {
2828

2929
@Override
3030
default boolean supportsContext(Observation.Context context) {
31-
return context instanceof CqlSessionContext;
31+
return context instanceof CassandraObservationContext;
3232
}
3333
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2022 the original author or authors.
2+
* Copyright 2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,20 +15,20 @@
1515
*/
1616
package org.springframework.data.cassandra.observability;
1717

18-
import java.lang.annotation.*;
19-
20-
import org.springframework.context.annotation.Import;
18+
import io.micrometer.observation.Observation;
2119

2220
/**
23-
* Annotation to enable Cassandra observability.
21+
* Returns the Cassandra Observation. Used internally - do not implement.
2422
*
25-
* @author Greg Turnquist
26-
* @since 4.0.0
23+
* @author Mark Paluch
24+
* @author Marcin Grzejszczak
25+
* @since 4.0
2726
*/
28-
@Inherited
29-
@Documented
30-
@Target(ElementType.TYPE)
31-
@Retention(RetentionPolicy.RUNTIME)
32-
@Import(CassandraObservationConfiguration.class)
33-
public @interface EnableCassandraObservability {
27+
interface CassandraObservationSupplier {
28+
29+
/**
30+
* @return the observation
31+
*/
32+
Observation getObservation();
33+
3434
}

0 commit comments

Comments
 (0)