5 // TrustMetricConfig - Configures the weight functions and time intervals for the metric
6 type TrustMetricConfig struct {
7 // Determines the percentage given to current behavior
8 ProportionalWeight float64
10 // Determines the percentage given to prior behavior
11 IntegralWeight float64
13 // The window of time that the trust metric will track events across.
14 // This can be set to cover many days without issue
15 TrackingWindow time.Duration
17 // Each interval should be short for adapability.
18 // Less than 30 seconds is too sensitive,
19 // and greater than 5 minutes will make the metric numb
20 IntervalLength time.Duration
23 // DefaultConfig returns a config with values that have been tested and produce desirable results
24 func DefaultConfig() TrustMetricConfig {
25 return TrustMetricConfig{
26 ProportionalWeight: 0.4,
28 TrackingWindow: (time.Minute * 60 * 24) * 14, // 14 days.
29 IntervalLength: 1 * time.Minute,
33 // Ensures that all configuration elements have valid values
34 func customConfig(tmc TrustMetricConfig) TrustMetricConfig {
35 config := DefaultConfig()
37 // Check the config for set values, and setup appropriately
38 if tmc.ProportionalWeight > 0 {
39 config.ProportionalWeight = tmc.ProportionalWeight
42 if tmc.IntegralWeight > 0 {
43 config.IntegralWeight = tmc.IntegralWeight
46 if tmc.IntervalLength > time.Duration(0) {
47 config.IntervalLength = tmc.IntervalLength
50 if tmc.TrackingWindow > time.Duration(0) &&
51 tmc.TrackingWindow >= config.IntervalLength {
52 config.TrackingWindow = tmc.TrackingWindow