-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Separate Metrics business and wire format models #7067
Separate Metrics business and wire format models #7067
Conversation
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.
Self review
public MetricsGossip Gossip { get; } | ||
|
||
public bool Reply { get; } | ||
|
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.
Added missing fields that, before, came from the protobuf generated code
@@ -130,7 +128,7 @@ public override string Manifest(object o) | |||
|
|||
private byte[] AdaptiveLoadBalancingPoolToBinary(Metrics.AdaptiveLoadBalancingPool pool) | |||
{ | |||
var proto = new AdaptiveLoadBalancingPool() | |||
var proto = new Proto.AdaptiveLoadBalancingPool() |
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.
Moved the protobuf generated codes to a new namespace, hence the change.
public sealed class EWMA: IEquatable<EWMA> | ||
{ | ||
public double Value { get; } | ||
|
||
public double Alpha { get; } | ||
|
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.
Added equality code and missing fields
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.
Note that in the old code, IEquatable was implemented by the protobuf generated code. We need to add this back.
@@ -40,15 +37,15 @@ public MetricsGossip(IImmutableSet<NodeMetrics> nodes) | |||
/// </summary> | |||
public MetricsGossip Remove(Actor.Address node) | |||
{ | |||
return new MetricsGossip(Nodes.Where(n => !n.Address.Equals(node)).ToImmutableHashSet()); | |||
return new MetricsGossip(Nodes.Where(n => !n.Address.Equals(node)).ToImmutableHashSet(NodeMetricsComparer.Instance)); |
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.
This is needed so that the immutable hash set will use the comparer to compare hash code and equality between the NodeMetrics.
namespace Akka.Cluster.Metrics.Serialization | ||
{ | ||
internal sealed class NodeMetricsComparer: IEqualityComparer<NodeMetrics> |
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.
This is needed because NodeMetrics only uses the Address property for equality and hash code computation. This is being used internally by MetricGossip ImmutableHashSet property to determine if 2 instances of NodeMetrics are the same or not. ImmutableHashSet first uses the GetHashCode() method to retrieve items, if more than one items are retrieved, it will use the Equals() method to get the more accurate match.
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.
LGTM - this is potentially a bit of a breaking change due to the way we're re-arranging public types but honestly the old coupling to Protobuf'd types was totally unacceptable and I doubt these changes will impact most users, given that the same "types" still exist with the same public members now.
Fixes #7065
Changes
Akka.Cluster.Metrics.Serialization.Proto
namespaceChecklist
For significant changes, please ensure that the following have been completed (delete if not relevant):