forked from newrelic/go-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapdex.go
51 lines (44 loc) · 1.15 KB
/
apdex.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package internal
import "time"
// ApdexZone is a transaction classification.
type ApdexZone int
// https://en.wikipedia.org/wiki/Apdex
const (
ApdexNone ApdexZone = iota
ApdexSatisfying
ApdexTolerating
ApdexFailing
)
// ApdexFailingThreshold calculates the threshold at which the transaction is
// considered a failure.
func ApdexFailingThreshold(threshold time.Duration) time.Duration {
return 4 * threshold
}
// CalculateApdexZone calculates the apdex based on the transaction duration and
// threshold.
//
// Note that this does not take into account whether or not the transaction
// had an error. That is expected to be done by the caller.
func CalculateApdexZone(threshold, duration time.Duration) ApdexZone {
if duration <= threshold {
return ApdexSatisfying
}
if duration <= ApdexFailingThreshold(threshold) {
return ApdexTolerating
}
return ApdexFailing
}
func (zone ApdexZone) label() string {
switch zone {
case ApdexSatisfying:
return "S"
case ApdexTolerating:
return "T"
case ApdexFailing:
return "F"
default:
return ""
}
}