-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix: Pad milliseconds with three zeroes #1
Conversation
Hi there. I caught this in my inbox but can't look at it until later. I had a frustrating time with the upstream in the past, so I'm happy to help here. However, I've been very distant from this code and don't understand the full ramifications of a change here. It seems absolutely correct that if the value being produced is milliseconds, then "35 milliseconds" should be ".035"; but I'll have to re-read the code and associated specs to determine whether the decimal is supposed to be two digits. In other words, is the correct output here ".03" or ".035"? Since you've been running this down, if you have any reasoning or references here to help me arrive at an answer easier, I'd appreciate it :) |
Great question! If I'm reading the spec correctly, it appears to allow anywhere from 1 - 6 digits of precision after the decimal point (based on the rule format from https://datatracker.ietf.org/doc/html/rfc5234#section-3.6):
(https://datatracker.ietf.org/doc/html/rfc5424#section-6) While two digits of precision is probably valid, three seems to be more common from what I've seen in other libraries that support RFC 5424 such as log4j2. There's even an example in the spec for milliseconds:
(https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.3.1) Interestingly enough, I also just ran across this in the spec which addresses this specific bug:
(https://datatracker.ietf.org/doc/html/rfc5424#appendix-A.4) Hope that helps! |
So, weirdly, RFC3339 (what the function says it generates) says I would however like to avoid using Also, if there are no tests here that break on the new code, there should be at least one new test. |
I skimmed RFC3339, but then I saw this in RFC5424, after which point I focused on that RFC instead:
(https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.3)
If it was just me I'd probably just replace the whole thing with
(https://github.com/myndzi/glossy/blob/master/lib/glossy/produce.js#L356-L357) While going down the rabbit hole I ran across this commit, which I think makes the change in a more backwards-compatible manner (should support Node >= 0.10) and also fixes a couple other minor issues in this same method: So maybe I'll see if I can rebase that on your repo.
💯 |
Yeah, it's more a sort of economy of work vs expectation for me. Generally speaking if it doesn't take a lot of effort and the library is broadly useful, I try to keep compatibility as far back as possible. It's unclear what the correct semver thing to do would be since this isn't exactly a breaking change in the package's API, but it very much feels like a patch version bump -- and I hate it when things break on me unexpectedly :)
Sounds good! |
Since this isn't version 1.0 yet, I think there's some flexibility:
(https://semver.org/#spec-item-4) But I think see what you mean; on the one hand this is a fix (i.e. "patch") on the other it could be seen as a breaking change (i.e. major). Since it's < 1.0 you could split the difference and bump the minor version 🤷♂️ I don't have a strong opinion either way (not that you're asking for it 😄) |
This is unrelated, but if you'd like I could also make some other quality-of-life improvements as I run across them. Off the top of my head:
|
…g protocol In contrast to original fix by @rcrichton: Fixed getFullYear instead of getUTCFullYear (would be an issues around the New Year's Eve). Fixed zero-padding of getMilliseconds value (getMilliseconds() returning 8 means xxx.008, not xxx.8). More efficient calculation of the offset (no more loops).
Math.abs, Math.foor, and Number.prototype.toFixed all require Node 0.10.0 or greater
5171a4c
to
8e39e0a
Compare
Sure :) I don't have any real intent to "maintain" this actively as an alternative to the upstream repo, but I'm happy to respond to any requests and keep a published version available, etc. Those sound like reasonable changes. Edit: I'll be at work for some while yet, but can merge and publish this later |
This way the correct URL will be used in the NPM registry (https://www.npmjs.com/package/@myndzi/glossy)
Cool, sounds good. I would typically open separate PRs for separate "changes" but the package.json stuff should be very trivial and the GitHub Actions would actually be relevant because it will run the tests for this bug, so if it's okay with you I'll just make more commits to this PR. |
Works for me :) Might as well include a patch version bump too, since that'll be necessary to publish the changes anyway |
- Set branch name (-branch is only for templates) - Add all desired supported node versions - Add link to upstream template for reference
npm ci doesn't exist on really old versions of Node, and since this package doesn't have any dependencies we don't need it anyway. Remove npm run build too while we're at it.
It's causing errors, I guess because this package has no dependencies, there's nothing to cache? This is the error: 'Error: Cache folder path is retrieved for npm but doesn't exist on disk: /home/runner/.npm'
Ok, I think I'm all done. I tried to keep the package.json changes to a minimum (by my standards 😆) |
Thanks a lot :) Hopefully this is useful to more folks! Just published to NPM |
Awesome, thanks so much! |
Hi!
You happen to have the only fork of
glossy
that's been published to NPM, so I'm hoping you'd be willing to merge this fix and publish a new release.The milliseconds were padded only with two zeroes, e.g.
Unfortunately Graylog parses
15:52:35.35
as15:52:35.350
instead of15:52:35.035
, so this fixes that.Here's a related issue with more details: winstonjs/winston-syslog#139
Thanks!