Skip to content

Introduce optional profiling through Stackdriver Profiler

Oswaldo Ferreira requested to merge osw-add-go-stackdriver-profiler into master

This introduces the first sample profiler driver (Stackdriver), allowing initializing any Go service that uses labkit (and upgrades to the new version) with the GITLAB_CONTINUOUS_PROFILING env variable as such:

GITLAB_CONTINUOUS_PROFILING="stackdriver?service=gitaly&service_version=1.0.1&project_id=test-123" go run file.go

Passing GITLAB_CONTINUOUS_PROFILING=stackdriver (without further params) will make the Stackdriver profiler guess these values based certain environment criterias described at https://godoc.org/cloud.google.com/go/profiler#Config.

In order to use the profiler, users of labkit will need to compile it with the -tags continuous_profiler_stackdriver, otherwise no dependencies will be added and GITLAB_CONTINUOUS_PROFILING will take no effect.

Binary size comparison with and without the tag

2.6.3 in gitlab-workhorse/ on master
› ls -l gitlab-workhorse
-rwxr-xr-x 1 osw staff 23300020 Feb  7 17:42 gitlab-workhorse*

2.6.3 in gitlab-workhorse/ on master
› fg
[1]  + continued  nvim .

2.6.3 in gitlab-workhorse/ on master
› make
### clean-build
rm -rf /Users/osw/projects/gitlab/gitlab-workhorse/_build
### Setting up target directory
rm -rf "/Users/osw/projects/gitlab/gitlab-workhorse/_build"
mkdir -p "/Users/osw/projects/gitlab/gitlab-workhorse/_build"
touch "/Users/osw/projects/gitlab/gitlab-workhorse/_build/.ok"
### Building gitlab-zip-cat
go build -ldflags "-X main.Version=v8.20.0 -X main.BuildTime=20200207.204449" -tags "tracer_static tracer_static_jaeger continuous_profiler_stackdriver" -o /Users/osw/projects/gitlab/gitlab-workhorse/gitlab-zip-cat gitlab.com/gitlab-org/gitlab-workhorse/cmd/gitlab-zip-cat
### Building gitlab-zip-metadata
go build -ldflags "-X main.Version=v8.20.0 -X main.BuildTime=20200207.204449" -tags "tracer_static tracer_static_jaeger continuous_profiler_stackdriver" -o /Users/osw/projects/gitlab/gitlab-workhorse/gitlab-zip-metadata gitlab.com/gitlab-org/gitlab-workhorse/cmd/gitlab-zip-metadata
### Building gitlab-workhorse
go build -ldflags "-X main.Version=v8.20.0 -X main.BuildTime=20200207.204449" -tags "tracer_static tracer_static_jaeger continuous_profiler_stackdriver" -o /Users/osw/projects/gitlab/gitlab-workhorse/gitlab-workhorse gitlab.com/gitlab-org/gitlab-workhorse

2.6.3 in gitlab-workhorse/ on master
› ls -l gitlab-workhorse
-rwxr-xr-x 1 osw staff 25092772 Feb  7 17:44 gitlab-workhorse*

So it adds about 1.7MB to the workhorse binary, only when adding -tags continuous_profiler_stackdriver in the compilation process.

gitlab-com/gl-infra/scalability#101 (closed)

Closes #8 (closed)

Edited by Oswaldo Ferreira

Merge request reports