@@ -3,7 +3,7 @@ import MetricQHistory from '@metricq/history'
3
3
import Vue from 'vue'
4
4
5
5
export class MetricHandler {
6
- constructor ( paramRenderer , paramMetricsArr , paramStartTime , paramStopTime , store , metricqBackendConfig ) {
6
+ constructor ( paramRenderer , paramStartTime , paramStopTime , store , metricqBackendConfig ) {
7
7
this . store = store
8
8
this . renderer = paramRenderer
9
9
this . startTime = new MetricTimestamp ( paramStartTime , 'start' )
@@ -13,7 +13,7 @@ export class MetricHandler {
13
13
this . WIGGLEROOM_PERCENTAGE = 0.05
14
14
this . TIME_MARGIN_FACTOR = 1.00 / 3
15
15
16
- this . initializeMetrics ( paramMetricsArr )
16
+ this . initializeMetrics ( [ ] )
17
17
}
18
18
19
19
initializeMetrics ( initialMetricNames ) {
@@ -26,14 +26,14 @@ export class MetricHandler {
26
26
27
27
doRequest ( maxDataPoints ) {
28
28
const timeMargin = ( this . stopTime . getUnix ( ) - this . startTime . getUnix ( ) ) * this . TIME_MARGIN_FACTOR
29
- const nonErrorProneMetrics = [ ]
30
- const remainingMetrics = [ ]
29
+ const metrics = [ ]
30
+ const errorProneMetrics = [ ]
31
31
for ( const curMetric of this . store . getters [ 'metrics/getAll' ] ( ) ) {
32
32
if ( curMetric . name . length > 0 ) {
33
33
if ( curMetric . errorprone ) {
34
- remainingMetrics . push ( curMetric . name )
34
+ errorProneMetrics . push ( curMetric . name )
35
35
} else {
36
- nonErrorProneMetrics . push ( curMetric . name )
36
+ metrics . push ( curMetric . name )
37
37
}
38
38
}
39
39
}
@@ -42,32 +42,32 @@ export class MetricHandler {
42
42
this . stopTime . getUnix ( ) + timeMargin ,
43
43
Math . round ( maxDataPoints + ( maxDataPoints * this . TIME_MARGIN_FACTOR * 2 ) ) )
44
44
const defaultAggregates = [ 'min' , 'max' , 'avg' , 'count' ]
45
- for ( let i = 0 ; i < nonErrorProneMetrics . length ; ++ i ) {
46
- queryObj . target ( nonErrorProneMetrics [ i ] , defaultAggregates )
45
+ for ( let i = 0 ; i < metrics . length ; ++ i ) {
46
+ queryObj . target ( metrics [ i ] , defaultAggregates )
47
47
}
48
48
const startTime = window . performance . now ( )
49
49
if ( queryObj . targets . length > 0 ) {
50
50
// TODO: register some callback
51
51
// execute query
52
52
// TODO: pass parameter nonErrorProneMetrics
53
53
queryObj . run ( ) . then ( ( dataset ) => {
54
- this . handleResponse ( nonErrorProneMetrics , dataset , startTime )
54
+ this . handleResponse ( metrics , dataset , startTime )
55
55
} ) . catch ( ( ) => {
56
- console . log ( 'Request failed: ' + nonErrorProneMetrics . join ( ',' ) )
57
- nonErrorProneMetrics . forEach ( ( curVal ) => {
56
+ console . log ( 'Request failed: ' + metrics . join ( ',' ) )
57
+ metrics . forEach ( ( curVal ) => {
58
58
console . log ( 'Marking as faulty: ' + curVal )
59
59
this . receivedError ( 0 , curVal )
60
60
} )
61
61
this . doRequest ( maxDataPoints )
62
62
} )
63
63
}
64
- for ( let i = 0 ; i < remainingMetrics . length ; ++ i ) {
64
+ for ( let i = 0 ; i < errorProneMetrics . length ; ++ i ) {
65
65
const queryObj = this . metricQHistory . query ( this . startTime . getUnix ( ) - timeMargin ,
66
66
this . stopTime . getUnix ( ) + timeMargin ,
67
67
maxDataPoints )
68
- queryObj . target ( remainingMetrics [ i ] , defaultAggregates )
68
+ queryObj . target ( errorProneMetrics [ i ] , defaultAggregates )
69
69
queryObj . run ( ) . then ( ( dataset ) => {
70
- this . handleResponse ( [ remainingMetrics [ i ] ] , dataset , startTime )
70
+ this . handleResponse ( [ errorProneMetrics [ i ] ] , dataset , startTime )
71
71
} )
72
72
}
73
73
}
@@ -77,13 +77,14 @@ export class MetricHandler {
77
77
const listOfFaultyMetrics = [ ]
78
78
let pointCountAgg = null
79
79
let pointCountRaw = 0
80
- for ( let i = 0 ; i < requestedMetrics . length ; ++ i ) {
81
- const metricName = requestedMetrics [ i ]
80
+
81
+ for ( const metric of requestedMetrics ) {
82
82
const matchingAggregatesObj = { }
83
83
let matchingAggregatesCount = 0
84
+
84
85
for ( const curMetricName in myData ) {
85
86
const splitted = curMetricName . split ( '/' )
86
- if ( splitted [ 0 ] === requestedMetrics [ i ] ) {
87
+ if ( splitted [ 0 ] === metric ) {
87
88
matchingAggregatesObj [ splitted [ 1 ] ] = true
88
89
matchingAggregatesCount += 1
89
90
if ( splitted [ 1 ] === 'count' || splitted [ 1 ] === 'raw' ) {
@@ -102,31 +103,31 @@ export class MetricHandler {
102
103
}
103
104
}
104
105
}
105
- if ( ! this . checkIfMetricIsOk ( metricName , matchingAggregatesCount , matchingAggregatesObj ) ) {
106
- listOfFaultyMetrics . push ( metricName )
107
- console . log ( 'Metric not ok:' + metricName )
108
- this . receivedError ( 0 , metricName )
106
+
107
+ if ( ! this . checkIfMetricIsOk ( metric , matchingAggregatesCount , matchingAggregatesObj ) ) {
108
+ listOfFaultyMetrics . push ( metric )
109
+ console . log ( 'Metric not ok:' + metric )
110
+ this . receivedError ( 0 , metric )
109
111
}
110
112
}
113
+
111
114
this . store . commit ( 'setAggregatePoints' , pointCountAgg )
112
115
this . store . commit ( 'setRawPoints' , pointCountRaw )
116
+
113
117
if ( listOfFaultyMetrics . length > 0 ) {
114
- Vue . toasted . error ( 'Fehler mit Metriken : ' + listOfFaultyMetrics . join ( ', ' ) , this . store . state . toastConfiguration )
118
+ Vue . toasted . error ( 'Fehler beim Abfragen von : ' + listOfFaultyMetrics . join ( ', ' ) , this . store . state . toastConfiguration )
115
119
}
120
+
116
121
this . renderer . renderMetrics ( myData , startTime )
117
122
}
118
123
119
124
checkIfMetricIsOk ( metricName , aggregateCount , aggregateObj ) {
120
- if ( ! metricName ||
121
- aggregateCount < 1 ||
122
- ( ! aggregateObj . count && ! aggregateObj . raw ) ) {
123
- return false
124
- }
125
- if ( ! ( ( aggregateObj . raw && ! aggregateObj . min && ! aggregateObj . max ) ||
126
- ( ! aggregateObj . raw && aggregateObj . min && aggregateObj . max ) ) ) {
125
+ if ( ! metricName || aggregateCount < 1 || ( ! aggregateObj . count && ! aggregateObj . raw ) ) {
127
126
return false
128
127
}
129
- return true
128
+
129
+ // we want (raw xor (min and max))
130
+ return aggregateObj . raw !== ( aggregateObj . min && aggregateObj . max )
130
131
}
131
132
132
133
searchMetricsPromise ( inputStr , metadata = false ) {
@@ -135,11 +136,10 @@ export class MetricHandler {
135
136
136
137
// TODO: move this function to DataCache, maybe?
137
138
getAllMinMax ( ) {
138
- const referenceAttribute = 'minmax'
139
139
if ( this . renderer . graticule . yRangeOverride . type === 'manual' ) {
140
140
return [ this . renderer . graticule . yRangeOverride . min , this . renderer . graticule . yRangeOverride . max ]
141
141
}
142
- let allMinMax = [ undefined , undefined ]
142
+ const result = [ Infinity , - Infinity ]
143
143
const timeFrame = this . renderer . graticule . curTimeRange
144
144
for ( const curMetric of this . store . getters [ 'metrics/getAll' ] ( ) ) {
145
145
if ( ! curMetric . draw ) continue
@@ -154,73 +154,50 @@ export class MetricHandler {
154
154
curMinMax = curCache . getAllMinMax ( timeFrame [ 0 ] , timeFrame [ 1 ] )
155
155
}
156
156
if ( curMinMax ) {
157
- if ( undefined === allMinMax [ 0 ] ) {
158
- allMinMax = curMinMax
159
- } else {
160
- if ( curMinMax [ 0 ] < allMinMax [ 0 ] ) {
161
- allMinMax [ 0 ] = curMinMax [ 0 ]
162
- }
163
- if ( curMinMax [ 1 ] > allMinMax [ 1 ] ) {
164
- allMinMax [ 1 ] = curMinMax [ 1 ]
165
- }
157
+ if ( curMinMax [ 0 ] < result [ 0 ] ) {
158
+ result [ 0 ] = curMinMax [ 0 ]
159
+ }
160
+ if ( curMinMax [ 1 ] > result [ 1 ] ) {
161
+ result [ 1 ] = curMinMax [ 1 ]
166
162
}
167
163
}
168
164
}
169
165
}
170
166
// add a little wiggle room, so that markers won't be cut off
171
- const delta = allMinMax [ 1 ] - allMinMax [ 0 ]
172
- allMinMax [ 0 ] -= delta * this . WIGGLEROOM_PERCENTAGE
173
- allMinMax [ 1 ] += delta * this . WIGGLEROOM_PERCENTAGE
174
- return allMinMax
167
+ const delta = result [ 1 ] - result [ 0 ]
168
+ result [ 0 ] -= delta * this . WIGGLEROOM_PERCENTAGE
169
+ result [ 1 ] += delta * this . WIGGLEROOM_PERCENTAGE
170
+ return result
175
171
}
176
172
177
- setTimeRange ( paramStartTime , paramStopTime ) {
178
- // TODO: check for zoom area if it is too narrow (i.e. less than 1000 ms)
179
- // TODO: sync the aforementioned minimum time window
180
- if ( undefined === paramStartTime || paramStartTime instanceof MetricTimestamp ) {
181
- paramStartTime = this . startTime . getUnix ( )
182
- } else {
183
- this . startTime . updateTime ( paramStartTime )
173
+ setTimeRange ( newStartTime , newStopTime ) {
174
+ if ( undefined === newStartTime || newStartTime instanceof MetricTimestamp ) {
175
+ newStartTime = this . startTime . getUnix ( )
184
176
}
185
- if ( undefined === paramStopTime || paramStopTime instanceof MetricTimestamp ) {
186
- paramStopTime = this . stopTime . getUnix ( )
187
- } else {
188
- this . stopTime . updateTime ( paramStopTime )
177
+ if ( undefined === newStopTime || newStopTime instanceof MetricTimestamp ) {
178
+ newStopTime = this . stopTime . getUnix ( )
189
179
}
190
180
191
- if ( isNaN ( paramStartTime ) || isNaN ( paramStopTime ) ) {
181
+ if ( isNaN ( newStartTime ) || isNaN ( newStopTime ) ) {
192
182
throw new Error ( 'uh oh time is NaN' )
193
183
}
194
- if ( paramStartTime >= paramStopTime ) {
195
- throw new Error ( `startTime(${ paramStartTime } ) is not smaller than stopTime(${ paramStopTime } )` )
184
+ if ( newStartTime >= newStopTime ) {
185
+ throw new Error ( `startTime(${ newStartTime } ) is not smaller than stopTime(${ newStopTime } )` )
196
186
}
197
187
198
- let timeSuitable = true
199
- if ( ( paramStopTime - paramStartTime ) < this . renderer . graticule . MIN_ZOOM_TIME ) {
200
- const oldDelta = paramStopTime - paramStartTime
201
- const newDelta = this . renderer . graticule . MIN_ZOOM_TIME
202
- paramStartTime -= Math . round ( ( newDelta - oldDelta ) / 2.00 )
203
- paramStopTime += Math . round ( ( newDelta - oldDelta ) / 2.00 )
204
- timeSuitable = false
188
+ if ( newStopTime - newStartTime < this . renderer . graticule . MIN_ZOOM_TIME ) {
189
+ return false
205
190
}
206
- if ( ( paramStopTime - paramStartTime ) > this . renderer . graticule . MAX_ZOOM_TIME ) {
207
- const oldDelta = paramStopTime - paramStartTime
208
- const newDelta = this . renderer . graticule . MAX_ZOOM_TIME
209
- paramStartTime += Math . round ( ( oldDelta - newDelta ) / 2.00 )
210
- paramStopTime -= Math . round ( ( oldDelta - newDelta ) / 2.00 )
211
- timeSuitable = false
191
+ if ( newStopTime - newStartTime > this . renderer . graticule . MAX_ZOOM_TIME ) {
192
+ return false
212
193
}
213
194
214
- this . renderer . updateMetricUrl ( )
215
- // maybe move this line to MetricQWebView.setPlotRanges()? NAW
216
- window . MetricQWebView . graticule . setTimeRange ( this . startTime . getUnix ( ) , this . stopTime . getUnix ( ) )
217
- return timeSuitable
218
- // this.lastRangeChangeTime = (new Date()).getTime();
219
- // TODO: return false when intended zoom area is smaller than e.g. 1000 ms
220
- // TODO: define a CONSTANT that is MINIMUM_ZOOM_AREA
195
+ this . startTime . updateTime ( newStartTime )
196
+ this . stopTime . updateTime ( newStopTime )
221
197
222
- // TODO: call url export here?
223
- // return true;
198
+ this . renderer . updateMetricUrl ( )
199
+ this . renderer . graticule . setTimeRange ( this . startTime . getUnix ( ) , this . stopTime . getUnix ( ) )
200
+ return true
224
201
}
225
202
226
203
zoomTimeAtPoint ( pointAt , zoomDirection ) {
@@ -237,10 +214,10 @@ export class MetricHandler {
237
214
return couldZoom
238
215
}
239
216
240
- receivedError ( errorCode , metricBase ) {
217
+ receivedError ( _errorCode , metric ) {
241
218
// mark a metric so it is being excluded in bulk-requests
242
- if ( this . store . getters [ 'metrics/get' ] ( metricBase ) ) {
243
- this . store . dispatch ( 'metrics/setError' , { metricKey : metricBase } )
219
+ if ( this . store . getters [ 'metrics/get' ] ( metric ) ) {
220
+ this . store . dispatch ( 'metrics/setError' , { metricKey : metric } )
244
221
}
245
222
}
246
223
0 commit comments