Code AI platform with Code Search & Cody
Go to file
Geoffrey Gilmore 2c7d217730
feat/cmd/gitserver: add memory tracking for both linux and macos (#63114)
Closes
https://linear.app/sourcegraph/issue/SRC-369/finalize-memory-tracking-in-gitserver-on-linux

This PR adds a memory tracking feature to all gitserver command, using
the utilities introduced in
https://app.graphite.dev/github/pr/sourcegraph/sourcegraph/62803.

When the GITSERVER_MEMORY_OBSERVATION_ENABLED env var is set, an
observer will be spawned that keeps track of the memory usage of the git
invocation. This information is available in traces. Additionally, we'll
print WARN logs if the commands uses more than 100 MB.


## Test plan

Run sg start, and manually tweak the high memory usage threshold down
from 500 MB to 1MB.



```diff
diff --git a/cmd/gitserver/internal/git/gitcli/command.go b/cmd/gitserver/internal/git/gitcli/command.go
index 393fa3c91e6..cf2630fc830 100644
--- a/cmd/gitserver/internal/git/gitcli/command.go
+++ b/cmd/gitserver/internal/git/gitcli/command.go
@@ -297,7 +297,7 @@ func (rc *cmdReader) waitCmd() error {
 	return rc.err
 }
 
-const highMemoryUsageThreshold = 500 * 1024 * 1024 // 500 MiB
+const highMemoryUsageThreshold = 1 * 1024 * 1024 // 500 MiB
 
 func (rc *cmdReader) trace() {
 	duration := time.Since(rc.cmdStart)

```


See log lines similar to the following when I run `sg start` (note the
memory usage information in the log fields):

```
[    gitserver-1] WARN gitserver gitcli/command.go:363 High memory usage exec request {"TraceId": "5881f40e3bbbe4d26ec0f32b7f64f535", "SpanId": "a68818dc9f1f9ee2", "ev.Fields": {"cmd": "config", "cmd_ru_maxrss_kib": "5056", "cmd_ru_maxrss_human_readable": "5.2 MB", "traceID": "5881f40e3bbbe4d26ec0f32b7f64f535", "cmd_ru_inblock": "0", "args": "[git config --unset-all gc.auto]", "actor": "0", "cmd_duration_ms": "6", "user_time_ms": "2", "system_time_ms": "2", "repo": "github.com/sgtest/typescript-deps", "error": "git command [git config --unset-all gc.auto] failed with status code 5 (output: \"\")", "cmd_ru_majflt": "10", "cmd_ru_oublock": "0", "trace": "https://sourcegraph.test:3443/-/debug/jaeger/trace/5881f40e3bbbe4d26ec0f32b7f64f535", "exit_status": "5", "cmd_ru_minflt": "494"}}
[    gitserver-1] WARN gitserver gitcli/command.go:363 High memory usage exec request {"TraceId": "93cb7e9b3a42cfc085f570b8ad4a2ded", "SpanId": "c35ecddb6ef89e24", "ev.Fields": {"cmd_duration_ms": "6", "system_time_ms": "2", "cmd_ru_maxrss_kib": "5072", "cmd_ru_maxrss_human_readable": "5.2 MB", "cmd_ru_minflt": "495", "cmd_ru_majflt": "10", "actor": "0", "exit_status": "5", "user_time_ms": "2", "cmd_ru_oublock": "0", "traceID": "93cb7e9b3a42cfc085f570b8ad4a2ded", "trace": "https://sourcegraph.test:3443/-/debug/jaeger/trace/93cb7e9b3a42cfc085f570b8ad4a2ded", "repo": "github.com/sgtest/update-ids-test-base", "cmd": "config", "args": "[git config --unset-all gc.auto]", "error": "git command [git config --unset-all gc.auto] failed with status code 5 (output: \"\")", "cmd_ru_inblock": "0"}}
[    gitserver-1] WARN gitserver gitcli/command.go:363 High memory usage exec request {"TraceId": "346f1d04dc869f069b04bcabadec0665", "SpanId": "ec43228229e5f531", "ev.Fields": {"actor": "0", "error": "git command [git config --unset-all gc.auto] failed with status code 5 (output: \"\")", "cmd_ru_maxrss_kib": "4960", "trace": "https://sourcegraph.test:3443/-/debug/jaeger/trace/346f1d04dc869f069b04bcabadec0665", "args": "[git config --unset-all gc.auto]", "exit_status": "5", "cmd_duration_ms": "7", "system_time_ms": "2", "repo": "github.com/sgtest/utf8_test", "user_time_ms": "2", "cmd_ru_maxrss_human_readable": "5.1 MB", "cmd_ru_minflt": "487", "cmd_ru_inblock": "0", "cmd_ru_oublock": "0", "traceID": "346f1d04dc869f069b04bcabadec0665", "cmd": "config", "cmd_ru_majflt": "10"}}
[    gitserver-1] WARN gitserver gitcli/command.go:363 High memory usage exec request {"TraceId": "1b6a65835e3f75e7e83c8fe7355baeb2", "SpanId": "d525ac1f8c077184", "ev.Fields": {"cmd_ru_oublock": "0", "repo": "github.com/sourcegraph/about", "args": "[git config --unset-all gc.auto]", "cmd_duration_ms": "7", "system_time_ms": "2", "cmd_ru_inblock": "0", "exit_status": "5", "error": "git command [git config --unset-all gc.auto] failed with status code 5 (output: \"\")", "cmd_ru_maxrss_kib": "4912", "cmd_ru_maxrss_human_readable": "5.0 MB", "cmd_ru_minflt": "483", "cmd": "config", "user_time_ms": "2", "trace": "https://sourcegraph.test:3443/-/debug/jaeger/trace/1b6a65835e3f75e7e83c8fe7355baeb2", "actor": "0", "cmd_ru_majflt": "10", "traceID": "1b6a65835e3f75e7e83c8fe7355baeb2"}}
[    gitserver-1] WARN gitserver gitcli/command.go:363 High memory usage exec request {"TraceId": "39bbc0cc8b99292e6d3b6dfc067d4049", "SpanId": "60e4d69a25a3074b", "ev.Fields": {"args": "[git config --unset-all gc.auto]", "cmd_duration_ms": "7", "cmd_ru_maxrss_kib": "5056", "cmd_ru_minflt": "492", "trace": "https://sourcegraph.test:3443/-/debug/jaeger/trace/39bbc0cc8b99292e6d3b6dfc067d4049", "actor": "0", "system_time_ms": "2", "cmd_ru_inblock": "0", "cmd": "config", "exit_status": "5", "error": "git command [git config --unset-all gc.auto] failed with status code 5 (output: \"\")", "user_time_ms": "2", "cmd_ru_maxrss_human_readable": "5.2 MB", "cmd_ru_oublock": "0", "repo": "github.com/sourcegraph-testing/etcd", "cmd_ru_majflt": "10", "traceID": "39bbc0cc8b99292e6d3b6dfc067d4049"}}
[
```


Note that I have not tested this e2e in a linux system, but I think it's
fine to test it on sourcegraph.com since:

1) we have the benchmarks / integration tests from the previous PR
2) it's behind a environment variable that is off by default

