Repository: Unleash/unleash-client-java
Pull request #245 (2024-07-25 09:52:07)

chore: bumped action versions to avoid deprecation warnings about nod…
…e versions


Patch:
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 704873b7..66a52c77 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -15,9 +15,9 @@ jobs:
         version: [8,11]
     steps:
       - name: Checkout
-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
       - name: Setup Java
-        uses: actions/setup-java@v3
+        uses: actions/setup-java@v4
         with:
           java-version: ${{ matrix.version }}
           cache: 'maven'
@@ -38,9 +38,9 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: Checkout
-        uses: actions/checkout@v2
+        uses: actions/checkout@v4
       - name: Setup Java
-        uses: actions/setup-java@v3
+        uses: actions/setup-java@v4
         with:
           java-version: 17
           distribution: 'temurin'
diff --git a/.github/workflows/publish_javadoc.yml b/.github/workflows/publish_javadoc.yml
index 18f23e45..a5c9c520 100644
--- a/.github/workflows/publish_javadoc.yml
+++ b/.github/workflows/publish_javadoc.yml
@@ -11,9 +11,9 @@ jobs:
     runs-on: ubuntu-20.04
     steps:
       - name: Checkout
-        uses: actions/checkout@v2
+        uses: actions/checkout@v4
       - name: Setup Java
-        uses: actions/setup-java@v1
+        uses: actions/setup-java@v4
         with:
           java-version: 17
       - name: Build
diff --git a/.github/workflows/pull_requests.yml b/.github/workflows/pull_requests.yml
index 8713d09b..42896f0b 100644
--- a/.github/workflows/pull_requests.yml
+++ b/.github/workflows/pull_requests.yml
@@ -12,7 +12,7 @@ jobs:
       - name: Checkout
         uses: actions/checkout@v4
       - name: Setup Java
-        uses: actions/setup-java@v3
+        uses: actions/setup-java@v4
         with:
           java-version: ${{ matrix.version }}
           cache: 'maven'
diff --git a/.github/workflows/release_to_central.yml b/.github/workflows/release_to_central.yml
index acb266ae..73371963 100644
--- a/.github/workflows/release_to_central.yml
+++ b/.github/workflows/release_to_central.yml
@@ -13,10 +13,10 @@ jobs:
   build:
     runs-on: ubuntu-latest
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
         name: Checkout code
       - name: Setup Java and Maven Central Repo
-        uses: actions/setup-java@v3
+        uses: actions/setup-java@v4
         with:
           java-version: '8'
           distribution: 'temurin'
diff --git a/src/main/java/io/getunleash/metric/ClientMetrics.java b/src/main/java/io/getunleash/metric/ClientMetrics.java
index f59a8ecc..82eac44e 100644
--- a/src/main/java/io/getunleash/metric/ClientMetrics.java
+++ b/src/main/java/io/getunleash/metric/ClientMetrics.java
@@ -2,6 +2,7 @@ package io.getunleash.metric;
 
 import io.getunleash.event.UnleashEvent;
 import io.getunleash.event.UnleashSubscriber;
