feat(docs): Add Methodology
[csit.git] / docs / content / methodology / trending_methodology / trend_analysis.md
1 ---
2 bookFlatSection: true
3 title: "Trending Analysis"
4 weight: 2
5 ---
6
7 # Trend Analysis
8
9 All measured performance trend data is treated as time-series data
10 that is modeled as a concatenation of groups,
11 within each group the samples come (independently) from
12 the same normal distribution (with some center and standard deviation).
13
14 Center of the normal distribution for the group (equal to population average)
15 is called a trend for the group.
16 All the analysis is based on finding the right partition into groups
17 and comparing their trends.
18
19 ## Anomalies in graphs
20
21 In graphs, the start of the following group is marked as a regression (red
22 circle) or progression (green circle), if the new trend is lower (or higher
23 respectively) then the previous group's.
24
25 ## Implementation details
26
27 ### Partitioning into groups
28
29 While sometimes the samples within a group are far from being distributed
30 normally, currently we do not have a better tractable model.
31
32 Here, "sample" should be the result of single trial measurement, with group
33 boundaries set only at test run granularity. But in order to avoid detecting
34 causes unrelated to VPP performance, the current presentation takes average of
35 all trials within the run as the sample. Effectively, this acts as a single
36 trial with aggregate duration.
37
38 Performance graphs show the run average as a dot (not all individual trial
39 results).
40
41 The group boundaries are selected based on `Minimum Description Length`[^1].
42
43 ### Minimum Description Length
44
45 `Minimum Description Length`[^1] (MDL) is a particular formalization
46 of `Occam's razor`[^2] principle.
47
48 The general formulation mandates to evaluate a large set of models,
49 but for anomaly detection purposes, it is useful to consider
50 a smaller set of models, so that scoring and comparing them is easier.
51
52 For each candidate model, the data should be compressed losslessly,
53 which includes model definitions, encoded model parameters,
54 and the raw data encoded based on probabilities computed by the model.
55 The model resulting in shortest compressed message is the "the" correct model.
56
57 For our model set (groups of normally distributed samples),
58 we need to encode group length (which penalizes too many groups),
59 group average (more on that later), group stdev and then all the samples.
60
61 Luckily, the "all the samples" part turns out to be quite easy to compute.
62 If sample values are considered as coordinates in (multi-dimensional)
63 Euclidean space, fixing stdev means the point with allowed coordinates
64 lays on a sphere. Fixing average intersects the sphere with a (hyper)-plane,
65 and Gaussian probability density on the resulting sphere is constant.
66 So the only contribution is the "area" of the sphere, which only depends
67 on the number of samples and stdev.
68
69 A somehow ambiguous part is in choosing which encoding
70 is used for group size, average and stdev.
71 Different encodings cause different biases to large or small values.
72 In our implementation we have chosen probability density
73 corresponding to uniform distribution (from zero to maximal sample value)
74 for stdev and average of the first group,
75 but for averages of subsequent groups we have chosen a distribution
76 which discourages delimiting groups with averages close together.
77
78 Our implementation assumes that measurement precision is 1.0 pps.
79 Thus it is slightly wrong for trial durations other than 1.0 seconds.
80 Also, all the calculations assume 1.0 pps is totally negligible,
81 compared to stdev value.
82
83 The group selection algorithm currently has no parameters,
84 all the aforementioned encodings and handling of precision is hard-coded.
85 In principle, every group selection is examined, and the one encodable
86 with least amount of bits is selected.
87 As the bit amount for a selection is just sum of bits for every group,
88 finding the best selection takes number of comparisons
89 quadratically increasing with the size of data,
90 the overall time complexity being probably cubic.
91
92 The resulting group distribution looks good
93 if samples are distributed normally enough within a group.
94 But for obviously different distributions (for example
95 `bimodal distribution`[^3]) the groups tend to focus on less relevant factors
96 (such as "outlier" density).
97
98 ## Common Patterns
99
100 When an anomaly is detected, it frequently falls into few known patterns,
101 each having its typical behavior over time.
102
103 We are going to describe the behaviors,
104 as they motivate our choice of trend compliance metrics.
105
106 ### Sample time and analysis time
107
108 But first we need to distinguish two roles time plays in analysis,
109 so it is more clear which role we are referring to.
110
111 Sample time is the more obvious one.
112 It is the time the sample is generated.
113 It is the start time or the end time of the Jenkins job run,
114 does not really matter which (parallel runs are disabled,
115 and length of gap between samples does not affect metrics).
116
117 Analysis time is the time the current analysis is computed.
118 Again, the exact time does not usually matter,
119 what matters is how many later (and how fewer earlier) samples
120 were considered in the computation.
121
122 For some patterns, it is usual for a previously reported
123 anomaly to "vanish", or previously unseen anomaly to "appear late",
124 as later samples change which partition into groups is more probable.
125
126 Dashboard and graphs are always showing the latest analysis time,
127 the compliance metrics are using earlier sample time
128 with the same latest analysis time.
129
130 Alerting e-mails use the latest analysis time at the time of sending,
131 so the values reported there are likely to be different
132 from the later analysis time results shown in dashboard and graphs.
133
134 ### Ordinary regression
135
136 The real performance changes from previously stable value
137 into a new stable value.
138
139 For medium to high magnitude of the change, one run
140 is enough for anomaly detection to mark this regression.
141
142 Ordinary progressions are detected in the same way.
143
144 ### Small regression
145
146 The real performance changes from previously stable value
147 into a new stable value, but the difference is small.
148
149 For the anomaly detection algorithm, this change is harder to detect,
150 depending on the standard deviation of the previous group.
151
152 If the new performance value stays stable, eventually
153 the detection algorithm is able to detect this anomaly
154 when there are enough samples around the new value.
155
156 If the difference is too small, it may remain undetected
157 (as new performance change happens, or full history of samples
158 is still not enough for the detection).
159
160 Small progressions have the same behavior.
161
162 ### Reverted regression
163
164 This pattern can have two different causes.
165 We would like to distinguish them, but that is usually
166 not possible to do just by looking at the measured values (and not telemetry).
167
168 In one cause, the real DUT performance has changed,
169 but got restored immediately.
170 In the other cause, no real performance change happened,
171 just some temporary infrastructure issue
172 has caused a wrong low value to be measured.
173
174 For small measured changes, this pattern may remain undetected.
175 For medium and big measured changes, this is detected when the regression
176 happens on just the last sample.
177
178 For big changes, the revert is also immediately detected
179 as a subsequent progression. The trend is usually different
180 from the previously stable trend (as the two population averages
181 are not likely to be exactly equal), but the difference
182 between the two trends is relatively small.
183
184 For medium changes, the detection algorithm may need several new samples
185 to detect a progression (as it dislikes single sample groups),
186 in the meantime reporting regressions (difference decreasing
187 with analysis time), until it stabilizes the same way as for big changes
188 (regression followed by progression, small difference
189 between the old stable trend and last trend).
190
191 As it is very hard for a fault code or an infrastructure issue
192 to increase performance, the opposite (temporary progression)
193 almost never happens.
194
195 ### Summary
196
197 There is a trade-off between detecting small regressions
198 and not reporting the same old regressions for a long time.
199
200 For people reading e-mails, a sudden regression with a big number of samples
201 in the last group means this regression was hard for the algorithm to detect.
202
203 If there is a big regression with just one run in the last group,
204 we are not sure if it is real, or just a temporary issue.
205 It is useful to wait some time before starting an investigation.
206
207 With decreasing (absolute value of) difference, the number of expected runs
208 increases. If there is not enough runs, we still cannot distinguish
209 real regression from temporary regression just from the current metrics
210 (although humans frequently can tell by looking at the graph).
211
212 When there is a regression or progression with just a small difference,
213 it is probably an artifact of a temporary regression.
214 Not worth examining, unless temporary regressions happen somewhat frequently.
215
216 It is not easy for the metrics to locate the previous stable value,
217 especially if multiple anomalies happened in the last few weeks.
218 It is good to compare last trend with long term trend maximum,
219 as it highlights the difference between "now" and "what could be".
220 It is good to exclude last week from the trend maximum,
221 as including the last week would hide all real progressions.
222
223 [^1]: [Minimum Description Length](https://en.wikipedia.org/wiki/Minimum_description_length)
224 [^2]: [Occam's razor](https://en.wikipedia.org/wiki/Occam%27s_razor)
225 [^3]: [bimodal distribution](https://en.wikipedia.org/wiki/Bimodal_distribution)