Ejemplo n.º 1
0
        /*
         * Two methods below, Equals and GetHashCode, should be used instead of generated in ClusterMetrics.Messages.g.cs
         * file. Since we do not have an option to not generate those methods for this particular class,
         * just stip them from generated code and paste here, with adding Address property check
         */


        /// <inheritdoc />
        public bool Equals(NodeMetrics other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }
            return(Equals(Address, other.Address));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the most recent data.
        /// </summary>
        public NodeMetrics Merge(NodeMetrics that)
        {
            if (!Address.Equals(that.Address))
            {
                throw new ArgumentException(nameof(that), $"merge only allowed for same address, {Address} != {that.Address}");
            }

            if (Timestamp >= that.Timestamp)
            {
                return(this); // that is order
            }
            return(new NodeMetrics(Address, that.Timestamp, that.Metrics.Union(Metrics)));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the most recent data with <see cref="Types.EWMA"/> averaging.
        /// </summary>
        public NodeMetrics Update(NodeMetrics that)
        {
            if (!Address.Equals(that.Address))
            {
                throw new ArgumentException(nameof(that), $"merge only allowed for same address, {Address} != {that.Address}");
            }

            // Apply sample ordering
            var(latestNode, currentNode) = Timestamp >= that.Timestamp ? (this, that) : (that, this);

            // Average metrics present in both latest and current.
            var updated = latestNode.Metrics
                          .SelectMany(latest => currentNode.Metrics.Select(current => (Latest: latest, Current: current)))
                          .Where(pair => pair.Latest.SameAs(pair.Current))
                          .Select(pair => pair.Current + pair.Latest)
                          .ToList();

            // Append metrics missing from either latest or current.
            // Equality is based on the metric's name
            var merged = updated.Union(latestNode.Metrics).Union(currentNode.Metrics);

            return(new NodeMetrics(Address, latestNode.Timestamp, merged));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns true if <code>that</code> address is the same as this
 /// </summary>
 public bool SameAs(NodeMetrics that) => Address.Equals(that.Address);