fix: make file update atomic, wait for /start#329
Conversation
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Summary of ChangesHello @toddbaert, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the reliability of the launchpad by addressing two key areas: ensuring data integrity during file modifications and improving the robustness of service startup. By introducing atomic file write operations, the system is better protected against partial or corrupted configuration files. Furthermore, the transition to an HTTP health check for Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
| err := StopFlagd() | ||
| if err != nil { | ||
| fmt.Println("could not stop flagd", err) | ||
| // Poll health endpoint until ready |
There was a problem hiding this comment.
The log output we were looking at doesn't actually mean the listening services are running - that statement is printed before the servers are guaranteed to be up.
The healthcheck actually waits until all services are up, so let's use that.
There was a problem hiding this comment.
Code Review
This pull request introduces some good reliability improvements, namely making file writes atomic and implementing a health check poll to wait for flagd to start. My review includes a high-severity fix for the new atomicWriteFile function to make it more robust by handling more error cases and preventing temporary file leaks. I've also added a medium-severity suggestion to improve maintainability by extracting hardcoded values into constants.
| ) | ||
|
|
||
| // writes a file atomically using mv | ||
| func atomicWriteFile(filename string, data []byte) error { |
There was a problem hiding this comment.
This atomically writes the file, so there's never any change of half-written data. We do something similar in OFO.
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Fixes a a few small reliability issues with the launchpad: