Go 1.20
Hybrid meetup #34 took place 2023-02-21 19:00 at Basislager Leipzig and was all about Go 1.20 (similar to previous years, where we looked at Go 1.14, 1.16, 1.18 - #9, #16, #25).
We had two great presentations:
- A rundown of most novelties in Go 1.20: Go 1.20 updates, including many examples – thanks, Andreas! … and
- Go 1.20 Coverage Profiling Support for Kubernetes Apps, a walkthrough on how to use Go 1.20 binary profiling with containerized workloads (with inception style isolation layer qualities) – thanks, Michael!
Some highlights from the release notes:
- context.WithCancelCause allows to pass a custom error along the cancellation line
- package http gained a wrapper around the
http.ResponseWriter
, calledhttp.ResponseController
allowing for per request timeout controls
Go started to add support for Profile-guided optimization, a technique already in place in various technologies.
As of Go 1.20, benchmarks for a representative set of Go programs show that building with PGO improves performance by around 2-4%. We expect performance gains to generally increase over time as additional optimizations take advantage of PGO in future versions of Go. – https://go.dev/doc/pgo
A challenge in containerized environments (e.g. k8s) is that profiling information may be written to emphemeral storage, hence lost, once the container is torn down.
At the same time, end-to-end (e2e) tests are an important technique to test software, especially when running in complex enviroments with many interactions (e.g. with other services, backends, …). You do not want to mock everything (too tedious), and containers are a popular way to isolate components, anyway.
The example project we looked at was a vSphere client library, that uses e2e tests running in a local cluster using kind, and ko to turn Go programs into images, automagically (excellent developer tools, btw).
If you mount a local path into kind, and mount that again into the pod running the tests and let the Go binary know, where to write the cover information (via GOCOVERDIR) - you can cover any environment that has a local filesystem exposed (e.g. your laptop, or CI, …).
It’s not easy, but it works - and impressive as for the fidelity of the test environment.
Quick Github Actions tip: To not exhausting CI limits on GH actions, cancel previous runs on a PR branch, if you push new commits - see this example.
Thanks to Andreas and Michael for the insights.
Go 1.20 continues to add small improvements to the language and ecosystem and more interesting things are in the pipeline, like the experimental structured logging slog.
What’s your favorite feature?
Join our meetup and let us know!