-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19192 from mkouba/scheduler-metrics
Scheduler - make it possible to record metrics automatically
- Loading branch information
Showing
13 changed files
with
306 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/metrics/Jobs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.quarkus.quartz.test.metrics; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
|
||
import org.eclipse.microprofile.metrics.annotation.Timed; | ||
|
||
import io.quarkus.scheduler.Scheduled; | ||
|
||
public class Jobs { | ||
|
||
static final CountDownLatch latch01 = new CountDownLatch(1); | ||
static final CountDownLatch latch02 = new CountDownLatch(1); | ||
|
||
@Scheduled(every = "1s") | ||
void everySecond() { | ||
latch01.countDown(); | ||
} | ||
|
||
@Timed(name = "foo") // Extension should not override this annotation | ||
@Scheduled(every = "1s") | ||
void anotherEverySecond() { | ||
latch02.countDown(); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/metrics/MpTimedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.quarkus.quartz.test.metrics; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.eclipse.microprofile.metrics.MetricID; | ||
import org.eclipse.microprofile.metrics.MetricRegistry; | ||
import org.eclipse.microprofile.metrics.Tag; | ||
import org.eclipse.microprofile.metrics.Timer; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class MpTimedTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Jobs.class) | ||
.addAsResource(new StringAsset("quarkus.scheduler.metrics.enabled=true"), | ||
"application.properties")); | ||
|
||
@Inject | ||
MetricRegistry metricRegistry; | ||
|
||
@Test | ||
void testTimedMethod() throws InterruptedException { | ||
assertTrue(Jobs.latch01.await(5, TimeUnit.SECONDS)); | ||
assertTrue(Jobs.latch02.await(5, TimeUnit.SECONDS)); | ||
Timer timer1 = metricRegistry | ||
.getTimer(new MetricID(Jobs.class.getName() + ".everySecond", new Tag("scheduled", "true"))); | ||
assertNotNull(timer1); | ||
assertTrue(timer1.getCount() > 0); | ||
Timer timer2 = metricRegistry.getTimer(new MetricID(Jobs.class.getName() + ".foo")); | ||
assertNotNull(timer2); | ||
assertTrue(timer2.getCount() > 0); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...duler/deployment/src/test/java/io/quarkus/scheduler/test/metrics/MicrometerTimedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package io.quarkus.scheduler.test.metrics; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.micrometer.core.annotation.Timed; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Metrics; | ||
import io.micrometer.core.instrument.Timer; | ||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry; | ||
import io.quarkus.scheduler.Scheduled; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class MicrometerTimedTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest test = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(Jobs.class) | ||
.addAsResource(new StringAsset("quarkus.scheduler.metrics.enabled=true"), | ||
"application.properties")); | ||
|
||
@Inject | ||
MeterRegistry registry; | ||
|
||
@BeforeAll | ||
static void addSimpleRegistry() { | ||
Metrics.globalRegistry.add(new SimpleMeterRegistry()); | ||
} | ||
|
||
@Test | ||
void testTimedMethod() throws InterruptedException { | ||
assertTrue(Jobs.latch01.await(5, TimeUnit.SECONDS)); | ||
assertTrue(Jobs.latch02.await(5, TimeUnit.SECONDS)); | ||
Timer timer1 = registry.get("scheduled.methods") | ||
.tag("method", "everySecond") | ||
.tag("class", "io.quarkus.scheduler.test.metrics.MicrometerTimedTest$Jobs") | ||
.tag("exception", "none") | ||
.timer(); | ||
assertNotNull(timer1); | ||
assertTrue(timer1.count() > 0); | ||
Timer timer2 = registry.get("foo") | ||
.tag("method", "anotherEverySecond") | ||
.tag("class", "io.quarkus.scheduler.test.metrics.MicrometerTimedTest$Jobs") | ||
.tag("exception", "none") | ||
.timer(); | ||
assertNotNull(timer2); | ||
assertTrue(timer2.count() > 0); | ||
} | ||
|
||
static class Jobs { | ||
|
||
static final CountDownLatch latch01 = new CountDownLatch(1); | ||
static final CountDownLatch latch02 = new CountDownLatch(1); | ||
|
||
@Scheduled(every = "1s") | ||
void everySecond() { | ||
latch01.countDown(); | ||
} | ||
|
||
@Timed("foo") // Extension should not override this annotation | ||
@Scheduled(every = "1s") | ||
void anotherEverySecond() { | ||
latch02.countDown(); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.