-
Notifications
You must be signed in to change notification settings - Fork 5
Client consent screen #225
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
base: main
Are you sure you want to change the base?
Changes from all commits
b9dee91
d6063a1
163e27b
012c781
1eeca9e
24544f6
bf14807
0cfb60c
76c29e3
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 |
|---|---|---|
|
|
@@ -12,9 +12,11 @@ | |
| import java.util.HashSet; | ||
| import java.util.Optional; | ||
| import java.util.Properties; | ||
| import java.util.Set; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.function.Function; | ||
|
|
||
| // todo: revise | ||
|
Member
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. todo still valid: still dont like the impl |
||
| public non-sealed abstract class SimpleContext implements FastStatsContext { | ||
| private final @Token String token; | ||
| private final Config config; | ||
|
|
@@ -24,6 +26,7 @@ public non-sealed abstract class SimpleContext implements FastStatsContext { | |
| private final Logger logger; | ||
|
|
||
| protected volatile boolean ready = false; | ||
| public volatile boolean submissionActive; | ||
|
|
||
| private @Nullable Metrics metrics; | ||
| private @Nullable FeatureFlagService featureFlagService; | ||
|
|
@@ -56,14 +59,33 @@ protected SimpleContext(final Factory<?, ?> factory, final LoggerFactory loggerF | |
|
|
||
| @MustBeInvokedByOverriders | ||
| protected final void initializeServices(final Factory<?, ?> factory) throws IllegalStateException { | ||
| initializeServices(factory, false); | ||
| } | ||
|
|
||
| /** | ||
| * Initializes service descriptions before consent so this context can participate in a live lifecycle registry. | ||
| */ | ||
| @MustBeInvokedByOverriders | ||
| protected final void initializeManagedServices(final Factory<?, ?> factory) throws IllegalStateException { | ||
| initializeServices(factory, true); | ||
| } | ||
|
|
||
| private void initializeServices(final Factory<?, ?> factory, final boolean lifecycleManaged) { | ||
| if (factory.metrics == null && factory.errorTracker == null && factory.featureFlagService == null) | ||
| throw new IllegalStateException("Context created without any service attached, was this intentional?"); | ||
|
|
||
| if (!preSubmissionStart()) return; | ||
| final var start = preSubmissionStart(); | ||
| if (!lifecycleManaged && !start) return; | ||
|
Comment on lines
+77
to
+78
Member
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. guard |
||
|
|
||
| this.metrics = config.submitMetrics() && factory.metrics != null ? factory.metrics.apply(metricsFactory()) : null; | ||
| this.errorTrackerService = config.errorTracking() && factory.errorTracker != null ? new SimpleErrorTrackerService(this, factory.errorTracker) : null; | ||
| if (factory.metrics != null && (lifecycleManaged || config.submitMetrics())) { | ||
| final var metricsFactory = metricsFactory(); | ||
| this.metrics = factory.metrics.apply(metricsFactory); | ||
| } | ||
| this.errorTrackerService = factory.errorTracker != null && (lifecycleManaged || config.errorTracking()) | ||
| ? new SimpleErrorTrackerService(this, factory.errorTracker) | ||
| : null; | ||
| this.featureFlagService = factory.featureFlagService != null ? factory.featureFlagService.apply(new SimpleFeatureFlagService.Factory(this)) : null; | ||
| this.submissionActive = start; | ||
|
|
||
| final var features = new HashSet<String>(3); | ||
| features.add("metrics=" + (metrics != null ? "yes" : "no")); | ||
|
|
@@ -161,6 +183,7 @@ public void shutdown() { | |
| if (errorTrackerService != null) errorTrackerService.shutdown(); | ||
| if (featureFlagService instanceof final SimpleFeatureFlagService service) service.shutdown(); | ||
| if (metrics instanceof final SimpleMetrics simpleMetrics) simpleMetrics.shutdown(); | ||
| this.submissionActive = false; | ||
| ready = false; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,10 @@ | |
| import java.util.HashSet; | ||
| import java.util.Set; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.stream.Stream; | ||
|
|
||
| @ApiStatus.Internal | ||
| // todo: revise | ||
|
Member
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. same here: still sucks |
||
| public abstract class SimpleMetrics extends SubmissionService implements Metrics { | ||
| private static final String COLLECT_PATH = "/v1/collect"; | ||
|
|
||
|
|
@@ -26,7 +28,7 @@ public abstract class SimpleMetrics extends SubmissionService implements Metrics | |
| @Contract(mutates = "io") | ||
| protected SimpleMetrics(final Factory factory) { | ||
| super(factory.context); | ||
| this.metrics = context.getConfig().additionalMetrics() ? Set.copyOf(factory.metrics) : Set.of(); | ||
| this.metrics = Set.copyOf(factory.metrics); | ||
| this.flush = factory.flush; | ||
| } | ||
|
|
||
|
|
@@ -43,6 +45,7 @@ public boolean isClientApplication() { | |
| } | ||
|
|
||
| private boolean submit() { | ||
| if (!context.submissionActive || !context.getConfig().submitMetrics()) return false; | ||
| try { | ||
| if (submit(url, createData(), "metrics")) { | ||
| if (flush != null) flush.run(); | ||
|
|
@@ -78,6 +81,7 @@ private void appendInternalData(final JsonObject metrics) { | |
| } | ||
|
|
||
| private void appendCustomData(final JsonObject metrics) { | ||
| if (!context.getConfig().additionalMetrics()) return; | ||
| this.metrics.forEach(metric -> { | ||
| try { | ||
| if (metrics.has(metric.getId())) { | ||
|
|
@@ -124,6 +128,11 @@ protected void shutdown() { | |
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Stream<Metric<?>> stream() { | ||
| return metrics.stream(); | ||
| } | ||
|
|
||
| public abstract static class Factory implements Metrics.Factory { | ||
| private @Nullable Runnable flush; | ||
| private final Set<Metric<?>> metrics = new HashSet<>(0); | ||
|
|
||
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.
create file