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 'negative' value type for negative events #3656

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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