Skip to content

Commit

Permalink
Add 'negative' value type for negative events
Browse files Browse the repository at this point in the history
  • Loading branch information
joanlopez committed Mar 20, 2024
1 parent f27cca5 commit dd70e22
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
14 changes: 8 additions & 6 deletions js/summary.js
Expand Up @@ -230,12 +230,14 @@ function nonTrendMetricValueForSum(metric, timeUnit) {
'min=' + humanizeValue(metric.values.min, metric, timeUnit),
'max=' + humanizeValue(metric.values.max, metric, timeUnit),
]
case 'rate':
return [
humanizeValue(metric.values.rate, metric, timeUnit),
succMark + ' ' + metric.values.passes,
failMark + ' ' + metric.values.fails,
]
case 'rate':
const passesMark = metric.contains === 'negative' ? failMark : succMark;
const failsMark = metric.contains === 'negative' ? succMark : failMark;
return [
humanizeValue(metric.values.rate, metric, timeUnit),
passesMark + ' ' + metric.values.passes,
failsMark + ' ' + metric.values.fails,
]
default:
return ['[no data]']
}
Expand Down
2 changes: 1 addition & 1 deletion metrics/builtin.go
Expand Up @@ -87,7 +87,7 @@ func RegisterBuiltinMetrics(registry *Registry) *BuiltinMetrics {
GroupDuration: registry.MustNewMetric(GroupDurationName, Trend, Time),

HTTPReqs: registry.MustNewMetric(HTTPReqsName, Counter),
HTTPReqFailed: registry.MustNewMetric(HTTPReqFailedName, Rate),
HTTPReqFailed: registry.MustNewMetric(HTTPReqFailedName, Rate, Negative),
HTTPReqDuration: registry.MustNewMetric(HTTPReqDurationName, Trend, Time),
HTTPReqBlocked: registry.MustNewMetric(HTTPReqBlockedName, Trend, Time),
HTTPReqConnecting: registry.MustNewMetric(HTTPReqConnectingName, Trend, Time),
Expand Down
7 changes: 4 additions & 3 deletions metrics/metric_type.go
Expand Up @@ -22,9 +22,10 @@ const (
trendString = "trend"
rateString = "rate"

defaultString = "default"
timeString = "time"
dataString = "data"
defaultString = "default"
timeString = "time"
dataString = "data"
negativeString = "negative"
)

// MarshalJSON serializes a MetricType as a human readable string.
Expand Down
13 changes: 10 additions & 3 deletions metrics/value_type.go
Expand Up @@ -4,9 +4,10 @@ import "errors"

// Possible values for ValueType.
const (
Default = ValueType(iota) // Values are presented as-is
Time // Values are time durations (milliseconds)
Data // Values are data amounts (bytes)
Default = ValueType(iota) // Values are presented as-is
Time // Values are time durations (milliseconds)
Data // Values are data amounts (bytes)
Negative // Values represent negative events (e.g. failed requests)
)

// ErrInvalidValueType indicates the serialized value type is invalid.
Expand All @@ -33,6 +34,8 @@ func (t ValueType) MarshalText() ([]byte, error) {
return []byte(timeString), nil
case Data:
return []byte(dataString), nil
case Negative:
return []byte(negativeString), nil
default:
return nil, ErrInvalidValueType
}
Expand All @@ -47,6 +50,8 @@ func (t *ValueType) UnmarshalText(data []byte) error {
*t = Time
case dataString:
*t = Data
case negativeString:
*t = Negative
default:
return ErrInvalidValueType
}
Expand All @@ -62,6 +67,8 @@ func (t ValueType) String() string {
return timeString
case Data:
return dataString
case Negative:
return negativeString
default:
return "[INVALID]"
}
Expand Down

0 comments on commit dd70e22

Please sign in to comment.