feat(placeholder): Adds age() function for timestamp evaluation in placeholders#1550
feat(placeholder): Adds age() function for timestamp evaluation in placeholders#1550jkellerer wants to merge 7 commits intoTwiN:masterfrom
age() function for timestamp evaluation in placeholders#1550Conversation
|
Something doesn't seem to be working. According to the documentation of that dateparse thing, timestamps should work. However, for an endpoint that returns However, it should be only a difference of 92036 and hence an age of 1m32s which is <5m! |
5695dbe to
1d02bfd
Compare
|
@CherryDT: Just enhanced the tests to cover 3 variants of unix timestamps (and the tests succeeded). While time without zone or offset is interpreted as local time, this doesn't matter for unix timestamps which are UTC by definition (and the new tests cover this). 6377274 is 106 minutes... this doesn't seem to be explainable by timezone issues. Could it be that clocks are out of sync? E.g. the following test covers your example from above and succeeds: d228f92 |
1d02bfd to
bfbfe93
Compare
|
Hm, no, the times are fine, I also added a "check" for the raw value to see what is being compared, and it does not make sense. Time on the server is OK: Should be only 2m difference: Also I think that number 6377010 is strange for another reason because other time values show in hours and minutes, why does age not? |
|
Try yourself with this check: - name: timestamp-test
interval: 10s
url: "https://time.jakcodex.io/api/time"
conditions:
- "age([BODY].epoch) < 5m"
- "[BODY].epoch > 0"
ui:
resolve-successful-conditions: trueThe "Timestamp" text displayed above is in my local browser time, which is UTC+1, so that would be 10:19:05 UTC = 1771582745000 which is correct. If you compare this to 1771582745811, you get a difference of 811 and not again 6377010. (Noteworthy: Here we again get 6377010 even though now the timestamp is the current time, while before it was a few minutes behind... I mean, this time the real age should have been <1s, before it was 92s, 120s, etc., yet the output is still 6377010 or just a few milliseconds above or below it, so it can't be a simple offset!) |
|
I found the problem and fixed it here: jkellerer#1 |
Make timestamps coming from a number field work with age function
44a0121 to
c5da861
Compare
|
@CherryDT thanks a lot for the fix. I've merged it and integrated the changes in the already existing block to deal with formats the library doesn't parse directly. |
|
The following could be a showstopper: markusmobius/go-dateparser#20 Maybe the parsing lib needs to be switched or made optional. |
|
Hm, true... for me it's OK but it could be a problem elsewhere... We don't need so many variations though, I feel like 95% of the use cases would be covered by just being able to parse UNIX timestamps in seconds or milliseconds (assuming seconds if the value is small enough - if this causes an issue for dates before February 1970, we'd need to allow selecting which one it is) and ISO8601 (note this, we probably have to use both). We could allow specifying a custom format if needed, just using |
|
@CherryDT , yes I think the same. I'm about to update the PR with own parsing of the most common formats. Basically allow the ones we have in the test but remove the relative and localised. |
- Refactored `parseAge` to support durations, unix timestamps and custom layouts directly. - Added `dateparser.go` to handle date parsing with regex and custom formats. - Modified tests in `placeholder_test.go` to reflect all changes. - Removed external dependencies.
|
@CherryDT , is the updated implementation working for you? |
Yes it works, thanks! |
|
@TwiN, could you please share your thoughts on this PR? I think it would be a really useful addition to Gatus. |
Summary
#916
Implemented using https://github.com/markusmobius/go-dateparser as it parses the most common timestamp formats thus we don't need to specify a pattern for parsing.Implemented without any 3rd party dependencies
Supported formats:
int64&float64, seconds or milliseconds) e.g.:1771235569,17712355691231,17712355691.231&1.7712355691231e12Checklist
README.md, if applicable.