Skip to content

Commit

Permalink
spring-projectsGH-1444: Observation Doc Gen Polishing
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
garyrussell authored Oct 21, 2022
1 parent 77dfa65 commit 36e98a7
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 129 deletions.
54 changes: 24 additions & 30 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -336,6 +343,37 @@ public void setMessageAckListener(MessageAckListener messageAckListener) {
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();
Expand Down Expand Up @@ -370,7 +408,10 @@ public C createListenerContainer(RabbitListenerEndpoint endpoint) {
.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);
Expand Down
11 changes: 0 additions & 11 deletions src/reference/asciidoc/_conventions.adoc

This file was deleted.

44 changes: 0 additions & 44 deletions src/reference/asciidoc/_metrics.adoc

This file was deleted.

38 changes: 0 additions & 38 deletions src/reference/asciidoc/_spans.adoc

This file was deleted.

8 changes: 4 additions & 4 deletions src/reference/asciidoc/appendix.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/reference/asciidoc/whats-new.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 36e98a7

Please sign in to comment.