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

Add Graphite Extension #72

Merged
merged 5 commits into from
May 30, 2021
Merged

Add Graphite Extension #72

merged 5 commits into from
May 30, 2021

Conversation

luneo7
Copy link
Contributor

@luneo7 luneo7 commented May 28, 2021

Adds Graphite Extension.
Fully working in native image.

With this extension you are able to customize the name mapper, to not clash with JMX extension I added GraphiteNameMapper qualifier (without it the IT tests fails with ambiguous produces)

We can also customize Graphite Meter Registry Config by implementing GraphiteMeterRegistryConfigCustomizer this is useful when you want to change the naming convention for instance (you can only to that after the registry is created)

@luneo7
Copy link
Contributor Author

luneo7 commented May 28, 2021

@cemnura @ebullient can you guys take a look? Thanks =]

@ebullient
Copy link
Contributor

Thanks! I am off today.. initial look is awesome! Will get to this as soon as I can. Thanks!

Copy link
Contributor

@ebullient ebullient left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know where the customizer pattern comes from, but I would rather avoid it. I am thinking about an additional property to disable the producer creating the default instance at all (which should make it easier to replace w/o relying on default bean ... which doesn't match some registry usage patterns)

@ebullient
Copy link
Contributor

ebullient commented May 29, 2021

Re: avoiding the customizers, this is what I'm thinking (and I do need to hustle for 2.0 Final): quarkusio/quarkus#17536

Each registry extension would need to check for an additional property, and if false, add a VetoDefaultMeterRegistryBuildItem (which would then veto the produces method that would have created the default MeterRegistry). That keeps things pretty clean from the registry extension side. The core micrometer extension then handles the annotation transformation piece.

A user would then set the flag to suppress the default, and would define their own @Produces method (with the injected config, etc), and can construct their registry directly (they could combine with other config, or with profiles, or whatever).

Would this suffice, or is there some other angle to the customizer that I'm missing?

@luneo7
Copy link
Contributor Author

luneo7 commented May 29, 2021

@ebullient That would do it. Adding @UnlessBuildProperty to the producer wouldn't it also do it? I will do the changes in the Graphite extension to keep it consistent. Did you gave a thought about the NameMapper? (I added a qualifier to it so it doesn't clash with the JMX one)...

@ebullient
Copy link
Contributor

ebullient commented May 30, 2021

Ha! I forgot about that. Same premise, let me see what that looks like. The qualifier for naming conventions is fine. ;)

edit: @UnlessBuildProperty is detected, but doesn't change behavior of the @Produces method -- the CDI bean is still created. I will mess with it a little more (there may be a bug), but I know this approach (with @Vetoed) works as intended. Final is in a very few days...

@ebullient
Copy link
Contributor

Just need to fix formatting and we are good to go! I will sort out Vetoed/Unless behavior in main.. (and will then handle updates here)

@luneo7
Copy link
Contributor Author

luneo7 commented May 30, 2021

Fixed formatting, IntelliJ pranked me in the last commit... Thanks =]

@ebullient ebullient merged commit 776be94 into quarkiverse:main May 30, 2021
@ebullient
Copy link
Contributor

@all-contributors please add @luneo7 for adding code to support graphite

@allcontributors
Copy link
Contributor

@ebullient

I've put up a pull request to add @luneo7! 🎉

@luneo7
Copy link
Contributor Author

luneo7 commented May 30, 2021

@ebullient I've made @UnlessBuildProperty work like this:

Index: micrometer-registry-graphite/runtime/src/main/java/io/quarkiverse/micrometer/registry/graphite/GraphiteConfig.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/micrometer-registry-graphite/runtime/src/main/java/io/quarkiverse/micrometer/registry/graphite/GraphiteConfig.java b/micrometer-registry-graphite/runtime/src/main/java/io/quarkiverse/micrometer/registry/graphite/GraphiteConfig.java
--- a/micrometer-registry-graphite/runtime/src/main/java/io/quarkiverse/micrometer/registry/graphite/GraphiteConfig.java	(revision 66dd2e93f06530de96c16c5d733fd189ae0ceb58)
+++ b/micrometer-registry-graphite/runtime/src/main/java/io/quarkiverse/micrometer/registry/graphite/GraphiteConfig.java	(date 1622393325132)
@@ -23,6 +23,14 @@
         @ConfigItem
         public Optional<Boolean> enabled;
 
