Skip to content
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

Add UserAgents.of(UserAgent, Iterable<Agent>) #902

Merged
merged 3 commits into from
Oct 4, 2022
Merged

Conversation

schlosna
Copy link
Contributor

@schlosna schlosna commented Oct 1, 2022

Before this PR

Creating a UserAgent with multiple additional informational agents required several immutable object creations. See palantir/dialogue#1797 for example

After this PR

==COMMIT_MSG==
Add UserAgents.of(UserAgent, Iterable)
==COMMIT_MSG==

Possible downsides?

@changelog-app
Copy link

changelog-app bot commented Oct 1, 2022

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Add UserAgents.of(UserAgent, Iterable)

Check the box to generate changelog(s)

  • Generate changelog entry

// Should never hit the following.
throw new SafeIllegalArgumentException(
"Illegal version format. This is a bug", SafeArg.of("version", version()));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably update this to use immutables params and avoid the Agent.Builder altogether

.from(base)
.addAllInformational(additional)
.build();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a bit odd given other factory methods live in the UserAgent class, however those don't take a base UserAgent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good call, not sure why I put it in UserAgents instead of with other factories in UserAgent.

I'm not sure if using @Value.Parameter buys us a ton in terms of either few allocations or readability as we don't currently include Guava in the service-config module, so no cheap Iterables.concat:

    static UserAgent of(UserAgent base, Iterable<Agent> additional) {
        return ImmutableUserAgent.of(
                base.nodeId(),
                base.primary(),
                Stream.concat(base.informational().stream(), StreamSupport.stream(additional.spliterator(), false))
                        .collect(Collectors.toList()));
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right -- lgtm!

@carterkozak
Copy link
Contributor

👍

@bulldozer-bot bulldozer-bot bot merged commit 11238a5 into develop Oct 4, 2022
@bulldozer-bot bulldozer-bot bot deleted the ds/agents branch October 4, 2022 15:21
@svc-autorelease
Copy link
Collaborator

Released 2.29.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants