Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Observation API usage #4065

Closed

Conversation

marcingrzejszczak
Copy link
Contributor

Prerequisites

Support for latest Micrometer 2.0.0 snapshots: https://github.com/spring-projects/spring-batch/pull/4060/files

What's done

  • Adds observation for Jobs and Steps.
  • Adds unit tests asserting that proper metrics are being created
  • Adds integration test (turns on only when Zipkin is available at a default port) to check how tracing looks like

Additional info

Trace view from Zipkin

image

Metrics from MeterRegistry

Notice the new spring.batch.job and spring.batch.step.

[main] INFO io.micrometer.tracing.test.SampleTestRunner - Gathered the following metrics
	Meter with name <spring.batch.job.active> and type <LONG_TASK_TIMER> has the following measurements 
		<[Measurement{statistic='ACTIVE_TASKS', value=0.0}, Measurement{statistic='DURATION', value=0.0}]> 
		and has the following tags <[tag(name=job)]>
	Meter with name <spring.batch.job> and type <TIMER> has the following measurements 
		<[Measurement{statistic='COUNT', value=1.0}, Measurement{statistic='TOTAL_TIME', value=0.029340031}, Measurement{statistic='MAX', value=0.029340031}]> 
		and has the following tags <[tag(error=none), tag(spring.batch.job.name=job), tag(spring.batch.job.status=COMPLETED)]>
	Meter with name <spring.batch.step> and type <TIMER> has the following measurements 
		<[Measurement{statistic='COUNT', value=1.0}, Measurement{statistic='TOTAL_TIME', value=0.010459161}, Measurement{statistic='MAX', value=0.010459161}]> 
		and has the following tags <[tag(error=none), tag(spring.batch.job.name=job), tag(spring.batch.step.name=step), tag(spring.batch.step.status=COMPLETED)]>

cc @jonatan-ivanov @shakuzen

@fmbenhassine
Copy link
Contributor

Thank you for your effort on this! I'm able to see tracing data in Zipkin in the new sample.

However, the test org.springframework.batch.sample.metrics.BatchMetricsTests#testBatchMetrics is failing with this PR even when I add Metrics.globalRegistry.withTimerObservationHandler();. Any idea?

without this change the BatchJobTagsProvider or BatchStepTagsProvider is not applied because it has a condition on instanceof BatchJobContext or BatchStepContext
with this change we're adding the missing context when the observation is created, without this the default context was used
@marcingrzejszczak
Copy link
Contributor Author

Yeah, check the commit 61ec4d4

@fmbenhassine fmbenhassine added this to the 5.0.0-M2 milestone Mar 15, 2022
fmbenhassine pushed a commit that referenced this pull request Mar 16, 2022
fmbenhassine added a commit that referenced this pull request Mar 16, 2022
* Fix tests
* Update Javadocs
* Update year in license headers
* Move observability APIs to a separate package
@fmbenhassine
Copy link
Contributor

Rebased, squashed and merged as e917d75. There are a couple of failing tests that I fixed in ae6c0b9.

The documentation changes that are expected to generate metrics and tracing meta-data did not work and failed with the following error:

[INFO] --- exec-maven-plugin:3.0.0:java (generate-metrics-metadata) @ spring-batch-docs ---
[WARNING]
java.lang.NoClassDefFoundError: io/micrometer/api/internal/logging/InternalLoggerFactory
    at io.micrometer.docs.metrics.DocsFromSources.<clinit> (DocsFromSources.java:34)
    at jdk.internal.misc.Unsafe.ensureClassInitialized0 (Native Method)
    at jdk.internal.misc.Unsafe.ensureClassInitialized (Unsafe.java:1155)
    at java.lang.invoke.DirectMethodHandle$EnsureInitialized.computeValue (DirectMethodHandle.java:377)
    at java.lang.invoke.DirectMethodHandle$EnsureInitialized.computeValue (DirectMethodHandle.java:374)
    at java.lang.ClassValue.getFromHashMap (ClassValue.java:228)
    at java.lang.ClassValue.getFromBackup (ClassValue.java:210)
    at java.lang.ClassValue.get (ClassValue.java:116)
    at java.lang.invoke.DirectMethodHandle.checkInitialized (DirectMethodHandle.java:400)
    at java.lang.invoke.DirectMethodHandle.ensureInitialized (DirectMethodHandle.java:388)
    at java.lang.invoke.DirectMethodHandle.internalMemberNameEnsureInit (DirectMethodHandle.java:338)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:254)
    at java.lang.Thread.run (Thread.java:833)
Caused by: java.lang.ClassNotFoundException: io.micrometer.api.internal.logging.InternalLoggerFactory
    at java.net.URLClassLoader.findClass (URLClassLoader.java:440)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:587)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:520)
    at io.micrometer.docs.metrics.DocsFromSources.<clinit> (DocsFromSources.java:34)
    at jdk.internal.misc.Unsafe.ensureClassInitialized0 (Native Method)
    at jdk.internal.misc.Unsafe.ensureClassInitialized (Unsafe.java:1155)
    at java.lang.invoke.DirectMethodHandle$EnsureInitialized.computeValue (DirectMethodHandle.java:377)
    at java.lang.invoke.DirectMethodHandle$EnsureInitialized.computeValue (DirectMethodHandle.java:374)
    at java.lang.ClassValue.getFromHashMap (ClassValue.java:228)
    at java.lang.ClassValue.getFromBackup (ClassValue.java:210)
    at java.lang.ClassValue.get (ClassValue.java:116)
    at java.lang.invoke.DirectMethodHandle.checkInitialized (DirectMethodHandle.java:400)
    at java.lang.invoke.DirectMethodHandle.ensureInitialized (DirectMethodHandle.java:388)
    at java.lang.invoke.DirectMethodHandle.internalMemberNameEnsureInit (DirectMethodHandle.java:338)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:254)
    at java.lang.Thread.run (Thread.java:833)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

These changes have been omitted from this PR. Please open a separate PR for that.

Thank you for all your effort in introducing the new Observation APIs in Spring Batch!

lcmarvin pushed a commit to lcmarvin/spring-batch that referenced this pull request Apr 16, 2022
lcmarvin pushed a commit to lcmarvin/spring-batch that referenced this pull request Apr 16, 2022
* Fix tests
* Update Javadocs
* Update year in license headers
* Move observability APIs to a separate package
fmbenhassine added a commit that referenced this pull request May 19, 2022
This is what is recommended by the observability
team in terms of tag naming with micrometer 1.10+
for consistency between both metrics and tracing.

In #4065, only some metrics have been updated to
follow this tag naming convention, but not all of
them. This commit updates all metrics in a similar
way for consistency.

Related to #4065 and #4098.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants