Repository: relayrides/pushy (java)

Issue:
Micrometer adapter does not pass tags to open connections gauge
In [`MicrometerApnsClientMetricsListener:163`](https://github.com/relayrides/pushy/blob/ddd6c9054c1c026b0aa55eeb8f200e1a7dcc90eb/micrometer-metrics-listener/src/main/java/com/turo/pushy/apns/metrics/micrometer/MicrometerApnsClientMetricsListener.java#L163), the tags given to the constructor does not get passed into `meterRegistry.gauge(...)`. This might be an issue when there are more than one `ApnsClient` instances, especially when the metrics are tagged with a unique string.

Pull request:
Add user-supplied tags to Micrometer gauges
This fixes #668, a bug where we weren't applying user-provided tags to the "open connections" gauge in the Micrometer metrics listener.

Patch:
diff --git a/micrometer-metrics-listener/pom.xml b/micrometer-metrics-listener/pom.xml
index ebe3f1d3..45615c65 100644
--- a/micrometer-metrics-listener/pom.xml
+++ b/micrometer-metrics-listener/pom.xml
@@ -65,6 +65,16 @@
                     </links>
                 </configuration>
             </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                </configuration>
+            </plugin>
+
         </plugins>
     </build>
 </project>
diff --git a/micrometer-metrics-listener/src/main/java/com/turo/pushy/apns/metrics/micrometer/MicrometerApnsClientMetricsListener.java b/micrometer-metrics-listener/src/main/java/com/turo/pushy/apns/metrics/micrometer/MicrometerApnsClientMetricsListener.java
index 0d968a27..10c9d05e 100644
--- a/micrometer-metrics-listener/src/main/java/com/turo/pushy/apns/metrics/micrometer/MicrometerApnsClientMetricsListener.java
+++ b/micrometer-metrics-listener/src/main/java/com/turo/pushy/apns/metrics/micrometer/MicrometerApnsClientMetricsListener.java
@@ -26,6 +26,7 @@ import com.turo.pushy.apns.ApnsClient;
 import com.turo.pushy.apns.ApnsClientMetricsListener;
 import io.micrometer.core.instrument.Counter;
 import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.Tags;
 import io.micrometer.core.instrument.Timer;
 
 import java.util.List;
@@ -160,7 +161,8 @@ public class MicrometerApnsClientMetricsListener implements ApnsClientMetricsLis
         this.rejectedNotifications = meterRegistry.counter(REJECTED_NOTIFICATIONS_COUNTER_NAME, tags);
 
         this.connectionFailures = meterRegistry.counter(CONNECTION_FAILURES_COUNTER_NAME, tags);
-        meterRegistry.gauge(OPEN_CONNECTIONS_GAUGE_NAME, openConnections);
+
+        meterRegistry.gauge(OPEN_CONNECTIONS_GAUGE_NAME, Tags.of(tags), openConnections);
     }
 
     /**


Test patch:
diff --git a/micrometer-metrics-listener/src/test/java/com/turo/pushy/apns/metrics/micrometer/MicrometerApnsClientMetricsListenerTest.java b/micrometer-metrics-listener/src/test/java/com/turo/pushy/apns/metrics/micrometer/MicrometerApnsClientMetricsListenerTest.java
index 8ac8d814..a3ddb995 100644
--- a/micrometer-metrics-listener/src/test/java/com/turo/pushy/apns/metrics/micrometer/MicrometerApnsClientMetricsListenerTest.java
+++ b/micrometer-metrics-listener/src/test/java/com/turo/pushy/apns/metrics/micrometer/MicrometerApnsClientMetricsListenerTest.java
@@ -22,14 +22,16 @@
 
 package com.turo.pushy.apns.metrics.micrometer;
 
-import io.micrometer.core.instrument.Counter;
-import io.micrometer.core.instrument.Gauge;
-import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.*;
 import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
 import org.junit.Before;
 import org.junit.Test;
 
+import java.util.Collections;
+import java.util.List;
+
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 public class MicrometerApnsClientMetricsListenerTest {
 
@@ -42,6 +44,25 @@ public class MicrometerApnsClientMetricsListenerTest {
         this.listener = new MicrometerApnsClientMetricsListener(this.meterRegistry);
     }
 
+    @Test
+    public void testMicrometerApnsClientMetricsListenerNoTags() {
+        for (final Meter meter : this.meterRegistry.getMeters()) {
+            assertTrue(meter.getId().getTags().isEmpty());
+        }
+    }
+
+    @Test
+    public void testMicrometerApnsClientMetricsListenerTags() {
+        final MeterRegistry taggedMeterRegistry = new SimpleMeterRegistry();
+        new MicrometerApnsClientMetricsListener(taggedMeterRegistry, "key", "value");
+
+        final List<Tag> expectedTags = Collections.singletonList(Tag.of("key", "value"));
+
+        for (final Meter meter : taggedMeterRegistry.getMeters()) {
+            assertEquals(expectedTags, meter.getId().getTags());
+        }
+    }
+
     @Test
     public void testHandleWriteFailure() {
         final Counter writeFailures = this.meterRegistry.get(MicrometerApnsClientMetricsListener.WRITE_FAILURES_COUNTER_NAME).counter();