-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid final garbage value from Fetch() #13
base: master
Are you sure you want to change the base?
Conversation
I'm not 100% certain this is the right fix for everyone- I haven't checked the librrd api or anything, but at least for my use case I always get one garbage value at the end of my Fetch() results. Taking out this "+ 1" makes the data match expectations.
Fetch() calls the C function rrd_fetch_r() in rrdtool In rrd_fetch_fn(), one malloc() is called for allocating a memory for two dimensional data Since we are mapping Values []float64 in FetchResult to the malloc'ed memory, Lines 396 to 405 in f3b7823
Lines 444 to 451 in f3b7823
I skimmed the rrd_fetch_fn() source code, I think you can skip reading the last data without this pull request. |
Sure, you can skip reading the last data if you know about the problem. There is a workaround. But handing back uninitialized values is usually not considered great library behavior. |
I checked the rrdtutorial example The tutorial saids
Since Fetch() is meant to get the same result as rrdfetch, I think it's OK as it is. |
I wasn't getting NaN, though. I was getting random garbage values. |
this may be convincing: t.go package main
import (
"fmt"
"os"
"strconv"
"time"
"github.com/ziutek/rrd"
)
func main() {
start, _ := strconv.Atoi(os.Args[2])
end, _ := strconv.Atoi(os.Args[3])
result, err := rrd.Fetch(os.Args[1], "AVERAGE", time.Unix(int64(start), 0),
time.Unix(int64(end), 0), time.Second)
if err != nil {
panic(err)
}
for i := 0; i < result.RowCnt; i++ {
fmt.Printf(" %d: %.10e\n",
result.Start.Add(time.Duration(i+1)*result.Step).Unix(),
result.ValueAt(0, i))
}
} output of rrdtool fetch on the test.rrd from the rrdtutorial example:
output of test program 't':
..and in some cases (not yet sure which) the last value is something besides 0.0. |
@thepaul Yes, I'm convinced now. Could you test your pull request for a case with dsCnt > 1? |
I'm not 100% certain this is the right fix for everyone- I haven't
checked the librrd api or anything, but at least for my use case I
always get one garbage value at the end of my Fetch() results. Taking
out this "+ 1" makes the data match expectations.