Skip to content

Commit

Permalink
Don't convert a point if it's not valid or is nil, lookback by step t…
Browse files Browse the repository at this point in the history
…o find previous point
  • Loading branch information
tedpearson committed Oct 3, 2023
1 parent 85ec515 commit 0b44ae0
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (pc PromConverter) ConvertToTimeSeries(forecast source.Forecast, params Par
i = j
break
}
if p.Timestamp == ts || (p.Timestamp < ts && p.Timestamp+3600 > ts) {
if p.Timestamp == ts || (p.Timestamp < ts && p.Timestamp+params.Step > ts) {
i = j
v := []any{ts, fmt.Sprintf("%f", p.Metric)}
values = append(values, v)
Expand All @@ -95,16 +95,19 @@ func (pc PromConverter) GetMetric(forecast source.Forecast, metric string) []Met
parts := strings.SplitN(metric, "_", 2)
name := strcase.ToCamel(parts[1])
if parts[0] == pc.AstronomyMeasurementName {
points := make([]Metric, len(forecast.AstroEvents))
for i, record := range forecast.AstroEvents {
points := make([]Metric, 0, len(forecast.AstroEvents))
for _, record := range forecast.AstroEvents {
field := reflect.ValueOf(record).FieldByName(name)
if !field.IsValid() {
return nil
}
points[i] = Metric{
if !field.Elem().IsValid() {
continue
}
points = append(points, Metric{
Timestamp: record.Time.Unix(),
Metric: ValueToFloat(field.Elem()),
}
})
}
return points
} else if parts[0] == pc.ForecastMeasurementName {
Expand Down

0 comments on commit 0b44ae0

Please sign in to comment.