Skip to content

feat: impact metrics serialization and wiring#340

Merged
sjaanus merged 2 commits intomainfrom
imp-ser
Dec 18, 2025
Merged

feat: impact metrics serialization and wiring#340
sjaanus merged 2 commits intomainfrom
imp-ser

Conversation

@sjaanus
Copy link
Copy Markdown
Contributor

@sjaanus sjaanus commented Dec 17, 2025

Histogram serialization and preparing to send with metrics. Doing the wiring.

Comment on lines +12 to +24
@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;
}
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are adding simple json serializer for Double.POSITIVE_INFINITY.

.registerTypeAdapter(LocalDateTime.class, new DateTimeSerializer())
.registerTypeAdapter(Instant.class, new InstantSerializer())
.registerTypeAdapter(AtomicLong.class, new AtomicLongSerializer())
.registerTypeAdapter(HistogramBucket.class, new HistogramBucketSerializer())
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Register our serializer

new GsonBuilder()
.registerTypeAdapter(LocalDateTime.class, new DateTimeSerializer())
.registerTypeAdapter(AtomicLong.class, new AtomicLongSerializer())
.registerTypeAdapter(HistogramBucket.class, new HistogramBucketSerializer())
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Register serializer.

@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Dec 17, 2025

Pull Request Test Coverage Report for Build 20329778924

Details

  • 24 of 24 (100.0%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+1.1%) to 80.08%

Totals Coverage Status
Change from base Build 20302906375: 1.1%
Covered Lines: 3121
Relevant Lines: 3739

💛 - Coveralls

ClientMetrics(
UnleashConfig config,
@Nullable MetricsBucket bucket,
@Nullable List<CollectedMetric> impactMetrics) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding impact metrics so it can be used in next iterations.

for (Double le : buckets) {
bucketSamples.add(
new HistogramBucket(le, data.buckets.getOrDefault(le, 0L)));
bucketSamples.add(new HistogramBucket(le, data.buckets.getOrDefault(le, 0L)));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linting

@Nullable Authenticator proxyAuthenticator,
@Nullable Consumer<UnleashException> startupExceptionHandler) {
@Nullable Consumer<UnleashException> startupExceptionHandler,
@Nullable ImpactMetricsDataSource impactMetricsRegistry) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Java it is possible to build config by adding custom registry.

import io.getunleash.impactmetrics.HistogramBucket;
import org.junit.jupiter.api.Test;

public class HistogramBucketSerializerTest {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding basic tests to validate our serializer works.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we test this in metrics tests or repo tests as you called it? it will be closer to the Node testing and also you will test the entire behavior including serialization.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another option is to have one broader test that will verify that we registered our serializer and when someone removed the registration accidentally tests will catch it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can theoretically add it when I get to HTTP layer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently moved to metric type test

@sjaanus sjaanus changed the title feat: impact metrics serialization and sending feat: impact metrics serialization and wiring Dec 17, 2025
@kwasniew kwasniew self-requested a review December 18, 2025 08:15
@github-project-automation github-project-automation Bot moved this from New to Approved PRs in Issues and PRs Dec 18, 2025
@sjaanus sjaanus merged commit bad6723 into main Dec 18, 2025
9 checks passed
@sjaanus sjaanus deleted the imp-ser branch December 18, 2025 08:18
@github-project-automation github-project-automation Bot moved this from Approved PRs to Done in Issues and PRs Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants