Show the reason why a mirror is down#224
Merged
Merged
Conversation
In case a mirror is down, also show the reason why. This is in response to the discussion at videolabs#221. Implementation is pretty straightforward, since we have the information in the Mirror struct already. The logic in ReasonString() is similar to the logic in the StatusString(), ie. if the mirror supports both HTTP and HTTPS, we have to remember that it might be up/up, up/down, down/up or down/down. And if it's down/down, the two reasons why might or might not be the same. Output before this commit: ``` $ mirrorbits list -down Identifier STATE SINCE mirror.nyist.edu.cn down (Tue, 16 Jun 2026 15:15:45 UTC) mirror.primelink.net.id down (Sun, 14 Jun 2026 11:00:30 UTC) mirror.aktkn.sg up/down (Thu, 16 Apr 2026 07:29:53 UTC) Unreachable ``` Output after this commit: ``` $ mirrorbits list -down Identifier STATE SINCE REASON mirror.nyist.edu.cn down (Tue, 16 Jun 2026 15:15:45 UTC) Got status code 429 mirror.primelink.net.id down (Sun, 14 Jun 2026 11:00:30 UTC) Unreachable mirror.aktkn.sg up/down (Thu, 16 Apr 2026 07:29:53 UTC) Unreachable ``` Note that "Unreachable" is not very telling, it's the reason set by mirrorbits for any network error. For more details one has to refer to the daemon log, it has all the crunchy details like "no route to host", "i/o timeout" or even "x509: certificate has expired or is not yet valid". But these details only exist in the daemon logs, and if we want to make it more visible, more changes will be needed in mirrorbits.
Summary of parameters for `w.Init`, from [1]:
minwidth minimal cell width including any padding
tabwidth width of tab characters (equivalent number of spaces)
padding padding added to a cell before computing its width
padchar ASCII char used for padding
Without padding, if a column is exactly 8-chars long, there will be no
space to separate it from the next column. For example, here what I get
with the command `mirrorbits stats file ....`:
```
$ mirrorbits stats file rust-grep-searcher
/pool/main/r/rust-grep-searcher/librust-grep-searcher-dev_0.1.16-1+b1_amd64.deb:1
/pool/main/r/rust-grep-searcher/rust-grep-searcher_0.1.16-1.debian.tar.xz: 1
/pool/main/r/rust-grep-searcher/rust-grep-searcher_0.1.16-1.dsc: 1
/pool/main/r/rust-grep-searcher/rust-grep-searcher_0.1.16.orig.tar.gz: 1
Total download requests: 4
```
As we can see, the command `mirrorbits list` worked around that by
adding a trailing space after each value, which is Ok but not super
clean.
Let's simplify: use a padding of 1 in every place where a tabwriter is
used, and then drop leading/trailing spaces around values as they are
not needed anymore.
[1]: https://pkg.go.dev/text/tabwriter
Make it slightly more readable. Also, always print reason (ie. make sure every row have a reason column, even though this column is empty for mirrors that are up). Otherwise the REASON label in the header line is not properly aligned.
Before this commit: ``` $ mirrorbits list | head -2 Identifier STATE SINCE REASON mirror.nyist.edu.cn up (Wed, 17 Jun 2026 03:57:43 UTC) ``` And after: ``` $ mirrorbits list | head -2 IDENTIFIER STATE SINCE REASON mirror.nyist.edu.cn up (Wed, 17 Jun 2026 03:57:43 UTC) ``` That's a breaking change for scripts that parse the output of `mirrorbits list` and filter out the heading with e.g. `grep -v ^Identifier', so that will need to be documented in the changelog.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is in response to the discussion at #221
This merge request also adds more minor changes around the "mirrorbits list" command.