github.com/lulzWill/go-agent@v2.1.2+incompatible/internal/apdex.go (about)

     1  package internal
     2  
     3  import "time"
     4  
     5  // ApdexZone is a transaction classification.
     6  type ApdexZone int
     7  
     8  // https://en.wikipedia.org/wiki/Apdex
     9  const (
    10  	ApdexNone ApdexZone = iota
    11  	ApdexSatisfying
    12  	ApdexTolerating
    13  	ApdexFailing
    14  )
    15  
    16  // ApdexFailingThreshold calculates the threshold at which the transaction is
    17  // considered a failure.
    18  func ApdexFailingThreshold(threshold time.Duration) time.Duration {
    19  	return 4 * threshold
    20  }
    21  
    22  // CalculateApdexZone calculates the apdex based on the transaction duration and
    23  // threshold.
    24  //
    25  // Note that this does not take into account whether or not the transaction
    26  // had an error.  That is expected to be done by the caller.
    27  func CalculateApdexZone(threshold, duration time.Duration) ApdexZone {
    28  	if duration <= threshold {
    29  		return ApdexSatisfying
    30  	}
    31  	if duration <= ApdexFailingThreshold(threshold) {
    32  		return ApdexTolerating
    33  	}
    34  	return ApdexFailing
    35  }
    36  
    37  func (zone ApdexZone) label() string {
    38  	switch zone {
    39  	case ApdexSatisfying:
    40  		return "S"
    41  	case ApdexTolerating:
    42  		return "T"
    43  	case ApdexFailing:
    44  		return "F"
    45  	default:
    46  		return ""
    47  	}
    48  }