+        /**
+         * By default, this extension will create a Graphite MeterRegistry instance.
+         * <p>
+         * Use this attribute to veto the creation of the default Graphite MeterRegistry.
+         */
+        @ConfigItem(defaultValue = "true")
+        public Boolean defaultRegistry;
+
         @Override
         public Optional<Boolean> getEnabled() {
             return enabled;
Index: micrometer-registry-graphite/runtime/src/main/java/io/quarkiverse/micrometer/registry/graphite/GraphiteMeterRegistryProvider.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/micrometer-registry-graphite/runtime/src/main/java/io/quarkiverse/micrometer/registry/graphite/GraphiteMeterRegistryProvider.java b/micrometer-registry-graphite/runtime/src/main/java/io/quarkiverse/micrometer/registry/graphite/GraphiteMeterRegistryProvider.java
--- a/micrometer-registry-graphite/runtime/src/main/java/io/quarkiverse/micrometer/registry/graphite/GraphiteMeterRegistryProvider.java	(revision 66dd2e93f06530de96c16c5d733fd189ae0ceb58)
+++ b/micrometer-registry-graphite/runtime/src/main/java/io/quarkiverse/micrometer/registry/graphite/GraphiteMeterRegistryProvider.java	(date 1622392991364)
@@ -5,6 +5,7 @@
 import javax.enterprise.inject.Produces;
 import javax.inject.Singleton;
 
+import io.quarkus.arc.properties.UnlessBuildProperty;
 import org.eclipse.microprofile.config.Config;
 
 import io.micrometer.core.instrument.Clock;
@@ -39,6 +40,7 @@
 
     @Produces
     @Singleton
+    @UnlessBuildProperty(name = "quarkus.micrometer.export.graphite.default-registry", stringValue = "false")
     public GraphiteMeterRegistry registry(GraphiteConfig config,
             @GraphiteNameMapper HierarchicalNameMapper nameMapper,
             Clock clock) {
Index: micrometer-registry-graphite/deployment/src/test/java/io/quarkiverse/micrometer/registry/graphite/deployment/GraphiteDefaultRegistryDisabledTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/micrometer-registry-graphite/deployment/src/test/java/io/quarkiverse/micrometer/registry/graphite/deployment/GraphiteDefaultRegistryDisabledTest.java b/micrometer-registry-graphite/deployment/src/test/java/io/quarkiverse/micrometer/registry/graphite/deployment/GraphiteDefaultRegistryDisabledTest.java
new file mode 100644
--- /dev/null	(date 1622393877312)
+++ b/micrometer-registry-graphite/deployment/src/test/java/io/quarkiverse/micrometer/registry/graphite/deployment/GraphiteDefaultRegistryDisabledTest.java	(date 1622393877312)
@@ -0,0 +1,56 @@
+package io.quarkiverse.micrometer.registry.graphite.deployment;
+
+import io.micrometer.core.instrument.Clock;
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
+import io.micrometer.graphite.GraphiteConfig;
+import io.micrometer.graphite.GraphiteMeterRegistry;
+import io.quarkus.arc.Unremovable;
+import io.quarkus.test.QuarkusUnitTest;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import java.util.Set;
+
+public class GraphiteDefaultRegistryDisabledTest {
+
+    @RegisterExtension
+    static final QuarkusUnitTest config = new QuarkusUnitTest()
+            .withConfigurationResource("test-logging.properties")
+            .overrideConfigKey("quarkus.micrometer.binder-enabled-default", "false")
+            .overrideConfigKey("quarkus.micrometer.export.graphite.enabled", "true")
+            .overrideConfigKey("quarkus.micrometer.export.graphite.default-registry", "false")
+            .overrideConfigKey("quarkus.micrometer.registry-enabled-default", "false")
+            .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
+
+    @Inject
+    MeterRegistry registry;
+
+    private static final GraphiteMeterRegistry TEST_REGISTRY = new GraphiteMeterRegistry(GraphiteConfig.DEFAULT, Clock.SYSTEM);
+
+    @Test
+    public void testMeterRegistryPresent() {
+        // Graphite is enabled (alone, all others disabled)
+        Assertions.assertNotNull(registry, "A registry should be configured");
+        Set<MeterRegistry> subRegistries = ((CompositeMeterRegistry) registry).getRegistries();
+        Assertions.assertEquals(1, subRegistries.size(),
+                "There should be a sub-registry: " + subRegistries);
+        Assertions.assertEquals(TEST_REGISTRY, subRegistries.iterator().next());
+    }
+
+    @Singleton
+    public static class TestProducer {
+        @Produces
+        @Singleton
+        @Unremovable
+        public GraphiteMeterRegistry registry() {
+            return TEST_REGISTRY;
+        }
+    }
+}

@ebullient
Copy link
Contributor

ebullient commented May 30, 2021

I think that is more or less what I tried here: ebullient/quarkus@vetoDefaultRegistry...ebullient:defaultUnlessProperty
And two registries were created (without removing all of the veto stuff -- I just bypassed using it to try the annotation in that branch. which is based on the PR branch) .. feel free to make comments there, rather than here.. but the PrometheusMeterRegistry did not behave correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants