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