## Changelog 

Adds a new experimental feature to enable track of `git` command memory
invocations when the `GITSERVER_MEMORY_OBSERVATION_ENABLED` environment
variable is true (off by default).
2024-06-10 14:26:41 -07:00
.apko Build images end-to-end using Bazel v2 (#61845) 2024-04-12 16:18:43 +01:00
.aspect bazel: rules_js rc3 and remove deprecated "exclude_declarations" option (#63095) 2024-06-05 10:33:37 +02:00
.buildkite chore(ci): remove backcompat mitigation (#62658) 2024-05-14 11:00:35 +01:00
.github chore(ci): fix PR template's changelog type list (#62998) 2024-05-31 13:51:05 +00:00
.vscode bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
client [Svelte]: Fix standard click-based popover flow (#63192) 2024-06-10 15:38:32 -03:00
cmd feat/cmd/gitserver: add memory tracking for both linux and macos (#63114) 2024-06-10 14:26:41 -07:00
dev msp/deploy: encode commit_message as base64 (#63165) 2024-06-07 23:31:42 +01:00
doc chore(codenav): Resolve repo and commit in common code (#63072) 2024-06-07 21:58:36 +08:00
docker-images fix(highlighting): Update JSX/TSX highlighting to more properly label tag delimiters (#63138) 2024-06-07 08:46:34 -04:00
internal feat/internal/memcmd: add internal/memcmd package to allow for memory tracking of exec.Cmd processes (#62803) 2024-06-10 14:20:15 -07:00
lib feat/cody-gateway: use Enterprise Portal for actor/productsubscriptions (#62934) 2024-06-07 11:46:01 -07:00
migrations scim: Fix user updates when SCIM was previously enabled (#63135) 2024-06-06 22:24:00 +02:00
monitoring Reapply "gitserver(client): Reintroduce 500 maximum connections limit" (#63134) 2024-06-07 10:46:19 +02:00
schema Cody Gateway: Add Gemini models to PLG and Enterprise users (#63053) 2024-06-04 23:46:36 +00:00
testing feat/bazel: //cmd/{frontend,server} targets that don't include client bundle for backend integration tests (#62877) 2024-05-28 14:32:48 +01:00
third_party chore(bazel): upgrade to latest rules_oci 1.x (#63085) 2024-06-05 14:35:37 +00:00
third-party-licenses chore: Completely sunset qdrant (#62018) 2024-04-22 18:00:57 +02:00
tools feat(release): allow creation of multiple patch release events (#63034) 2024-06-03 11:14:24 -04:00
ui/assets feat/bazel: //cmd/{frontend,server} targets that don't include client bundle for backend integration tests (#62877) 2024-05-28 14:32:48 +01:00
wolfi-images security: Auto-update package lockfiles for Sourcegraph base images (#63104) 2024-06-05 16:04:36 +00:00
wolfi-packages s3proxy: Fix permissions on s3proxy package binary (#62907) 2024-05-24 15:55:00 +00:00
.bazel_fix_commands.json SG Start Bazel Improvements Take 2 (#60687) 2024-03-05 01:44:21 -08:00
.bazelignore Create a shared Cody Ignore dataset (#61968) 2024-05-09 13:18:35 +00:00
.bazeliskrc chore: upgrade to Aspect CLI 5.8.19 (#59203) 2024-01-02 15:13:24 +01:00
.bazelrc feat(ci): Adds playwright tests for sveltekit to bazel (#62560) 2024-06-06 12:45:05 -06:00
.bazelversion bazel: bump to 7.1 (#61092) 2024-03-13 14:52:25 +00:00
.dockerignore use esbuild for client/web builds (#57365) 2023-10-23 10:59:06 -07:00
.editorconfig proto: Add editorconfig to ident using two spaces (#57281) 2023-10-03 00:39:42 +00:00
.eslintrc.js Revert vs-code extension deleting (#61258) 2024-03-20 13:53:27 +01:00
.gitattributes dev/linearhooks: add POC (#62367) 2024-05-07 00:14:05 -07:00
.gitignore chore(codenav): Resolve repo and commit in common code (#63072) 2024-06-07 21:58:36 +08:00
.graphqlrc.yml
.hadolint.yaml bump comby version to 1.7.1 (#35830) 2022-05-20 20:12:01 -07:00
.mailmap mailmap: add entries for Eric and Renovate (#50966) 2023-04-25 09:42:22 +02:00
.mocharc.js reapply "switch from jest to vitest for faster, simpler tests (#57886)" (#58145) 2023-11-07 12:00:18 +02:00
.npmrc pnpm: remove update notifier message (#51630) 2023-05-10 08:53:39 +02:00
.percy.yml ci: percy defer snapshots upload (#54116) 2023-06-25 18:57:49 -07:00
.pre-commit-config.yaml exclude pnpm-lock.yaml from precommit (#61158) 2024-03-14 15:35:14 +00:00
.prettierignore svelte: Add lucide icons and new icon API (#62908) 2024-05-29 11:25:04 +02:00
.stylelintignore rework plugin structure and implement frontside blogpost (#46883) 2023-02-15 11:49:51 +02:00
.stylelintrc.json web: drop bootstrap depenedency (#41401) 2022-09-07 03:11:26 -07:00
.swcrc use swc instead of babel for faster bazel typescript transpilation (#57912) 2023-11-02 22:49:03 -07:00
.tool-versions chore(tooling): bump Go version to 1.22.4 (#63124) 2024-06-06 15:19:03 +00:00
.trivyignore
BUILD.bazel feat/bazel: //cmd/{frontend,server} targets that don't include client bundle for backend integration tests (#62877) 2024-05-28 14:32:48 +01:00
CHANGELOG.md chore(graph): Add changelog entry for Python scip-ctags fix (second attempt) (#63106) 2024-06-07 15:27:54 +02:00
CODENOTIFY nix: update pnpm hash (#51512) 2023-05-05 12:51:59 +00:00
CONTRIBUTING.md fix: update links for dev docs (#62758) 2024-05-17 13:47:34 +02:00
deps.bzl chore(codenav): Resolve repo and commit in common code (#63072) 2024-06-07 21:58:36 +08:00
doc.go
eslint-relative-formatter.js bazel: implement custom ESLint Bazel rule (#52062) 2023-05-22 04:05:45 -07:00
flake.lock nix: bump to bazel 7.1 (#61326) 2024-03-22 16:57:50 +00:00
flake.nix nix: build pg-utils with nix [static edition] (#61734) 2024-04-09 20:24:19 +01:00
gen.go chore: fixup go-mockgen run statement (#61028) 2024-03-12 13:06:36 +00:00
go.mod feat/internal/memcmd: add internal/memcmd package to allow for memory tracking of exec.Cmd processes (#62803) 2024-06-10 14:20:15 -07:00
go.sum chore(codenav): Resolve repo and commit in common code (#63072) 2024-06-07 21:58:36 +08:00
graphql-schema-linter.config.js
LICENSE relicense all paths other than MIT licensed code, client/cody*, jetbrains, VS code, and browser extension to enterprise (#53345) (#53345) 2023-06-13 10:28:11 -07:00
LICENSE.enterprise Update Enterprise license copyright notice (#62467) 2024-05-06 17:35:32 +00:00
linter_deps.bzl chore: Remove redundant loop captures (#62264) 2024-04-30 07:57:21 -06:00
mockgen.temp.yaml gitserver: Sunset Exec endpoint (#62774) 2024-06-06 14:36:22 +02:00
mockgen.test.yaml feat/cody-gateway: use Enterprise Portal for actor/productsubscriptions (#62934) 2024-06-07 11:46:01 -07:00
mockgen.yaml bazel: native go-mockgen in Bazel (#60386) 2024-02-16 13:26:48 +00:00
nogo_config.json chore: Remove redundant loop captures (#62264) 2024-04-30 07:57:21 -06:00
package.json feat(ci): Adds playwright tests for sveltekit to bazel (#62560) 2024-06-06 12:45:05 -06:00
pnpm-lock.yaml Svelte: add sentry (#63126) 2024-06-07 15:35:27 +00:00
pnpm-workspace.yaml Create a shared Cody Ignore dataset (#61968) 2024-05-09 13:18:35 +00:00
postcss.config.js
prettier.config.js clean up Cody CSS to increase shareability and improve display in web app (#50279) 2023-04-03 12:29:05 -07:00
README.md Update broken link for our Development docs in the README file (#62638) 2024-05-13 14:13:45 -07:00
release.yaml chore(release): remind releasers of tag pipeline (#63150) 2024-06-07 11:47:11 +01:00
renovate.json Require approval to run Renovate (#57608) 2023-10-18 20:36:53 +02:00
SECURITY.md
service-catalog.yaml lib/servicecatalog: init to distribute catalog (#46999) 2023-01-26 17:22:27 -08:00
sg.config.yaml feat/cmd/gitserver: add memory tracking for both linux and macos (#63114) 2024-06-10 14:26:41 -07:00
shell.nix bazel: use pgutil binaries from GCS instead of from the host (#61741) 2024-04-11 18:00:21 +01:00
stamp_tags.bzl Switch to OCI/Wolfi based image (#52693) 2023-06-02 12:12:52 +02:00
tsconfig.base.json web: fix pnpm-lock issue (#47478) 2023-02-09 22:04:31 -08:00
tsconfig.json release: drop legacy release tooling (#61220) 2024-04-09 14:29:35 -05:00
vitest.shared.ts code intel: Don't rely on URL polyfill to correctly parse git: URIs (#58258) 2023-11-17 19:32:46 +01:00
vitest.workspace.ts vitest: Fix workspace config wrt client/web/ (#58397) 2023-11-17 08:22:46 +00:00
WORKSPACE chore(tooling): bump Go version to 1.22.4 (#63124) 2024-06-06 15:19:03 +00:00

DocsContributingTwitterDiscord

Build status Scorecard Latest release Discord Contributors


Sourcegraph makes it easy to read, write, and fix code—even in big, complex codebases.

  • Code search: Search all of your repositories across all branches and all code hosts.
  • Code intelligence: Navigate code, find references, see code owners, trace history, and more.
  • Fix and refactor: Roll out large-scale changes to many repositories at once and track big migrations.

Getting started



Development

Refer to the Developing Sourcegraph guide to get started.

Documentation

The doc directory has additional documentation for developing and understanding Sourcegraph:

License

This repository contains primarily non-OSS-licensed files. See LICENSE.

Copyright (c) 2018-present Sourcegraph Inc.