Skip to content
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

Restarts Prometheus subprocess when it crashes #663

Merged
merged 10 commits into from
May 28, 2020

Conversation

mpmcroy
Copy link
Contributor

@mpmcroy mpmcroy commented May 27, 2020

Adds restart logic for the Prometheus subprocess by listening for process exit events.

Manually tested using the following:
$ yarn do shadowbox/docker/run
$ pgrep prometheus | xargs sudo kill

TODO: Can we write an integration test?
TODO: Can we publish an event somewhere to track the number of crashes we see?

@mpmcroy mpmcroy requested a review from alalamav May 27, 2020 21:45
@mpmcroy mpmcroy requested a review from fortuna May 27, 2020 21:45
src/shadowbox/infrastructure/prometheus_scraper.ts Outdated Show resolved Hide resolved
prometheusConfigFilename: string, prometheusEndpoint: string, prometheusTsdbFilename: string,
prometheusLocation: string, configJson: {}, verbose: boolean) {
await writePrometheusConfigToDisk(prometheusConfigFilename, configJson);
const processArgs = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This library is intended to be a generic Prometheus client, but these are all application-specific parameters. Could you change it back to take a generic list of args?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Vini. That's interesting insight!

I usually recommend the opposite and put all the "opinions" into the client. This guarantees a consistent experience for all users of the client. And only allow optional customizations to be overridden. I like to think of it as analogous to a builder pattern with all required params without going full builder.


On a side note, I put the logic back into the caller.

Copy link
Collaborator

@fortuna fortuna May 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you when we talk about the domain objects. But I see everything under infrastructure/ as a different bounded context, independent of our app, with their own models.

src/shadowbox/infrastructure/prometheus_scraper.ts Outdated Show resolved Hide resolved
src/shadowbox/infrastructure/prometheus_scraper.ts Outdated Show resolved Hide resolved
src/shadowbox/infrastructure/prometheus_scraper.ts Outdated Show resolved Hide resolved
src/shadowbox/infrastructure/prometheus_scraper.ts Outdated Show resolved Hide resolved
@mpmcroy mpmcroy requested a review from fortuna May 28, 2020 15:25
Copy link
Collaborator

@fortuna fortuna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick change!

mkdirp.sync(path.dirname(configFilename));
export async function startPrometheus(
configFilename: string, configJson: {}, processArgs: string[], endpoint: string) {
await writePrometheusConfigToDisk(configFilename, configJson);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it makes sense to make these two calls in main instead. It feels odd to pass both a config filename and the config contents to a method. The configJson is not really used by spawnPrometheusSubprocess.

Anyway, not important, up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strongly either way about it.

The configFilename is used in the args, so there's kind of a duplication going on.

I would personally keep it as one method (even if the signature isn't that great) so that users don't forget to call writeConfigFile before spawnPromProcess.

@mpmcroy mpmcroy merged commit f27eb72 into master May 28, 2020
@sbruens sbruens deleted the mpmcroy-prometheus-restart branch March 5, 2024 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants