Skip to content

Commit 17311eb

Browse files
Support for Micrometer Observations (#1131)
with this change we're introducing Micrometer Observations for CircuitBreakers
1 parent c779081 commit 17311eb

File tree

12 files changed

+619
-1
lines changed

12 files changed

+619
-1
lines changed

docs/pom.xml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
<upload-docs-zip.phase>deploy</upload-docs-zip.phase>
2121
<!-- Don't upload docs jar to central / repo.spring.io -->
2222
<maven-deploy-plugin-default.phase>none</maven-deploy-plugin-default.phase>
23+
24+
<!-- Observability -->
25+
<micrometer-docs-generator.version>1.0.0-M5</micrometer-docs-generator.version>
26+
<micrometer-docs-generator.inputPath>${maven.multiModuleProjectDirectory}/spring-cloud-commons/</micrometer-docs-generator.inputPath>
27+
<micrometer-docs-generator.inclusionPattern>.*</micrometer-docs-generator.inclusionPattern>
28+
<micrometer-docs-generator.outputPath>${maven.multiModuleProjectDirectory}/target/</micrometer-docs-generator.outputPath>
2329
</properties>
2430
<dependencies>
2531
<dependency>
@@ -46,6 +52,58 @@
4652
<plugin>
4753
<groupId>org.codehaus.mojo</groupId>
4854
<artifactId>exec-maven-plugin</artifactId>
55+
<executions>
56+
<execution>
57+
<id>generate-metrics-metadata</id>
58+
<phase>prepare-package</phase>
59+
<goals>
60+
<goal>java</goal>
61+
</goals>
62+
<configuration>
63+
<mainClass>io.micrometer.docs.metrics.DocsFromSources</mainClass>
64+
<includePluginDependencies>true</includePluginDependencies>
65+
<arguments>
66+
<argument>${micrometer-docs-generator.inputPath}</argument>
67+
<argument>${micrometer-docs-generator.inclusionPattern}</argument>
68+
<argument>${micrometer-docs-generator.outputPath}</argument>
69+
</arguments>
70+
</configuration>
71+
</execution>
72+
<execution>
73+
<id>generate-tracing-metadata</id>
74+
<phase>prepare-package</phase>
75+
<goals>
76+
<goal>java</goal>
77+
</goals>
78+
<configuration>
79+
<mainClass>io.micrometer.docs.spans.DocsFromSources</mainClass>
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>
87+
</execution>
88+
</executions>
89+
<dependencies>
90+
<dependency>
91+
<groupId>io.micrometer
92+
</groupId>
93+
<artifactId>micrometer-docs-generator-spans</artifactId>
94+
<version>${micrometer-docs-generator.version}
95+
</version>
96+
<type>jar</type>
97+
</dependency>
98+
<dependency>
99+
<groupId>io.micrometer
100+
</groupId>
101+
<artifactId>micrometer-docs-generator-metrics</artifactId>
102+
<version>${micrometer-docs-generator.version}
103+
</version>
104+
<type>jar</type>
105+
</dependency>
106+
</dependencies>
49107
</plugin>
50108
<plugin>
51109
<groupId>org.apache.maven.plugins</groupId>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
:root-target: ../../../target/
2+
3+
[[observability]]
4+
== Observability metadata
5+
6+
include::{root-target}_metrics.adoc[]
7+
8+
include::{root-target}_spans.adoc[]

docs/src/main/asciidoc/appendix.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ This appendix provides a list of common {project-full-name} properties and refer
1111
NOTE: Property contributions can come from additional jar files on your classpath, so you should not consider this an exhaustive list.
1212
Also, you can define your own properties.
1313

14-
include::_configprops.adoc[]
14+
include::_configprops.adoc[]
15+
16+
include::_observability.adoc[]

spring-cloud-commons/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,5 +192,10 @@
192192
<artifactId>reactor-test</artifactId>
193193
<scope>test</scope>
194194
</dependency>
195+
<dependency>
196+
<groupId>io.micrometer</groupId>
197+
<artifactId>micrometer-observation-test</artifactId>
198+
<scope>test</scope>
199+
</dependency>
195200
</dependencies>
196201
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright 2013-2021 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.cloud.client.circuitbreaker.observation;
18+
19+
import io.micrometer.common.docs.KeyName;
20+
import io.micrometer.observation.Observation;
21+
import io.micrometer.observation.docs.DocumentedObservation;
22+
23+
enum CircuitBreakerDocumentedObservation implements DocumentedObservation {
24+
25+
/**
26+
* Observation created when we wrap a Supplier passed to the CircuitBreaker.
27+
*/
28+
CIRCUIT_BREAKER_SUPPLIER_OBSERVATION {
29+
@Override
30+
public Class<? extends Observation.ObservationConvention<? extends Observation.Context>> getDefaultConvention() {
31+
return DefaultCircuitBreakerObservationConvention.class;
32+
}
33+
34+
@Override
35+
public KeyName[] getLowCardinalityKeyNames() {
36+
return LowCardinalityTags.values();
37+
}
38+
39+
@Override
40+
public String getPrefix() {
41+
return "spring.cloud.circuitbreaker";
42+
}
43+
44+
// TODO: Move this to convention with the next micrometer release
45+
// @Override
46+
// public String getContextualName() {
47+
// return "circuit-breaker";
48+
// }
49+
},
50+
51+
/**
52+
* Observation created when we wrap a Function passed to the CircuitBreaker as
53+
* fallback.
54+
*/
55+
CIRCUIT_BREAKER_FUNCTION_OBSERVATION {
56+
@Override
57+
public Class<? extends Observation.ObservationConvention<? extends Observation.Context>> getDefaultConvention() {
58+
return DefaultCircuitBreakerObservationConvention.class;
59+
}
60+
61+
@Override
62+
public KeyName[] getLowCardinalityKeyNames() {
63+
return LowCardinalityTags.values();
64+
}
65+
66+
@Override
67+
public String getPrefix() {
68+
return "spring.cloud.circuitbreaker";
69+
}
70+
71+
// TODO: Move this to convention with the next micrometer release
72+
// @Override
73+
// public String getContextualName() {
74+
// return "circuit-breaker fallback";
75+
// }
76+
};
77+
78+
enum LowCardinalityTags implements KeyName {
79+
80+
/**
81+
* Defines the type of wrapped lambda.
82+
*/
83+
OBJECT_TYPE {
84+
@Override
85+
public String getKeyName() {
86+
return "spring.cloud.circuitbreaker.type";
87+
}
88+
}
89+
90+
}
91+
92+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2018-2021 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.cloud.client.circuitbreaker.observation;
18+
19+
import io.micrometer.observation.Observation;
20+
21+
/**
22+
* Circuit Breaker {@link Observation.Context}.
23+
*
24+
* @author Marcin Grzejszczak
25+
* @since 4.0.0
26+
*/
27+
public class CircuitBreakerObservationContext extends Observation.Context {
28+
29+
private final Type type;
30+
31+
/**
32+
* Creates a new instance of {@link CircuitBreakerDocumentedObservation}.
33+
* @param type type of wrapped object
34+
*/
35+
public CircuitBreakerObservationContext(Type type) {
36+
this.type = type;
37+
}
38+
39+
/**
40+
* Gets the wrapped object type.
41+
* @return type of wrapped object
42+
*/
43+
public Type getType() {
44+
return type;
45+
}
46+
47+
/**
48+
* Describes the type of wrapped object.
49+
*/
50+
public enum Type {
51+
52+
/**
53+
* Fallback function.
54+
*/
55+
FUNCTION,
56+
57+
/**
58+
* Operation to run.
59+
*/
60+
SUPPLIER
61+
62+
}
63+
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2018-2021 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.cloud.client.circuitbreaker.observation;
18+
19+
import io.micrometer.observation.Observation;
20+
21+
/**
22+
* {@link Observation.ObservationConvention} for {@link CircuitBreakerObservationContext}.
23+
*
24+
* @author Marcin Grzejszczak
25+
* @since 4.0.0
26+
*/
27+
public interface CircuitBreakerObservationConvention
28+
extends Observation.ObservationConvention<CircuitBreakerObservationContext> {
29+
30+
@Override
31+
default boolean supportsContext(Observation.Context context) {
32+
return context instanceof CircuitBreakerObservationContext;
33+
}
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2018-2021 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.cloud.client.circuitbreaker.observation;
18+
19+
import java.util.Locale;
20+
21+
import io.micrometer.common.KeyValues;
22+
23+
/**
24+
* Default implementation of {@link CircuitBreakerObservationContext}.
25+
*
26+
* @author Marcin Grzejszczak
27+
* @since 4.0.0
28+
*/
29+
public class DefaultCircuitBreakerObservationConvention implements CircuitBreakerObservationConvention {
30+
31+
static final DefaultCircuitBreakerObservationConvention INSTANCE = new DefaultCircuitBreakerObservationConvention();
32+
33+
@Override
34+
public KeyValues getLowCardinalityKeyValues(CircuitBreakerObservationContext context) {
35+
return KeyValues.of(CircuitBreakerDocumentedObservation.LowCardinalityTags.OBJECT_TYPE
36+
.of(context.getType().name().toLowerCase(Locale.ROOT)));
37+
}
38+
39+
@Override
40+
public String getName() {
41+
return "spring.cloud.circuitbreaker";
42+
}
43+
44+
}

0 commit comments

Comments
 (0)