-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
add modification_time field to filestat input plugin #3305
Conversation
Sounds like we need to add an interface and mock globpath. I also wonder if we should use a different format for the time, other options I can think of are unixnano |
if fileInfo == nil { | ||
return 0 | ||
} else { | ||
return fileInfo.ModTime().Unix() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about providing precision greater than 1s?
@phemmer Do you think we should use UnixNano format here? Floats are easier to read IMO but not as accurate? |
That would make sense to me (using |
Let's make that change too then @puckpuck |
updated to use UnixNano() ... let me know if you need anything else |
"exists": int64(1), | ||
"size_bytes": int64(0), | ||
"exists": int64(1), | ||
"modification_time": int64(getModificationTime(fs, tags1["file"])), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use acc.HasInt64Field(
to assert that the field is set, then you can remove the getModificationTime function. This will be good enough for now in my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping you wouldn't ask for something like that 😉
means I need to modify each test case to assert all fields individually, because acc.AssertContainsTaggedFields(...)
will fail now. Hence why I did the getModificationTime function... required fewer changes to implement.
Test each field individually and modification_time is an int64 when exists is 1
Updated to test each field individually and modification_time is an int64 if the file exists. I think this looks kinda ugly, happy to revert it back, change something else, or leave it as is. |
It is too bad from a naming perspective that In the meantime I added HasPoint and converted filestat_test.go, sorry about all the conflicts but I think this will allow the tests to be reasonable. |
This is helping, but still have the issue that I don't have a way to test an accumulator that it contains an int64 field, for a specific set of tags. Given this test set:
The first 2 files should have a modification_time but the 3rd should not, however Not wanting to make this become such a monumental task for testing, I decided to break it out into 2 more unit test. Each will test for a single file only, first one should have the field, the second should not. |
Required for all PRs:
Adds a modification_time field to filestat. Fixes #2116
I'm not particularly fond of the way unit tests has to work for this. Because the modification time will change based on when you fetch from git, there is no easy way to unit test this. My solution was to create a function which is leveraged by each unit test to set the expected modification time to that of the actual file. If this approach isn't acceptable, I'm happy to change it to something else.