mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 21:24:05 -08:00
Change nested ifs to a switch
Signed-off-by: Trevor Whitney <trevorjwhitney@gmail.com>
This commit is contained in:
parent
b4e324f637
commit
e3513d1dd2
|
@ -192,23 +192,28 @@ func (h *FloatHistogram) Scale(factor float64) *FloatHistogram {
|
||||||
//
|
//
|
||||||
// This method returns a pointer to the receiving histogram for convenience.
|
// This method returns a pointer to the receiving histogram for convenience.
|
||||||
func (h *FloatHistogram) Add(other *FloatHistogram) *FloatHistogram {
|
func (h *FloatHistogram) Add(other *FloatHistogram) *FloatHistogram {
|
||||||
if other.CounterResetHint != h.CounterResetHint {
|
switch {
|
||||||
// The outcome of adding an increment to a guage histogram will always be a GaugeType
|
case other.CounterResetHint == h.CounterResetHint:
|
||||||
if other.CounterResetHint == GaugeType && h.CounterResetHint != GaugeType {
|
// Adding apples to apples, all good. No need to change anything.
|
||||||
|
case h.CounterResetHint == GaugeType:
|
||||||
|
// Adding something else to a gauge. That's probably OK. Outcome is a gauge.
|
||||||
|
// Nothing to do since the receiver is already marked as gauge.
|
||||||
|
case other.CounterResetHint == GaugeType:
|
||||||
|
// Similar to before, but this time the receiver is "something else" and we have to change it to gauge.
|
||||||
h.CounterResetHint = GaugeType
|
h.CounterResetHint = GaugeType
|
||||||
}
|
case h.CounterResetHint == UnknownCounterReset:
|
||||||
|
// With the receiver's CounterResetHint being "unknown", this could still be legitimate
|
||||||
// This could be legitime if the caller knows what they are doing, but the resulting hint
|
// if the caller knows what they are doing. Outcome is then again "unknown".
|
||||||
// must be UnknownCounterReset.
|
// No need to do anything since the receiver's CounterResetHint is already "unknown".
|
||||||
if other.CounterResetHint == UnknownCounterReset && h.CounterResetHint != GaugeType {
|
case other.CounterResetHint == UnknownCounterReset:
|
||||||
|
// Similar to before, but now we have to set the receiver's CounterResetHint to "unknown".
|
||||||
h.CounterResetHint = UnknownCounterReset
|
h.CounterResetHint = UnknownCounterReset
|
||||||
}
|
default:
|
||||||
|
// All other cases shouldn't actually happen.
|
||||||
// TODO(trevorwhitney): this leaves CounterReset and NotCounterReset. If we have mismatch of
|
// They are a direct collision of CounterReset and NotCounterReset.
|
||||||
// these hints, that cannot be right, and we should raise a warning when possible.
|
// Conservatively set the CounterResetHint to "unknown" and isse a warning.
|
||||||
// if other.CounterResetHint == CounterReset && h.CounterResetHint == NotCounterReset ||
|
h.CounterResetHint = UnknownCounterReset
|
||||||
// other.CounterResetHint == NotCounterReset && h.CounterResetHint == CounterReset {
|
// TODO(trevorwhitney): Actually issue the warning as soon as the plumbing for it is in place
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
otherZeroCount := h.reconcileZeroBuckets(other)
|
otherZeroCount := h.reconcileZeroBuckets(other)
|
||||||
|
|
Loading…
Reference in a new issue