GitHub Actions workflow
Some important changes to GitHub Actions workflows:
golangci-lint and its builder (golangci-lint-action v8.0.0)
The Go extension for Visual Studio Code supports golangci-lint albeit through the “Go” debug console. An advantage of accessing it in Visual Studio Code is that recommendations hyperlink to the code.
I’ve added golangci-lint to most of my repos’ GitHub Actions workflows. Belatedly, I realized it should run before not in parallel with the e.g. container builder.
Golang error handling
In Golang, it is common to see errors return as:
errors.New(msg)
And:
fmt.Error(msg)
fmt.Errorf("...",msg,foo,bar)
If there are nested errors, these can be wrapped into a new error using the %w formatting directive:
if err!=nil {
msg := "something went wrong"
return ...,fmt.Errorf("%s: %w", msg, err)
}
It is good practice to create custom error types.
Not only can this improve readability but it enables a mechanism where the error type can be used to clarify code.
Patch Prometheus Operator `externalUrl`
I continue to learn “tricks” with Prometheus and (kube-prometheus ⊃ Prometheus Operator).
For too long, I’ve lived with Alertmanager alerts including “View in Alertmanager” and “Source” hyperlinks that don’t work because they defaulted incorrectly.
The solution when running either Prometheus or Alertmanager (same for both) is to use the flag:
--web.external-url="${EXTERNAL_URL}"
Conveniently, when running kube-prometheus, there are Prometheus and Alertmanager CRDs for configuring Prometheus and Alertmanager and these include the field:
externalUrl: "${EXTERNAL_URL}"
The question is: How to configure this value?