-
Notifications
You must be signed in to change notification settings - Fork 78
feat: impact metrics serialization and wiring #340
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,10 @@ | |
| import io.getunleash.engine.UnleashEngine; | ||
| import io.getunleash.event.UnleashEvent; | ||
| import io.getunleash.event.UnleashSubscriber; | ||
| import io.getunleash.impactmetrics.CollectedMetric; | ||
| import io.getunleash.lang.Nullable; | ||
| import io.getunleash.util.UnleashConfig; | ||
| import java.util.List; | ||
|
|
||
| public class ClientMetrics implements UnleashEvent { | ||
|
|
||
|
|
@@ -18,8 +20,16 @@ public class ClientMetrics implements UnleashEvent { | |
| @Nullable private final String platformName; | ||
| @Nullable private final String platformVersion; | ||
| @Nullable private final String yggdrasilVersion; | ||
| @Nullable private final List<CollectedMetric> impactMetrics; | ||
|
|
||
| ClientMetrics(UnleashConfig config, @Nullable MetricsBucket bucket) { | ||
| this(config, bucket, null); | ||
| } | ||
|
|
||
| ClientMetrics( | ||
| UnleashConfig config, | ||
| @Nullable MetricsBucket bucket, | ||
| @Nullable List<CollectedMetric> impactMetrics) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding impact metrics so it can be used in next iterations. |
||
| this.environment = config.getEnvironment(); | ||
| this.appName = config.getAppName(); | ||
| this.instanceId = config.getInstanceId(); | ||
|
|
@@ -29,6 +39,7 @@ public class ClientMetrics implements UnleashEvent { | |
| this.platformName = System.getProperty("java.vm.name"); | ||
| this.platformVersion = System.getProperty("java.version"); | ||
| this.yggdrasilVersion = UnleashEngine.getCoreVersion(); | ||
| this.impactMetrics = impactMetrics; | ||
| } | ||
|
|
||
| public String getAppName() { | ||
|
|
@@ -71,6 +82,11 @@ public String getYggdrasilVersion() { | |
| return yggdrasilVersion; | ||
| } | ||
|
|
||
| @Nullable | ||
| public List<CollectedMetric> getImpactMetrics() { | ||
| return impactMetrics; | ||
| } | ||
|
|
||
| @Override | ||
| public void publishTo(UnleashSubscriber unleashSubscriber) { | ||
| unleashSubscriber.clientMetrics(this); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,10 @@ | |
| import com.google.gson.*; | ||
| import io.getunleash.UnleashException; | ||
| import io.getunleash.event.EventDispatcher; | ||
| import io.getunleash.impactmetrics.HistogramBucket; | ||
| import io.getunleash.util.AtomicLongSerializer; | ||
| import io.getunleash.util.DateTimeSerializer; | ||
| import io.getunleash.util.HistogramBucketSerializer; | ||
| import io.getunleash.util.InstantSerializer; | ||
| import io.getunleash.util.UnleashConfig; | ||
| import io.getunleash.util.UnleashURLs; | ||
|
|
@@ -38,6 +40,7 @@ public DefaultHttpMetricsSender(UnleashConfig unleashConfig) { | |
| .registerTypeAdapter(LocalDateTime.class, new DateTimeSerializer()) | ||
| .registerTypeAdapter(Instant.class, new InstantSerializer()) | ||
| .registerTypeAdapter(AtomicLong.class, new AtomicLongSerializer()) | ||
| .registerTypeAdapter(HistogramBucket.class, new HistogramBucketSerializer()) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Register our serializer |
||
| .create(); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,10 @@ | |
| import com.google.gson.GsonBuilder; | ||
| import io.getunleash.UnleashException; | ||
| import io.getunleash.event.EventDispatcher; | ||
| import io.getunleash.impactmetrics.HistogramBucket; | ||
| import io.getunleash.util.AtomicLongSerializer; | ||
| import io.getunleash.util.DateTimeSerializer; | ||
| import io.getunleash.util.HistogramBucketSerializer; | ||
| import io.getunleash.util.OkHttpClientConfigurer; | ||
| import io.getunleash.util.UnleashConfig; | ||
| import java.io.IOException; | ||
|
|
@@ -58,6 +60,7 @@ public OkHttpMetricsSender(UnleashConfig config) { | |
| new GsonBuilder() | ||
| .registerTypeAdapter(LocalDateTime.class, new DateTimeSerializer()) | ||
| .registerTypeAdapter(AtomicLong.class, new AtomicLongSerializer()) | ||
| .registerTypeAdapter(HistogramBucket.class, new HistogramBucketSerializer()) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Register serializer. |
||
| .create(); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package io.getunleash.util; | ||
|
|
||
| import com.google.gson.JsonElement; | ||
| import com.google.gson.JsonObject; | ||
| import com.google.gson.JsonSerializationContext; | ||
| import com.google.gson.JsonSerializer; | ||
| import io.getunleash.impactmetrics.HistogramBucket; | ||
| import java.lang.reflect.Type; | ||
|
|
||
| public class HistogramBucketSerializer implements JsonSerializer<HistogramBucket> { | ||
|
|
||
| @Override | ||
| public JsonElement serialize( | ||
| HistogramBucket src, Type typeOfSrc, JsonSerializationContext context) { | ||
| JsonObject jsonObject = new JsonObject(); | ||
| if (Double.isInfinite(src.getLe()) && src.getLe() > 0) { | ||
| jsonObject.addProperty("le", "+Inf"); | ||
| } else { | ||
| jsonObject.addProperty("le", src.getLe()); | ||
| } | ||
| jsonObject.addProperty("count", src.getCount()); | ||
| return jsonObject; | ||
| } | ||
| } | ||
|
Comment on lines
+12
to
+24
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are adding simple json serializer for |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |
| import io.getunleash.UnleashException; | ||
| import io.getunleash.event.NoOpSubscriber; | ||
| import io.getunleash.event.UnleashSubscriber; | ||
| import io.getunleash.impactmetrics.ImpactMetricsDataSource; | ||
| import io.getunleash.lang.Nullable; | ||
| import io.getunleash.metric.DefaultHttpMetricsSender; | ||
| import io.getunleash.repository.HttpFeatureFetcher; | ||
|
|
@@ -73,6 +74,7 @@ public class UnleashConfig { | |
| @Nullable private final ToggleBootstrapProvider toggleBootstrapProvider; | ||
| @Nullable private final Proxy proxy; | ||
| @Nullable private final Consumer<UnleashException> startupExceptionHandler; | ||
| @Nullable private final ImpactMetricsDataSource impactMetricsRegistry; | ||
|
|
||
| private UnleashConfig( | ||
| @Nullable URI unleashAPI, | ||
|
|
@@ -106,7 +108,8 @@ private UnleashConfig( | |
| @Nullable ToggleBootstrapProvider unleashBootstrapProvider, | ||
| @Nullable Proxy proxy, | ||
| @Nullable Authenticator proxyAuthenticator, | ||
| @Nullable Consumer<UnleashException> startupExceptionHandler) { | ||
| @Nullable Consumer<UnleashException> startupExceptionHandler, | ||
| @Nullable ImpactMetricsDataSource impactMetricsRegistry) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Java it is possible to build config by adding custom registry. |
||
|
|
||
| if (appName == null) { | ||
| throw new IllegalStateException("You are required to specify the unleash appName"); | ||
|
|
@@ -172,6 +175,7 @@ private UnleashConfig( | |
| this.clientSpecificationVersion = | ||
| UnleashProperties.getProperty("client.specification.version"); | ||
| this.startupExceptionHandler = startupExceptionHandler; | ||
| this.impactMetricsRegistry = impactMetricsRegistry; | ||
| } | ||
|
|
||
| public static Builder builder() { | ||
|
|
@@ -352,6 +356,11 @@ public Proxy getProxy() { | |
| return proxy; | ||
| } | ||
|
|
||
| @Nullable | ||
| public ImpactMetricsDataSource getImpactMetricsRegistry() { | ||
| return impactMetricsRegistry; | ||
| } | ||
|
|
||
| public MetricSenderFactory getMetricSenderFactory() { | ||
| return this.metricSenderFactory; | ||
| } | ||
|
|
@@ -462,6 +471,7 @@ public static class Builder { | |
| private @Nullable Authenticator proxyAuthenticator; | ||
|
|
||
| private @Nullable Consumer<UnleashException> startupExceptionHandler; | ||
| private @Nullable ImpactMetricsDataSource impactMetricsRegistry; | ||
|
|
||
| private static String getHostname() { | ||
| String hostName = System.getProperty("hostname"); | ||
|
|
@@ -715,6 +725,12 @@ public Builder startupExceptionHandler( | |
| return this; | ||
| } | ||
|
|
||
| public Builder impactMetricsRegistry( | ||
| @Nullable ImpactMetricsDataSource impactMetricsRegistry) { | ||
| this.impactMetricsRegistry = impactMetricsRegistry; | ||
| return this; | ||
| } | ||
|
|
||
| public UnleashConfig build() { | ||
| return new UnleashConfig( | ||
| unleashAPI, | ||
|
|
@@ -749,7 +765,8 @@ public UnleashConfig build() { | |
| toggleBootstrapProvider, | ||
| proxy, | ||
| proxyAuthenticator, | ||
| startupExceptionHandler); | ||
| startupExceptionHandler, | ||
| impactMetricsRegistry); | ||
| } | ||
|
|
||
| public String getDefaultSdkVersion() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linting