summaryrefslogtreecommitdiff
path: root/cmd/check
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2020-09-19 03:34:49 -0700
committerStan Hu <stanhu@gmail.com>2020-09-20 21:40:40 -0700
commita487572a904cc149840488eefdfe121173d8bcb5 (patch)
treed17cf7bff45492a587027851bb6e0bcb493cff58 /cmd/check
parentf100e7e83943b3bb5db232f5bf79a616fdba88f1 (diff)
downloadgitlab-shell-a487572a904cc149840488eefdfe121173d8bcb5.tar.gz
Make it possible to propagate correlation ID across processes
Previously, gitlab-shell did not pass a context through the application. Correlation IDs were generated down the call stack instead of passed around from the start execution. This has several potential downsides: 1. It's easier for programming mistakes to be made in future that lead to multiple correlation IDs being generated for a single request. 2. Correlation IDs cannot be passed in from upstream requests 3. Other advantages of context passing, such as distributed tracing is not possible. This commit changes the behavior: 1. Extract the correlation ID from the environment at the start of the application. 2. If no correlation ID exists, generate a random one. 3. Pass the correlation ID to the GitLabNet API requests. This change also enables other clients of GitLabNet (e.g. Gitaly) to pass along the correlation ID in the internal API requests (https://gitlab.com/gitlab-org/gitaly/-/issues/2725). Fixes https://gitlab.com/gitlab-org/gitlab-shell/-/issues/474
Diffstat (limited to 'cmd/check')
-rw-r--r--cmd/check/main.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/cmd/check/main.go b/cmd/check/main.go
index e88b9fe..28634f4 100644
--- a/cmd/check/main.go
+++ b/cmd/check/main.go
@@ -38,7 +38,10 @@ func main() {
os.Exit(1)
}
- if err = cmd.Execute(); err != nil {
+ ctx, finished := command.ContextWithCorrelationID()
+ defer finished()
+
+ if err = cmd.Execute(ctx); err != nil {
fmt.Fprintf(readWriter.ErrOut, "%v\n", err)
os.Exit(1)
}