-
Notifications
You must be signed in to change notification settings - Fork 92
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: only load config and rules once #1470
Conversation
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.
Personally, I think I would have done it differently by keeping the io.ReadCloser abstraction but changing it to a io.ReadSeekerCloser so it could be reset to the beginning to re-read it. I believe this would have been a smaller change, but also, I think what you did here is fine and don't need to force you to change it.
However, because Reader is a well-known abstraction in Go with a specific meaning, and this is no longer one of those, if you prefer to do it this way, I'd like to change the name used in all these functions. Instead of getReaderFor, maybe getDataBufferFor? or getContentsFor? And similarly for other functions and the new type you created.
Also, there are a couple of wrong comments now. (Like, "we read the file twice").
I didn't know about |
Reopenning because I would've had to make my own implementation of |
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.
Thank you! I'm happy now.
Which problem is this PR solving?
We found an issue where refinery, as part of its config load process on startup or reload, would load the config/rules (whether from file or http or any), multiple times. This was happening because we the config data was passed around as a reader and if we ever needed the data a second time (which we do for validation vs unmarshaling into config) we had to go get another reader.
Short description of the changes
newFileConfig
to first grab the data of all config locations and the use this data for all validation and unmarshalling. This preventsnewFileConfig
from needing to grab the data multiple times