+import io.getunleash.lang.Nullable;
 import io.getunleash.util.UnleashConfig;
 
 public class ClientMetrics implements UnleashEvent {
@@ -10,12 +11,20 @@ public class ClientMetrics implements UnleashEvent {
     private final String instanceId;
     private final MetricsBucket bucket;
     private final String environment;
+    private final String specVersion;
+    @Nullable private final String platformName;
+    @Nullable private final String platformVersion;
+    @Nullable private final String yggdrasilVersion;
 
     ClientMetrics(UnleashConfig config, MetricsBucket bucket) {
         this.environment = config.getEnvironment();
         this.appName = config.getAppName();
         this.instanceId = config.getInstanceId();
         this.bucket = bucket;
+        this.specVersion = config.getClientSpecificationVersion();
+        this.platformName = System.getProperty("java.vm.name");
+        this.platformVersion = System.getProperty("java.version");
+        this.yggdrasilVersion = null;
     }
 
     public String getAppName() {
@@ -34,6 +43,25 @@ public class ClientMetrics implements UnleashEvent {
         return environment;
     }
 
+    public String getSpecVersion() {
+        return specVersion;
+    }
+
+    @Nullable
+    public String getPlatformName() {
+        return platformName;
+    }
+
+    @Nullable
+    public String getPlatformVersion() {
+        return platformVersion;
+    }
+
+    @Nullable
+    public String getYggdrasilVersion() {
+        return yggdrasilVersion;
+    }
+
     @Override
     public void publishTo(UnleashSubscriber unleashSubscriber) {
         unleashSubscriber.clientMetrics(this);
diff --git a/src/main/java/io/getunleash/metric/ClientRegistration.java b/src/main/java/io/getunleash/metric/ClientRegistration.java
index b3019de7..a820ccf9 100644
--- a/src/main/java/io/getunleash/metric/ClientRegistration.java
+++ b/src/main/java/io/getunleash/metric/ClientRegistration.java
@@ -2,6 +2,7 @@ package io.getunleash.metric;
 
 import io.getunleash.event.UnleashEvent;
 import io.getunleash.event.UnleashSubscriber;
+import io.getunleash.lang.Nullable;
 import io.getunleash.util.UnleashConfig;
 import java.time.LocalDateTime;
 import java.util.Set;
@@ -14,6 +15,10 @@ public class ClientRegistration implements UnleashEvent {
     private final LocalDateTime started;
     private final long interval;
     private final String environment;
+    @Nullable private final String platformName;
+    @Nullable private final String platformVersion;
+    @Nullable private final String yggdrasilVersion;
+    private final String specVersion;
 
     ClientRegistration(UnleashConfig config, LocalDateTime started, Set<String> strategies) {
         this.environment = config.getEnvironment();
@@ -23,6 +28,10 @@ public class ClientRegistration implements UnleashEvent {
         this.started = started;
         this.strategies = strategies;
         this.interval = config.getSendMetricsInterval();
+        this.specVersion = config.getClientSpecificationVersion();
+        this.platformName = System.getProperty("java.vm.name");
+        this.platformVersion = System.getProperty("java.version");
+        this.yggdrasilVersion = null;
     }
 
     public String getAppName() {
@@ -53,6 +62,24 @@ public class ClientRegistration implements UnleashEvent {
         return environment;
     }
 
+    @Nullable
+    public String getPlatformName() {
+        return platformName;
+    }
+
+    @Nullable
+    public String getPlatformVersion() {
+        return platformVersion;
+    }
+
+    public @Nullable String getYggdrasilVersion() {
+        return yggdrasilVersion;
+    }
+
+    public String getSpecVersion() {
+        return specVersion;
+    }
+
     @Override
     public void publishTo(UnleashSubscriber unleashSubscriber) {
         unleashSubscriber.clientRegistered(this);
diff --git a/src/main/java/io/getunleash/metric/UnleashMetricServiceImpl.java b/src/main/java/io/getunleash/metric/UnleashMetricServiceImpl.java
index fa200cd1..caf2c3b0 100644
--- a/src/main/java/io/getunleash/metric/UnleashMetricServiceImpl.java
+++ b/src/main/java/io/getunleash/metric/UnleashMetricServiceImpl.java
@@ -13,7 +13,6 @@ public class UnleashMetricServiceImpl implements UnleashMetricService {
     private static final Logger LOGGER = LoggerFactory.getLogger(UnleashMetricServiceImpl.class);
     private final LocalDateTime started;
     private final UnleashConfig unleashConfig;
-
     private final MetricSender metricSender;
 
     // mutable
@@ -40,6 +39,7 @@ public class UnleashMetricServiceImpl implements UnleashMetricService {
                         300,
                         unleashConfig.getUnleashURLs().getClientMetricsURL());
         long metricsInterval = unleashConfig.getSendMetricsInterval();
+
         executor.setInterval(sendMetrics(), metricsInterval, metricsInterval);
     }
 


Test patch:
diff --git a/src/test/java/io/getunleash/metric/UnleashMetricServiceImplTest.java b/src/test/java/io/getunleash/metric/UnleashMetricServiceImplTest.java
index 1640ce03..ed5b631a 100644
--- a/src/test/java/io/getunleash/metric/UnleashMetricServiceImplTest.java
+++ b/src/test/java/io/getunleash/metric/UnleashMetricServiceImplTest.java
@@ -5,6 +5,7 @@ import static org.mockito.Mockito.*;
 
 import io.getunleash.util.UnleashConfig;
 import io.getunleash.util.UnleashScheduledExecutor;
+import java.time.LocalDateTime;
 import java.util.HashSet;
 import java.util.Set;
 import org.junit.jupiter.api.Test;
@@ -412,4 +413,49 @@ public class UnleashMetricServiceImplTest {
         assertThat(unleashMetricService.getFailures()).isEqualTo(0);
         assertThat(unleashMetricService.getSkips()).isEqualTo(0);
     }
+
+    @Test
+    public void should_add_new_metrics_data_to_bucket() {
+        UnleashConfig config =
+                UnleashConfig.builder()
+                        .appName("test")
+                        .sendMetricsInterval(10)
+                        .unleashAPI("http://unleash.com")
+                        .build();
+
+        UnleashScheduledExecutor executor = mock(UnleashScheduledExecutor.class);
+        DefaultHttpMetricsSender sender = mock(DefaultHttpMetricsSender.class);
+
+        UnleashMetricService unleashMetricService =
+                new UnleashMetricServiceImpl(config, sender, executor);
+
+        ArgumentCaptor<Runnable> sendMetricsCallback = ArgumentCaptor.forClass(Runnable.class);
+        verify(executor).setInterval(sendMetricsCallback.capture(), anyLong(), anyLong());
+
+        sendMetricsCallback.getValue().run();
+        ArgumentCaptor<ClientMetrics> metricsSent = ArgumentCaptor.forClass(ClientMetrics.class);
+        verify(sender, times(1)).sendMetrics(metricsSent.capture());
+        ClientMetrics metrics = metricsSent.getValue();
+        assertThat(metrics.getSpecVersion()).isNotEmpty();
+        assertThat(metrics.getYggdrasilVersion()).isNull();
+        assertThat(metrics.getPlatformName()).isNotEmpty();
+        assertThat(metrics.getPlatformVersion()).isNotEmpty();
+    }
+
+    @Test
+    public void client_registration_also_includes_new_metrics_metadata() {
+        UnleashConfig config =
+                UnleashConfig.builder()
+                        .appName("test")
+                        .sendMetricsInterval(10)
+                        .unleashAPI("http://unleash.com")
+                        .build();
+        Set<String> strategies = new HashSet<>();
+        strategies.add("default");
+        ClientRegistration reg = new ClientRegistration(config, LocalDateTime.now(), strategies);
+        assertThat(reg.getPlatformName()).isNotEmpty();
+        assertThat(reg.getPlatformVersion()).isNotEmpty();
+        assertThat(reg.getSpecVersion()).isEqualTo(config.getClientSpecificationVersion());
+        assertThat(reg.getYggdrasilVersion()).isNull();
+    }
 }