-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Subprocess manager and its tests for the prometheus_exec Receiver #499
Subprocess manager and its tests for the prometheus_exec Receiver #499
Conversation
Codecov Report
@@ Coverage Diff @@
## master #499 +/- ##
==========================================
- Coverage 86.03% 86.01% -0.02%
==========================================
Files 187 188 +1
Lines 10142 10193 +51
==========================================
+ Hits 8726 8768 +42
- Misses 1093 1098 +5
- Partials 323 327 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
Overall this PR looks good. Mostly only minor suggestions.
However, I would recommend starting with a PR that adds the Receiver skeleton and a shell for the manager that just does nothing rather than starting with this manager. You will likely need an interface + mock implementation of the manager anyway in order to write tests and get your test coverage up.
It's usually better to start from client code, and build up to an implementation that does something interesting. Otherwise you're building writing code and expecting / hoping it will meet the needs of the client that doesn't exist yet (even though in this case you know what's coming, but it will still cause issues if any refactoring is needed), as well as requiring reviewers to imagine how this will be used.
In terms of getting test coverage up in general and ensuring you have tests to cover typical error conditions, the usual way of doing this in Go is to write an interface with the functions defined in the external package (e.g. StdoutPipe()
, Start()
, etc). Then you can mock the interface for testing and inject your mocks. You will need to refactor your code somewhat to make this possible (e.g. factor out the code that creates the Command object) but you should be able to test nearly everything.
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package subprocessmanager |
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.
Does subprocessmanager
need to be in a separate package? It's not that large; I would recommend just putting it directly in the prometheusexecreceiver
package, unless you have a good reason why you want it to be a separate package such that people can consume it as a standalone package.
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 had discussions in the past with Quentin where we thought it would be a good idea to leave it as a separate package other can consume! It keeps track of runtime and has methods to compute exponential backoff, pipe the output of the subprocesses and format the environment variables!
return envSlice | ||
} | ||
|
||
// GetDelay will compute the exponential backoff for a given process according to its crash count and time alive |
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.
// GetDelay will compute the exponential backoff for a given process according to its crash count and time alive | |
// GetDelay will compute the delay for a given process according to its crash count and time alive using an exponential backoff algorithm |
Also consider if it would make sense to use https://github.com/cenkalti/backoff instead of writing this logic yourself. I think that package is used in a few other places in the Collector already
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.
Changed the wording! I prefer using my own logic since I have more power with the use of computing the backoff with crashCount
as well as runtime (elapsed
). Since I'm also managing the receiver associated to the subprocess, there's lots of different conditions that define whether a process is "healthy" or not!
I spoke with James offline in regards to his summary comment, and I'll try moving the PR this way (only the subprocess manager part of the receiver) for two main reasons: the entire feature/PR is done (the rest of the code is ready to go and will be made into a PR as soon as this is merged!) and it is referenced for context in this PR's description. This happened because I made the entire feature and then retroactively needed to break the PR into smaller chunks. In the future I'll be more mindful about how to break up my work beforehand. We'll discuss further tonight as well. |
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.
Would recommend moving the config
package into the subprocessmanager
package as I don't think this needs to be separated
Assigning to @keitwb for review, as per Jay's suggestion during the weekly meeting |
// Process struct holds all the info needed to instantiate a subprocess | ||
type Process struct { | ||
Command string | ||
Port int |
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.
Is Port
part of some yet unimplemented feature? I can't see any uses of it. Is it supposed to be used to construct an arg to the subprocess telling it what port to run on?
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.
Yeah! This PR is one part of the bigger picture receiver prometheus_exec
and port
is important! thanks! It's used to keep track of the original port passed into the config for this process/receiver combo.
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.
EDIT: removing since this package is being moved to the Core repo, and I want to make it usable by all
This package is moving to the core repo. This decision was following discussions with @bogdandrutu and @james-bebbington to make this usable by anyone who needs to manage subprocesses in their code. |
@Nicolas-MacBeth to unblock you, we thing it is better if you work in parallel:
|
Sounds good! Thanks for the swift responses. |
… done during a request (#499) Co-authored-by: alrex <aboten@lightstep.com>
[![Mend Renovate logo banner](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/pkg/sftp](https://togithub.com/pkg/sftp) | require | patch | `v1.13.5` -> `v1.13.6` | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>pkg/sftp (github.com/pkg/sftp)</summary> ### [`v1.13.6`](https://togithub.com/pkg/sftp/releases/tag/v1.13.6) [Compare Source](https://togithub.com/pkg/sftp/compare/v1.13.5...v1.13.6) \[[GH-499](https://togithub.com/pkg/sftp/issues/499)] writeToSequential: improve tests for write errors \[[GH-513](https://togithub.com/pkg/sftp/issues/513)] More context for EOF during client setup \[[GH-516](https://togithub.com/pkg/sftp/issues/516)] RealPathFileLister: allow to return an error \[[GH-525](https://togithub.com/pkg/sftp/issues/525)] Document the weirdness of the reversal of arguments to SSH_FXP_SYMLINK \[[GH-526](https://togithub.com/pkg/sftp/issues/526)] request server: handle relative symlinks \[[GH-528](https://togithub.com/pkg/sftp/issues/528)] Add support for working directory in Server \[[GH-533](https://togithub.com/pkg/sftp/issues/533)] CI: add CIFuzz integration \[[GH-537](https://togithub.com/pkg/sftp/issues/537)] Stop ReadFromWithConcurrency sending more data than it needs to \[[GH-545](https://togithub.com/pkg/sftp/issues/545)] refactor sshfx encoding, fix link rot, go fmt \[[GH-553](https://togithub.com/pkg/sftp/issues/553)] Marshal extended attribute data if FileInfo supports it \[[GH-554](https://togithub.com/pkg/sftp/issues/554)] Properly handle io.EOF error conditions when reading </details> --- ### Configuration 📅 **Schedule**: Branch creation - "on tuesday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/open-telemetry/opentelemetry-collector-contrib). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy41OS44IiwidXBkYXRlZEluVmVyIjoiMzcuNTkuOCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com>
…ry#29477) [![Mend Renovate logo banner](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/pkg/sftp](https://togithub.com/pkg/sftp) | require | patch | `v1.13.5` -> `v1.13.6` | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>pkg/sftp (github.com/pkg/sftp)</summary> ### [`v1.13.6`](https://togithub.com/pkg/sftp/releases/tag/v1.13.6) [Compare Source](https://togithub.com/pkg/sftp/compare/v1.13.5...v1.13.6) \[[open-telemetryGH-499](https://togithub.com/pkg/sftp/issues/499)] writeToSequential: improve tests for write errors \[[open-telemetryGH-513](https://togithub.com/pkg/sftp/issues/513)] More context for EOF during client setup \[[open-telemetryGH-516](https://togithub.com/pkg/sftp/issues/516)] RealPathFileLister: allow to return an error \[[open-telemetryGH-525](https://togithub.com/pkg/sftp/issues/525)] Document the weirdness of the reversal of arguments to SSH_FXP_SYMLINK \[[open-telemetryGH-526](https://togithub.com/pkg/sftp/issues/526)] request server: handle relative symlinks \[[open-telemetryGH-528](https://togithub.com/pkg/sftp/issues/528)] Add support for working directory in Server \[[open-telemetryGH-533](https://togithub.com/pkg/sftp/issues/533)] CI: add CIFuzz integration \[[open-telemetryGH-537](https://togithub.com/pkg/sftp/issues/537)] Stop ReadFromWithConcurrency sending more data than it needs to \[[open-telemetryGH-545](https://togithub.com/pkg/sftp/issues/545)] refactor sshfx encoding, fix link rot, go fmt \[[open-telemetryGH-553](https://togithub.com/pkg/sftp/issues/553)] Marshal extended attribute data if FileInfo supports it \[[open-telemetryGH-554](https://togithub.com/pkg/sftp/issues/554)] Properly handle io.EOF error conditions when reading </details> --- ### Configuration 📅 **Schedule**: Branch creation - "on tuesday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/open-telemetry/opentelemetry-collector-contrib). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy41OS44IiwidXBkYXRlZEluVmVyIjoiMzcuNTkuOCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com>
Please look at #453 for the full PR. Since that PR was too big, I'm breaking it up into 2 different PRs, starting with this one. The entire feature/Receiver was written so please refer back to it for better context if need be! This is the subprocess manager part of the receiver, an sub-package of the receiver!
Test coverage is 89% since the lines that are not covered are OS-level error returns that are hard to replicate in testing.