mc icon indicating copy to clipboard operation
mc copied to clipboard

Exit mc mirror when errors occur if retry is disabled and it's a watch operation

Open jadolg opened this issue 9 months ago • 7 comments

Community Contribution License

All community contributions in this pull request are licensed to the project maintainers under the terms of the Apache 2 license. By creating this pull request I represent that I have the right to license the contributions to the project maintainers under the Apache 2 license.

Description

When running mc mirror --watch the cli exits with a non-zero exit code instead of just printing the error.

Motivation and Context

I'm running mc mirror --watch in a systemd unit to constantly mirror my minio buckets to AWS S3. In the current state, it's not possible to monitor mc effectively since the process will just continue running.

How to test this PR?

Types of changes

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Optimization (provides speedup with no functional changes)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • [ ] Fixes a regression (If yes, please add commit-id or PR # here)
  • [ ] Unit tests added/updated
  • [ ] Internal documentation updated
  • [ ] Create a documentation update request here

jadolg avatar Mar 11 '25 12:03 jadolg

Solves https://github.com/minio/mc/issues/5162

jadolg avatar Mar 11 '25 12:03 jadolg

@klauspost it is a breaking change but I think it makes sense. mc mirror --watch is a long running operation. Without directly looking at the logs, there's currently no way to know that the application is failing to do it's job. In my case, I was trying to mirror a bucket into an unexisting bucket in another system. I'm running mc mirror --watch in an "unatended" way (systemd unit) so I'm not looking at the logs unless something goes wrong. mc mirror --watch will fail and I have no idea my bucket is not being mirrored. I could technically monitor the logs and trigger some alert if errors occur, but then I'd need to account for all possible errors and error format making this not really bulletproof. My point is: I think it should break if an error occurs so it is obvious the operation can't be completed. If you are concerned about breaking other people's already existing workflows, we could also hide this behavior behind a flag (Eg: --fail-on-error) wdyt?

jadolg avatar May 06 '25 06:05 jadolg

If you are concerned about breaking other people's already existing workflows, we could also hide this behavior behind a flag (Eg: --fail-on-error)

Yeah. I think that is the only reasonable approach. mc is running in a lot of places, so we need to be reasonable about back-compat.

klauspost avatar May 06 '25 08:05 klauspost

New flag added and removed the need for the --watch parameter since the new flag should make it explicit for all mirror operations.

jadolg avatar May 06 '25 09:05 jadolg

ok, so my only remaining reservation is that it may not exit in all cases where people would expect it, but I can live with that.

klauspost avatar May 06 '25 12:05 klauspost

ok, so my only remaining reservation is that it may not exit in all cases where people would expect it, but I can live with that.

It's tricky to get it to fail everywhere where it might fail because everything happens separately but I think monitorMirrorStatus should cover most cases since the errors were only logged there anyway.

jadolg avatar May 07 '25 06:05 jadolg

@klauspost What would be the next steps for this PR to get merged or at least looked at?

jadolg avatar May 12 '25 09:05 jadolg