Skip to content

Commit

Permalink
Fix bug converting astronomy events to prom response
Browse files Browse the repository at this point in the history
  • Loading branch information
tedpearson committed Oct 2, 2023
1 parent 00a64b2 commit 85ec515
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func MakeForecasters(enabled []string, cacheDir string, vcKey string) map[string
}

// todo
// deployment stuff
// grafana dashboards
// make influx forwarded token and our required auth token allowed to be different
// update readme
Expand Down
14 changes: 12 additions & 2 deletions prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (pc PromConverter) GetMetric(forecast source.Forecast, metric string) []Met
}
points[i] = Metric{
Timestamp: record.Time.Unix(),
Metric: field.Elem().Interface().(float64),
Metric: ValueToFloat(field.Elem()),
}
}
return points
Expand All @@ -119,10 +119,20 @@ func (pc PromConverter) GetMetric(forecast source.Forecast, metric string) []Met
}
points[i] = Metric{
Timestamp: record.Time.Unix(),
Metric: field.Elem().Interface().(float64),
Metric: ValueToFloat(field.Elem()),
}
}
return points
}
return nil
}

func ValueToFloat(value reflect.Value) float64 {
if value.CanInt() {
return float64(value.Int())
}
if value.CanFloat() {
return value.Float()
}
return 0
}

0 comments on commit 85ec515

Please sign in to comment.