GH-1444: Observation Doc Gen Polishing

- single task for spans and metrics
- always gen and remove packages from file names

* Fix link in What's New; add observation properties to container factory.
This commit is contained in:
Gary Russell
2022-10-21 16:54:40 -04:00
committed by GitHub
parent 77dfa657dd
commit 36e98a735f
7 changed files with 71 additions and 129 deletions

View File

@@ -56,7 +56,7 @@ ext {
log4jVersion = '2.19.0'
logbackVersion = '1.4.4'
lz4Version = '1.8.0'
micrometerDocsVersion = '1.0.0-RC1'
micrometerDocsVersion = '1.0.0-SNAPSHOT'
micrometerVersion = '1.10.0-RC1'
micrometerTracingVersion = '1.0.0-RC1'
mockitoVersion = '4.8.0'
@@ -419,36 +419,8 @@ project('spring-rabbit') {
testRuntimeOnly ("junit:junit:$junit4Version") {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
adoc "io.micrometer:micrometer-docs-generator-spans:$micrometerDocsVersion"
adoc "io.micrometer:micrometer-docs-generator-metrics:$micrometerDocsVersion"
}
def inputDir = file('src/main/java/org/springframework/amqp/rabbit/support/micrometer').absolutePath
def outputDir = rootProject.file('src/reference/asciidoc').absolutePath
task generateObservabilityMetricsDocs(type: JavaExec) {
onlyIf { !isCI }
mainClass = 'io.micrometer.docs.metrics.DocsFromSources'
inputs.dir(inputDir)
outputs.dir(outputDir)
classpath configurations.adoc
args inputDir, '.*', outputDir
}
task generateObservabilitySpansDocs(type: JavaExec) {
onlyIf { !isCI }
mainClass = 'io.micrometer.docs.spans.DocsFromSources'
inputs.dir(inputDir)
outputs.dir(outputDir)
classpath configurations.adoc
args inputDir, '.*', outputDir
}
// javadoc {
// finalizedBy generateObservabilityMetricsDocs, generateObservabilitySpansDocs
// }
}
compileTestKotlin {
@@ -522,10 +494,12 @@ project('spring-rabbit-test') {
configurations {
asciidoctorExtensions
micrometerDocs
}
dependencies {
asciidoctorExtensions "io.spring.asciidoctor.backends:spring-asciidoctor-backends:${springAsciidoctorBackendsVersion}"
micrometerDocs "io.micrometer:micrometer-docs-generator:$micrometerDocsVersion"
}
task prepareAsciidocBuild(type: Sync) {
@@ -535,8 +509,28 @@ task prepareAsciidocBuild(type: Sync) {
into "$buildDir/asciidoc"
}
def observationInputDir = file('spring-rabbit/src/main/java/org/springframework/amqp/rabbit/support/micrometer').absolutePath
def generatedDocsDir = file("$buildDir/docs/generated").absolutePath
task generateObservabilityDocs(type: JavaExec) {
mainClass = 'io.micrometer.docs.DocsGeneratorCommand'
inputs.dir(observationInputDir)
outputs.dir(generatedDocsDir)
classpath configurations.micrometerDocs
args observationInputDir, /.+/, generatedDocsDir
}
task filterMetricsDocsContent(type: Copy) {
dependsOn generateObservabilityDocs
from generatedDocsDir
include '_*.adoc'
into generatedDocsDir
rename { filename -> filename.replace '_', '' }
filter { line -> line.replaceAll('org.springframework.amqp.rabbit.support.micrometer.', '').replaceAll('^Fully qualified n', 'N') }
}
asciidoctorPdf {
dependsOn prepareAsciidocBuild
dependsOn prepareAsciidocBuild, filterMetricsDocsContent
baseDirFollowsSourceFile()
asciidoctorj {

View File

@@ -32,6 +32,7 @@ import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer;
import org.springframework.amqp.rabbit.listener.MessageAckListener;
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpoint;
import org.springframework.amqp.rabbit.support.micrometer.RabbitListenerObservationConvention;
import org.springframework.amqp.support.ConsumerTagStrategy;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.amqp.utils.JavaUtils;
@@ -118,6 +119,12 @@ public abstract class AbstractRabbitListenerContainerFactory<C extends AbstractM
private MessageAckListener messageAckListener;
private Boolean micrometerEnabled;
private Boolean observationEnabled;
private RabbitListenerObservationConvention observationConvention;
/**
* @param connectionFactory The connection factory.
* @see AbstractMessageListenerContainer#setConnectionFactory(ConnectionFactory)
@@ -336,6 +343,37 @@ public abstract class AbstractRabbitListenerContainerFactory<C extends AbstractM
this.messageAckListener = messageAckListener;
}
/**
* Set to false to disable micrometer listener timers. When true, ignored
* if {@link #setObservationEnabled(boolean)} is set to true.
* @param micrometerEnabled false to disable.
* @since 3.0
* @see #setObservationEnabled(boolean)
*/
public void setMicrometerEnabled(boolean micrometerEnabled) {
this.micrometerEnabled = micrometerEnabled;
}
/**
* Enable observation via micrometer; disables basic Micrometer timers enabled
* by {@link #setMicrometerEnabled(boolean)}.
* @param observationEnabled true to enable.
* @since 3.0
* @see #setMicrometerEnabled(boolean)
*/
public void setObservationEnabled(boolean observationEnabled) {
this.observationEnabled = observationEnabled;
}
/**
* Set an observation convention; used to add additional key/values to observations.
* @param observationConvention the convention.
* @since 3.0
*/
public void setObservationConvention(RabbitListenerObservationConvention observationConvention) {
this.observationConvention = observationConvention;
}
@Override
public C createListenerContainer(RabbitListenerEndpoint endpoint) {
C instance = createContainerInstance();
@@ -370,7 +408,10 @@ public abstract class AbstractRabbitListenerContainerFactory<C extends AbstractM
.acceptIfNotNull(this.afterReceivePostProcessors, instance::setAfterReceivePostProcessors)
.acceptIfNotNull(this.deBatchingEnabled, instance::setDeBatchingEnabled)
.acceptIfNotNull(this.messageAckListener, instance::setMessageAckListener)
.acceptIfNotNull(this.batchingStrategy, instance::setBatchingStrategy);
.acceptIfNotNull(this.batchingStrategy, instance::setBatchingStrategy)
.acceptIfNotNull(this.micrometerEnabled, instance::setMicrometerEnabled)
.acceptIfNotNull(this.observationEnabled, instance::setObservationEnabled)
.acceptIfNotNull(this.observationConvention, instance::setObservationConvention);
if (this.batchListener && this.deBatchingEnabled == null) {
// turn off container debatching by default for batch listeners
instance.setDeBatchingEnabled(false);

View File

@@ -1,11 +0,0 @@
[[observability-conventions]]
=== Observability - Conventions
Below you can find a list of all `GlobalObservabilityConventions` and `ObservabilityConventions` declared by this project.
.ObservationConvention implementations
|===
|ObservationConvention Class Name | Applicable ObservationContext Class Name
|`DefaultRabbitListenerObservationConvention`|`RabbitMessageReceiverContext`
|`DefaultRabbitTemplateObservationConvention`|`RabbitMessageSenderContext`
|===

View File

@@ -1,44 +0,0 @@
[[observability-metrics]]
=== Observability - Metrics
Below you can find a list of all samples declared by this project.
[[observability-metrics-listener-observation]]
==== Listener Observation
____
Observation for Rabbit listeners.
____
**Metric name** `spring.rabbit.listener` (defined by convention class `RabbitListenerObservation$DefaultRabbitListenerObservationConvention`). **Type** `timer` and **base unit** `seconds`.
Name of the enclosing class `RabbitListenerObservation`.
IMPORTANT: All tags must be prefixed with `spring.rabbit.listener` prefix!
.Low cardinality Keys
[cols="a,a"]
|===
|Name | Description
|`spring.rabbit.listener.id`|Listener id.
|===
[[observability-metrics-template-observation]]
==== Template Observation
____
Observation for `RabbitTemplate` s.
____
**Metric name** `spring.rabbit.template` (defined by convention class `RabbitTemplateObservation$DefaultRabbitTemplateObservationConvention`). **Type** `timer` and **base unit** `seconds`.
Name of the enclosing class `RabbitTemplateObservation`.
IMPORTANT: All tags must be prefixed with `spring.rabbit.template` prefix!
.Low cardinality Keys
[cols="a,a"]
|===
|Name | Description
|`spring.rabbit.template.name`|Bean name of the template.
|===

View File

@@ -1,38 +0,0 @@
[[observability-spans]]
=== Observability - Spans
Below you can find a list of all spans declared by this project.
[[observability-spans-listener-observation]]
==== Listener Observation Span
> Observation for Rabbit listeners.
**Span name** `spring.rabbit.listener` (defined by convention class `RabbitListenerObservation$DefaultRabbitListenerObservationConvention`).
Name of the enclosing class `RabbitListenerObservation`.
IMPORTANT: All tags and event names must be prefixed with `spring.rabbit.listener` prefix!
.Tag Keys
|===
|Name | Description
|`spring.rabbit.listener.id`|Listener id.
|===
[[observability-spans-template-observation]]
==== Template Observation Span
> Observation for `RabbitTemplate` s.
**Span name** `spring.rabbit.template` (defined by convention class `RabbitTemplateObservation$DefaultRabbitTemplateObservationConvention`).
Name of the enclosing class `RabbitTemplateObservation`.
IMPORTANT: All tags and event names must be prefixed with `spring.rabbit.template` prefix!
.Tag Keys
|===
|Name | Description
|`spring.rabbit.template.name`|Bean name of the template.
|===

View File

@@ -2,17 +2,17 @@
[[observation-gen]]
== Micrometer Observation Documentation
include::_metrics.adoc[]
include::../docs/generated/metrics.adoc[]
include::_spans.adoc[]
include::../docs/generated/spans.adoc[]
include::_conventions.adoc[]
include::../docs/generated/conventions.adoc[]
[appendix]
[[change-history]]
== Change History
This section describes what changes have been made as versions have changed.
This section describes changes that have been made as versions have changed.
=== Current Release

View File

@@ -14,7 +14,7 @@ The remoting feature (using RMI) is no longer supported.
==== Observation
Enabling observation for timers and tracing using Micrometer is now supported.
See <<observation>> for more information.
See <<micrometer-observation>> for more information.
==== AsyncRabbitTemplate