From 993dfafed9457f1e57bfd02e73f8b4adb79fb9fd Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Wed, 18 Sep 2024 20:39:41 -0400 Subject: [PATCH] prevent the flags log from spamming --- .../java/cc/pulseapp/api/model/Feature.java | 18 ++++++++++++++++++ .../cc/pulseapp/api/service/FlagsService.java | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/cc/pulseapp/api/model/Feature.java b/src/main/java/cc/pulseapp/api/model/Feature.java index 783a24e..9292775 100644 --- a/src/main/java/cc/pulseapp/api/model/Feature.java +++ b/src/main/java/cc/pulseapp/api/model/Feature.java @@ -2,6 +2,8 @@ package cc.pulseapp.api.model; import lombok.*; +import java.util.Objects; + /** * A feature flag. * @@ -30,6 +32,8 @@ public enum Feature { */ @Setter private Object value; + + /** * Get a feature by its id. * @@ -44,4 +48,18 @@ public enum Feature { } return null; } + + /** + * Get the combined hash + * code of all features. + * + * @return the combined hash code + */ + public static int hash() { + int hash = 0; + for (Feature feature : VALUES) { + hash+= Objects.hash(feature.isEnabled(), feature.getValue()); + } + return hash; + } } \ No newline at end of file diff --git a/src/main/java/cc/pulseapp/api/service/FlagsService.java b/src/main/java/cc/pulseapp/api/service/FlagsService.java index 00e21aa..614d630 100644 --- a/src/main/java/cc/pulseapp/api/service/FlagsService.java +++ b/src/main/java/cc/pulseapp/api/service/FlagsService.java @@ -45,6 +45,7 @@ public final class FlagsService { new Timer().scheduleAtFixedRate(new TimerTask() { @Override @SneakyThrows public void run() { + int oldFlags = Feature.hash(); for (BaseFlag flag : client.getEnvironmentFlags().getAllFlags()) { Feature feature = Feature.getById(flag.getFeatureName()); if (feature == null) { @@ -54,7 +55,9 @@ public final class FlagsService { feature.setEnabled(flag.getEnabled()); feature.setValue(value instanceof String stringedValue && (stringedValue.isBlank()) ? null : value); } - log.info("Fetched new flags (:"); + if (oldFlags != Feature.hash()) { + log.info("Fetched new flags (:"); + } } }, 0L, FETCH_INTERVAL); }