Browse Source

Fix process.go processing the oldest datapoint instead of the most recent

Brendan Abolivier 7 years ago
parent
commit
7aa7dbb9c2
Signed by: Brendan Abolivier <contact@brendanabolivier.com> GPG key ID: 8EF1500759F70623
1 changed files with 3 additions and 4 deletions
  1. 3
    4
      src/metrics-alerting/process/process.go

+ 3
- 4
src/metrics-alerting/process/process.go View File

103
 	data script_data.Data,
103
 	data script_data.Data,
104
 ) error {
104
 ) error {
105
 	series, err := client.ReadSeriesOfNumbers(script.Script)
105
 	series, err := client.ReadSeriesOfNumbers(script.Script)
106
-
107
 	for _, serie := range series {
106
 	for _, serie := range series {
108
-		if !isRecentEnough(serie.Datapoints[0]) {
107
+		mostRecentDataPoint := serie.Datapoints[len(serie.Datapoints)-1]
108
+		if !isRecentEnough(mostRecentDataPoint) {
109
 			// If the serie hasn't been active in the last 10min, don't consider
109
 			// If the serie hasn't been active in the last 10min, don't consider
110
 			// it
110
 			// it
111
 			// TODO: If the serie was active at the previous run, send an alert
111
 			// TODO: If the serie was active at the previous run, send an alert
122
 		// to find when the situation began so we can add info about time in the
122
 		// to find when the situation began so we can add info about time in the
123
 		// alert.
123
 		// alert.
124
 		if err = processFloat(
124
 		if err = processFloat(
125
-			serie.Datapoints[0][1], script, alerter, serie.Labels, data,
125
+			mostRecentDataPoint[1], script, alerter, serie.Labels, data,
126
 		); err != nil {
126
 		); err != nil {
127
 			return err
127
 			return err
128
 		}
128
 		}
157
 	now := time.Now().UnixNano() / 1000 // Current timestamp (seconds)
157
 	now := time.Now().UnixNano() / 1000 // Current timestamp (seconds)
158
 
158
 
159
 	return now-int64(datapoint[0]) <= allowedOffset
159
 	return now-int64(datapoint[0]) <= allowedOffset
160
-	return false
161
 }
160
 }