Commit Graph

3748 Commits

Author SHA1 Message Date
William Bezuidenhout
9898262143
ci: automatic retry push images job at least 1 (#64145)
Closes DINF-154

## Test plan
CI

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-30 09:32:03 +01:00
Varun Gandhi
3f0a85219c
chore: Move codenav types to lower-level package (#64141)
For the implementation of precise usagesForSymbol, I need to be
able to access some of these types in the codenav package directly, so move
a bunch of types there to avoid an import cycle: codenav -> resolvers -> codenav.
2024-07-30 12:25:11 +08:00
Noah S-C
878931fceb
chore(ci): emit execlog for image push jobs (#64130)
So we can dig into why stuff is being built

## Test plan

CI

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-29 14:08:10 +00:00
William Bezuidenhout
4f5793473f
chore(sg): show cloud ephemeral faq (#64127)
* show a link to the FAQ on certain errors
* add FAQ command to open the FAQ page

Closes  DINF-150
<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

## Test plan
Locally
```
⚠️ Triggering Cloud Ephemeral builds from "main" is not supported.

  Alternatively, if you still want to deploy "main" you can do:

  1. create a new branch off main by running  git switch <branch-name>
  2. push the branch to the remote by running  git push -u origin <branch-name>
  3. trigger the build by running  sg cloud ephemeral build

  FAQ https://www.notion.so/sourcegraph/How-to-deploy-my-branch-on-an-ephemeral-Cloud-instance-dac45846ca2a4e018c802aba37cf6465?pvs=4#20cb92ae27464891a9d03650b4d67cee
```

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-29 15:58:51 +02:00
Noah S-C
51cf4dcba8
fix(ci): reduce push_all concurrency even further due to ratelimits (#64111)
😢 

## Test plan

CI

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-26 19:13:27 +01:00
James Cotter
d2dd9ac454
msp/deploy: remove old author variable (#64107)
Leftover that somehow slipped through 🤦🏻 

## Test plan
CI
<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->
2024-07-26 16:56:53 +01:00
James Cotter
20664df7fc
msp/deploy: use BUILDKITE_BUILD_CREATOR as fallback (#64104)
If a build is triggered from the web the variable BUILDKITE_BUILD_AUTHOR
is not set which the msp_deploy.sh script requires. This PR uses
BUILDKITE_BUILD_CREATOR as a fallback if _AUTHOR is missing

## Test plan
Tested locally
2024-07-26 15:51:09 +01:00
Noah S-C
59a0d15eab
fix(ci): reduce push_all concurrency due to ratelimits (#64106)
<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

## Test plan

CI

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-26 14:44:23 +00:00
Varun Gandhi
6d981c60ad
chore: Update main occurrence extraction code to allow for symbol-based matching (#64082)
At the heart of the loop for extracting usages across a Sourcegraph
instance is the `extractLocationsFromPosition` function, which
extracts related symbols and source ranges from a single SCIP
Document. (Source ranges for returning to the user directly,
and related symbols to do further lookups, e.g. in the case
of inheritance.)

Since we want to perform matching based on symbol names in the upcoming
precise usagesForSymbol API, and also return symbol names for each
associated source range, this function needs to be updated to:
1. Be able to take a symbol name for doing lookups. This is done using
    the new `FindUsagesKey` type which allows two cases - position-based and
    symbol-based.
2. Be able to return symbol names associated with every source range.
    This is done by creating a new `UsageBuilder` type which somewhat subsumes
    the `Location` type. We avoid copying the same 'UploadID' and 'Path'
    fields eagerly for clarity; that will be handled by callers in the future when
    they mix `UsageBuilder` values across different Documents (by first calling `build`).

For the above, I've introduced a new func `extractRelatedUsagesAndSymbolNames`,
and `extractLocationsFromPosition` delegates to that. In the future,
`extractLocationsFromPosition` will be removed.
2024-07-26 18:28:43 +08:00
Noah S-C
1069817b5b
chore(bazel): rework push_all to improve concurrency by avoiding bazel server lock (round 2) (#64079)
Second attempt at https://github.com/sourcegraph/sourcegraph/pull/64044,
now that rate limit is set right. So lets boost the concurrency to all
cores!

## Test plan

main dry-run
https://buildkite.com/sourcegraph/sourcegraph/builds/284268#0190e9cf-b902-4f7c-a1ad-fca8700b8fa0

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-25 12:59:43 +00:00
Varun Gandhi
cadb6d8e70
chore: Unify LsifStore.*SymbolUsages APIs into one (#64076)
For precise usagesForSymbols, we want to propagate usages everywhere
(with associated symbol names, not just 'Location' values). This PR
introduces the new Usage type, and unifies the old GetBulkSymbolUsages and
GetMinimalBulkSymbolUsages APIs into a single GetSymbolUsages API.

We convert the Usage values to Location to avoid changing a lot of code
at once.

We also change the DB query to do grouping and aggregation for us
instead of doing it in Go code.

---------

Co-authored-by: Christoph Hegemann <christoph.hegemann@sourcegraph.com>
2024-07-25 20:45:47 +08:00
YK
09bd207693
Update the outdated link to #dev-experience to #discuss-dev-infra (#64018)
## Test plan

Test each link manually.

---------

Co-authored-by: Bolaji Olajide <25608335+BolajiOlajide@users.noreply.github.com>
2024-07-25 06:58:22 -05:00
Bolaji Olajide
20b858f6c3
fix(build-tracker): Failed back-compat doesn't count towards branch-locking quota (#63911)
Closes
[DINF-51](https://linear.app/sourcegraph/issue/DINF-51/failed-back-compat-doesnt-count-towards-branch-locking-quota)

## Context

If a back-compat step on main fails, the build is marked as having
failed. However, we don't treat that as a failure in build-tracker,
resulting in no #buildkite-main post and not counting towards failed
build quota for locking main.

The reason why this was happening is that the Backcompat build wasn't
linked to the main Sourcegraph build in anyway. However, when a
backcompat fails the main build reflects the status of this failure, but
we do not use this field when determining the status of a build, so it
doesn't work for our use case.

![CleanShot 2024-07-18 at 15 04
15@2x](https://github.com/user-attachments/assets/9553330a-ad98-45cc-b4ce-03a22ca1b99d)

We [instead do a walkthrough of all the jobs associated with a build to
figure
out](https://sourcegraph.sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/dev/build-tracker/main.go?L349-372)
if the build has failed, fixed or is passing.

With this logic, it means we have to link the steps from child builds
that a particular build triggers to it's parent.

## Test plan

* Create a build that'll have backcompat failing
* The build tracker event associated with the main build will be
reported with a state of failed to buildkite.

![CleanShot 2024-07-18 at 15 10
45@2x](https://github.com/user-attachments/assets/1bf503ab-0020-47bf-9512-b3a9ee5d4e36)


## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-25 06:45:09 -05:00
Noah S-C
c016ce08c1
Revert "chore(bazel): rework push_all to improve concurrency by avoiding bazel server lock" (#64051)
Reverts sourcegraph/sourcegraph#64044

Dockerhub cant handle it and keeps ratelimiting us

## Test plan

CI
2024-07-24 19:33:21 +00:00
William Bezuidenhout
0309564f93
ci: make internal+promote release higher priority in runtypes (#64049)
With the https://github.com/sourcegraph/sourcegraph/pull/63985/files
PatchRelease is matched before InternalRelease leading to the wrong
build being generated.

We therefore move the Promote and Internal Release runtypes higher in
priority so that they get matched first.

## Test plan
```
export RELEASE_INTERNAL=true
export VERSION="5.5.2463"
go run ./dev/sg ci preview
```
👇🏼 
```
go run ./dev/sg ci preview
⚠️ Running sg with a dev build, following flags have different default value unless explictly set: skip-auto-update, disable-analytics
If the current branch were to be pushed, the following pipeline would be run:
  Parsed diff:
  changed files: [WORKSPACE client/web-sveltekit/BUILD.bazel client/web-sveltekit/playwright.config.ts client/web-sveltekit/src/lib/navigation/GlobalHeader.svelte client/web-
  sveltekit/src/routes/[...repo=reporev]/(validrev)/(code)/page.spec.ts client/web/src/cody/chat/new-chat/NewCodyChatPage.tsx client/web/src/cody/sidebar/new-cody-sidebar/NewCodySidebar.tsx
  client/web/src/cody/sidebar/new-cody-sidebar/NewCodySidebarWebChat.tsx client/web/src/enterprise/batches/settings/AddCredentialModal.tsx
  client/web/src/enterprise/batches/settings/BatchChangesCreateGitHubAppPage.tsx client/web/src/repo/blame/hooks.ts client/web/src/repo/blame/shared.ts cmd/frontend/auth/user.go
  cmd/frontend/auth/user_test.go cmd/frontend/internal/codycontext/context.go cmd/frontend/internal/codycontext/context_test.go deps.bzl dev/ci/push_all.sh dev/ci/runtype/runtype.go go.mod go.sum
  internal/codeintel/uploads/BUILD.bazel internal/codeintel/uploads/internal/background/backfiller/BUILD.bazel internal/codeintel/uploads/internal/background/backfiller/mocks_test.go
  internal/codeintel/uploads/internal/background/commitgraph/BUILD.bazel internal/codeintel/uploads/internal/background/commitgraph/job_commitgraph.go
  internal/codeintel/uploads/internal/background/expirer/BUILD.bazel internal/codeintel/uploads/internal/background/expirer/mocks_test.go
  internal/codeintel/uploads/internal/background/processor/BUILD.bazel internal/codeintel/uploads/internal/background/processor/mocks_test.go internal/codeintel/uploads/internal/store/BUILD.bazel
  internal/codeintel/uploads/internal/store/commitdate.go internal/codeintel/uploads/internal/store/commitdate_test.go internal/codeintel/uploads/internal/store/observability.go
  internal/codeintel/uploads/internal/store/store.go internal/codeintel/uploads/mocks_test.go internal/database/migration/shared/data/cmd/generator/consts.go
  internal/database/migration/shared/data/stitched-migration-graph.json package.json pnpm-lock.yaml schema/schema.go schema/site.schema.json]
  diff changes: "Go, Client, pnpm, Docs, Shell"
  The generated build pipeline will now follow, see you next time!

  • Detected run type: Internal release
  • Detected diffs: Go, Client, pnpm, Docs, Shell
  • Computed variables:
    • VERSION=5.5.2463
  • Computed build steps:
    • Aspect Workflow specific steps
      • 🤖 Generated steps that include Buildifier, Gazelle, Test and Integration/E2E tests
    • Image builds
      • :bazel::packer: 🚧 Build executor image
    • :bazel: Bazel prechecks & build  sg
    • :bazel: BackCompat Tests
    • :bazel:🧹 Go mod tidy
    • Linters and static analysis
      • 🍍:lint-roller: Run sg lint → depends on bazel-prechecks
    • Client checks
      • :java: Build (client/jetbrains)
      • :vscode: Tests for VS Code extension
      • :stylelint: Stylelint (all)
    • Security Scanning
      • Semgrep SAST Scan
    • Publish candidate images
      • :bazel::docker: Push candidate Images
    • End-to-end tests
      • :bazel::docker::packer: Executors E2E → depends on bazel-push-images-candidate
    • Publish images
      • :bazel::packer:  Publish executor image → depends on executor-vm-image:candidate
      • :bazel:⤴️ Publish executor binary
      • :bazel::docker: Push final images → depends on main::test main::test_2
    • Release
      • Release tests → depends on bazel-push-images
      • Finalize internal release

```
<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-24 18:59:58 +00:00
Noah S-C
14123fcc42
chore(bazel): rework push_all to improve concurrency by avoiding bazel server lock (#64044)
This PR is a second attempt at improving push_all.sh, continuing on from
(and inspired by) https://github.com/sourcegraph/sourcegraph/pull/63391.
As a recap, that PR uses
[--script_path](https://bazel.build/reference/command-line-reference#flag--script_path)
to emit a short bash script for every `oci_push` target, which
essentially does minor setup + invokes the executable as if running
`bazel run`.

While the idea in https://github.com/sourcegraph/sourcegraph/pull/63391
was good, it trades concurrent server locking with an equal amount of
overhead in sequentially building the scripts. By observing the
scripts<b>[1]</b> that it would emit, we can notice a few things:
- The path
`/home/noah/.cache/bazel/_bazel_noah/8fd1d20666a46767e7f29541678514a0/execroot/__main__/bazel-out/k8-fastbuild/bin/`
shows up twice, which is the same path that `./bazel-bin` points at
- The script only `cd`'s to a path, unsets some environment variables,
and then executes the underlying script of the target.

The path can be observed to be a combination of bazel-bin, the target's
package (`//cmd/batcheshelper` in this case), as well as the target with
some extra static strings (`candidate_push` with `push_` prefix and
`.sh{,.runfiles}` suffixes for the script & its runfiles respectively).
Knowing this, and assuming that this is reliably so, we can opt to
recreate this manually instead, saving on the hefty overhead of `bazel
run --script_path`.

The current average times for `Push candidate images` and `Push final
images` are ~7m50s and ~8m30s respectively. While the example
main-dry-run build
[here](https://buildkite.com/sourcegraph/sourcegraph/builds/284041#0190e54a-9aaa-471a-81bf-623fce6ffa45)
isnt fully representative of how much rebuilding is required, it sets a
pretty solid 3m20s baseline.

Note this may break with rules_oci changes, but imo thats a small and
very infrequent cost to pay for cleaner log output + shaving a good
piece of time off.

<details><summary><b>[1]</b> A <code>--script_path</code>
example</summary>

```
#!/nix/store/mqc7dqwp046lh41dhs7r7q7192zbliwd-bash/bin/bash
cd /home/noah/.cache/bazel/_bazel_noah/8fd1d20666a46767e7f29541678514a0/execroot/__main__/bazel-out/k8-fastbuild/bin/cmd/batcheshelper/push_candidate_push.sh.runfiles/__main__ && \
  exec env \
    -u JAVA_RUNFILES \
    -u RUNFILES_DIR \
    -u RUNFILES_MANIFEST_FILE \
    -u RUNFILES_MANIFEST_ONLY \
    -u TEST_SRCDIR \
    BUILD_WORKING_DIRECTORY=/home/noah/Sourcegraph/sourcegraph \
    BUILD_WORKSPACE_DIRECTORY=/home/noah/Sourcegraph/sourcegraph \
  /home/noah/.cache/bazel/_bazel_noah/8fd1d20666a46767e7f29541678514a0/execroot/__main__/bazel-out/k8-fastbuild/bin/cmd/batcheshelper/push_candidate_push.sh "$@"
```

</details> 

## Test plan

Observe a `sg ci build main-dry-run`
[here](https://buildkite.com/sourcegraph/sourcegraph/builds/284041#0190e54a-9aaa-471a-81bf-623fce6ffa45).

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-24 16:55:09 +01:00
Varun Gandhi
dc7da57edb
chore: Make location fetching queries more uniform (#64026)
This patch changes the location querying code so that:
1. We're populating structures corresponding to SCIP instead of LSIF
   (with "scheme" and "identifier" inside "MonikerData")
2. Avoid repeatedly allocating a constant string 'scip' for the scheme
    only to throw it away later.
3. Makes the two queries and their scanning code more similar for easier
    comparison. When I land precise usagesForSymbol, I will de-duplicate
    some of the scanning code between these two queries.

I have avoided renaming all of the local variables to avoid creating
more noise.

## Test plan

Covered by existing tests.
2024-07-24 11:14:22 +02:00
Will Dollman
9dd901f3c9
Integrate security release approval into release pipeline (#63990)
As part of the [Vuln Scanning
Improvements](https://linear.app/sourcegraph/project/[p0]-vulnerability-scanning-improvements-75299c4312dd/issues)
project, I've been working on tooling to automate the security approval
step of the release process.

This PR integrates these improvements into the release pipeline:

* Internal releases will run a vulnerability scan
* Promote-to-public releases will check for security approval

If a public release does not have security approval, it will block the
promotion process. The step happens at the start of the pipeline so
should be a fast-fail. You can also check for release approval before
running promotion by running `@secbot cve approve-release <version>` in
the #secbot-commands channel. In an ideal world we (security) will have
already gone through and approved ahead of release.

I've tested this PR as much as I can without running an actual release!
We have a 5.5.x release tomorrow so it'll be a good test. If it does
cause problems that can't be easily solved, it can always be temporarily
disabled.

I've tagged this PR to be backported to `5.5.x`.

<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

## Pre-merge checklist

- [x] Revert commit that disables release promotion

## Test plan

Manual testing of the release process:
- [x] [Successful test
run](https://buildkite.com/sourcegraph/sourcegraph/builds/283774#0190dfd6-fa70-4cea-9711-f5b8493c7714)
that shows the security scan being triggered
- [x] [Promote to public test
run](https://buildkite.com/sourcegraph/sourcegraph/builds/283826) that
shows the security approval approving a release
- [x] [Promote to public test
run](https://buildkite.com/sourcegraph/sourcegraph/builds/283817#0190e0ec-0641-4451-b7c7-171e664a3127)
that shows the security approval rejecting a release with un-accepted
CVEs

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-24 09:19:49 +01:00
Varun Gandhi
1b0e004d03
chore(codeintel): Rename uploads/../Store -> codegraph/../DataStore (#64001)
Also consolidates mocks to avoid wasting time generating
and compiling them repeatedly, and reducing pollution of
Find Usages results in the editor (yes, I know these can be
filtered out, but it's silly to have multiple copies).
2024-07-24 08:24:20 +01:00
Bolaji Olajide
067115910c
fix(ci): check command out for error when git fails (#63993)
Closes [#1110](https://github.com/sourcegraph/devx-support/issues/1110)
Closes DINF-96

We don't print the stdErr when a command fails … in particular when git
fails. Therefore we see very little in the panic of what went wrong.

Explanation:
> There's a weird behavior that occurs where an error isn't accessible
in the err variable
// from a *Cmd executing a git command after calling CombinedOutput().
// This occurs due to how Git handles errors and how the exec package in
Go interprets the command's output.
// Git often writes error messages to stderr, but it might still exit
with a status code of 0 (indicating success).
// In this case, CombinedOutput() won't return an error, but the error
message will be in the out variable.

## Test plan

Manual testing

```go
func main() {
	ctx := context.Background()
	cmd := exec.CommandContext(ctx, "git", "rev-parse", "--is-inside-work-tree")
	out, err := handleGitCommandExec(cmd)
	if err != nil {
		// er := errors.Wrap(err, fmt.Sprintf("idsdsd: %s", string(out)))
		panic(err)
	}
	fmt.Println("hello", string(out))
}
```

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-23 09:56:33 -05:00
Varun Gandhi
eeded69538
feat(build): Add exhaustruct linter (codeintel POC) (#63965)
For certain types, we do not want the zero-value initialization for structs.
This means we need to trade off readability vs exhaustive initialization
checking, as the Go syntax `Foo{Bar: bar}` is more readable, but doesn't do
exhaustiveness checking, and `Foo{bar}` does check for exhaustiveness but can be less
readable depending on context.

For now, the check is only introduced for one type, and is meant to be
opt-in so that code authors may choose for stricter checking.
2024-07-23 17:26:01 +08:00
Varun Gandhi
548cb609f3
chore(codeintel): Move mock generation near interface package (#64000)
This patch moves the mocks for `codenav/../lsifstore` package to a
separate package `lsifstore/mocks` instead of it living in `codenav`.
The problem is that if you update the `LsifStore` interface, then you
get an error when trying to regenerate mocks, as regeneration happens
in the `codenav` package, and that package's old mocks no longer
satisfy the new interface (so there is an error when looking at other test
files). Moving the codegen to a separate package avoids this problem.
2024-07-23 09:24:53 +01:00
Will Dollman
b7242d280f
Publish images for all commits on release branches (#63985)
In order to run nightly vulnerability scans of Sourcegraph releases, we
need to publish a new set of images whenever the release branch is
pushed to.

Previously, this was implemented in
https://github.com/sourcegraph/sourcegraph/pull/63379 but with RFC 795
the release branch format changed from 5.5.1234 to 5.5.x.

This PR updates the regex to catch this new format.

The end result of this is that whenever Buildkite runs on a branch
matching `\d.\d.x`, it will push images to the
`us.gcr.io/sourcegraph-dev/gitserver` registry with the tag
`$branch-insiders`.

I've also tagged this PR for backport as we want it on the current patch
release branch 5.5.x :)

<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

## Test plan

- Test buildkite run on branch `will-0.0.x` (with modified regex to
match that branch)
https://buildkite.com/sourcegraph/sourcegraph/builds/283608

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-22 16:12:56 +01:00
Quinn Slack
1fe876e89c
finish removing chromatic (#63966)
We removed Chromatic in
https://github.com/sourcegraph/sourcegraph/pull/62228, but there were
still some remnants.

## Test plan

CI
2024-07-21 18:37:02 -07:00
Varun Gandhi
9145768648
chore: Rename uploadstore packages for clarity (#63931)
- The `internal/uploadstore` package is renamed to `object` indicating
   that it is meant to provide a generic object storage wrapper.
- The `search/exhaustive/uploadstore` package is used in very few places
  so I've merged into the `internal/search` package similar to
  `internal/embeddings`.

There are a few reasons to do the renaming.

1. The word `upload` in a more general context is ambiguous (just in
    `internal/`) - in the codeintel context, it means "SCIP index" but it
    can also be interpreted generically ("upload of _some_ data").
2. Better readability - `object.Storage` is much shorter than
    `uploadstore.Store`. Additionally, we use the term `Store` A LOT
    in the codebase, and usually, these refer to wrappers over some
    tables in some DB.

    Making things worse, some of our code also has:

    ```
    uploadsstore
"github.com/sourcegraph/sourcegraph/internal/codeintel/uploads/internal/store"
    ```

And code which says `uploadsstore.Store` (notice the extra `s` 😢), which
is actually a wrapper over some key DB tables like `lsif_uploads`.
2024-07-22 08:57:56 +08:00
Robert Lin
30d50b72a2
feat/sg: add 'sg sams client create' (#63885)
Adds an equivalent to the curl command we currently share, but in `sg`.
If we add a better API around this later it's just an in-place
replacement.

Similar to https://github.com/sourcegraph/sourcegraph/pull/63883 this
"just works" with zero configuration against SAMS-dev.

Part https://linear.app/sourcegraph/issue/CORE-220, a spike into
polishing some local-dev DX for SAMS.

## Test plan

```
sg sams client create -redirect-uris='https://sourcegraph.test:3443/.auth/callback' robert-testing
```

if you hit an error loading the secret, e.g. targeting the prod
instance, you get a suggestion to get Entitle access:

```
sg sams client create -redirect-uris='https://sourcegraph.test:3443/.auth/callback' -sams='https://accounts.sourcegraph.com' robert-testing
⚠️ Running sg with a dev build, following flags have different default value unless explictly set: skip-auto-update, disable-analytics
👉 Failed to get secret - do you have Entitle access to the "sourcegraph-accounts-prod-csvc" project? See https://sourcegraph.notion.site/Sourcegraph-Accounts-infrastructure-operations-b90a571da30443a8b1e7c31ade3594fb
 google(sourcegraph-accounts-prod-csvc): failed to get secret "MANAGEMENT_SECRET": rpc error: code = PermissionDenied desc = Permission 'secretmanager.versions.access' denied for resource 'projects/sourcegraph-accounts-prod-csvc/secrets/MANAGEMENT_SECRET/versions/latest' (or it may not exist).
```
## Changelog

- `sg sams client create` can now be used to create IdP clients for
SAMS.

---------

Co-authored-by: Erik Seliger <erikseliger@me.com>
2024-07-19 13:41:28 -07:00
Robert Lin
51bfacf851
feat/sg: allow sg commands to default to local-dev SAMS-dev credentials (#63883)
As it says on the tin - various commands related to SAMS can now target
dev services integrated against SAMS-dev directly. See test plan for
examples.

I've also refactored the `sg sams introspect-token` etc commands in
preparation for introducing more `sg sams` commands - the existing
commands are now collapsed into `sg sams token introspect` and `sg sams
token introspect -p`

Part https://linear.app/sourcegraph/issue/CORE-220, a spike into
polishing some local-dev DX for SAMS.

I also upgrade the glamour library because I noticed the JSON
pretty-printing was no longer colored - the upgrade fixed that

## Test plan

All the below now work with no additional effort:

```sh
# get token details and print a temporary token
sg sams token introspect -p
# list enterprise-portal-dev data
sg enterprise subscription list -member.cody-analytics-viewer 'robert@sourcegraph.com'
```

You can use it against locally running services that connect to SAMS-dev
as well, for example the below also works with no additional
flags/envvars:

```sh
sg start dotcom # includes enterprise-portal
sg enterprise subscription list -enterprise-portal-server=http://localhost:6081
```

## Changelog

- `sg` commands requiring SAMS client credentials now load shared
SAMS-dev client credentials by default.
2024-07-19 11:25:26 -07:00
Camden Cheek
033cb9d901
Search: add regex support to repo:has.meta() (#63891)
This adds support to searching for repo metadata with a regex pattern.

Background: repo metadata is a useful feature for shoehorning
business-specific information into the search query language. It allows
tagging repos with arbitrary metadata (think ownership info, quality
info, 3rd-party system IDs, etc.). This ends up being a useful escape
hatch to shim in functionality that is not natively supported in
Sourcegraph.

However it's currently limited to searching with an exact key/value
pair. We've had a few requests to extend this to allow searching by
pattern because it enables ingesting semi-structured data and making it
searchable.

This adds the ability to use a `/.../`-delimited regex pattern to match
against both keys and values. For example,
`repo:has.meta(team:/^my\/org/)`
2024-07-19 11:53:24 -06:00
Warren Gifford
43df26fab3
feature/release: update sg release cut to automate stitch graph gen and release branch creation (#63794)
<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

Resolve:
[https://linear.app/sourcegraph/issue/REL-253/bug-automate-the-stitched-migration-graph-bazel-archive-generation](https://linear.app/sourcegraph/issue/REL-253/bug-automate-the-stitched-migration-graph-bazel-archive-generation)

## Test plan
Tested by running `go run ./dev/sg release cut --version “5.7.0"`

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->

---------

Co-authored-by: Anish Lakhwara <anish+git@lakhwara.com>
Co-authored-by: Anish Lakhwara <anish+github@lakhwara.com>
2024-07-18 23:15:04 -07:00
Geoffrey Gilmore
12570e4ee4
Revert "fix(sg): resolve overwrite env ordering in sg (#63838)" (#63924)
https://github.com/sourcegraph/sourcegraph/pull/63838 accidentally broke
the local-dev site configuration workflow (the site-configuration from
local dev was replaced with a stock configuration).

 Reverting this is probably the fastest way to resolve this. 

See https://sourcegraph.slack.com/archives/C07KZF47K/p1721329375844059
for more context.

## Test plan

CI

## Changelog

- The flawed env overwriting logic in sg from
https://github.com/sourcegraph/sourcegraph/pull/63838 has been reverted.
2024-07-18 20:46:35 +00:00
James Cotter
4c040347ec
sg/msp: enable alerting by default for production projects (#63912)
<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->
Opsgenie alert notifications for critical alerts should be enabled by
default for production projects or where `env.alerting.opsgenie` is set
to true.

Closes CORE-223
## Test plan
Tested locally by running `sg msp gen` for a `prod` env which doesn't
have an alerting config and verifying that notification suppression was
disabled

Set `env.alerting.opsgenie` to false which enabled suppression again.

No changes to `test` environments unless `env.alerting.opsgenie` is set
to true.
2024-07-18 20:57:38 +01:00
Robert Lin
f6ce941610
feat/sg: do not persist external secrets (#63890)
Secrets fetched from GSM should probably not be stored locally. As we
increase the usage of fetching external secrets, this stuff is
increasingly sensitive, particularly for SAMS stuff - every time it's
used, we should ensure that the user has the required permissions, and
also only store external secrets in-memory.

It looks like several other callsites make use of the persistence of
other secrets e.g. those prompted from users, so this change
specifically targets the `GetExternal` method. Additionally, I also
added a check on load to delete any legacy external secrets that are
stored to disk on load - we can remove this after a few weeks.

## Test plan

Unit tests asserts old behaviour and new desired behaviour

`sg start -cmd cody-gateway` uses external secrets and works as expected

After running `sg`, `sg secret list` has no external secrets anymore
2024-07-18 10:04:24 -07:00
Bolaji Olajide
857ade25db
fix(sg): resolve overwrite env ordering in sg (#63838)
Closes
[DINF-58](https://linear.app/sourcegraph/issue/DINF-58/overwrite-ordering-in-sg)


https://github.com/user-attachments/assets/d8e59a5f-9390-47f7-a6a7-9ccbf97423f8

## Test plan

- Add a `commandset` to the `sg.config.overwrite.yaml`
- This commandset should depend on an existing command in the
`sg.config.yaml` file.
- The commandset should also include an `env var` that should override
what's set in the `command` contained in the `sg.config.yaml` file.
- Running `sg start <commandset name>` should allow the env ordering
matrix shown below

```
Priority: overwrite.command.env > overwrite.commandset.env > command.env > commandset.env.
```

## Changelog

N/A
2024-07-18 12:01:04 -05:00
Noah S-C
b7dac3b808
fix(ci): only emit bazel execlog artifact for 'test' commands (#63916)
Delivery Manifest step has started to run `bazel build` commands, in them clobbering our execlog artifacts. We should only emit it for the test buildkite jobs (at least for the time being), as it currently doesnt make sense for e.g. the image push jobs which contain multiple invocations

## Test plan

CI

## Changelog
2024-07-18 15:17:12 +01:00
Rafał Gajdulewicz
7211c8cdb2
[sg] Make rfc command use private RFCs by default (#63902)
This PR changes the `sg rfc` command to introduce a new flag `--public`
(previously, an implicit default) and removes the flag `--private` (new
default).

This change implements part of our new approach to RFCs (private by
default,
[context](https://sourcegraph.slack.com/archives/C03L2R35ENL/p1719013625952019)
[need to
follow-up](https://sourcegraph.slack.com/archives/C01GNBB34FR/p1720813994240309?thread_ts=1720626835.727909&cid=C01GNBB34FR)).

## Test plan

- ran `sg rfc create "test new default"` and a private
[RFC](https://docs.google.com/document/d/1gGrejPvHQaeKPrHr4PW_XxdArZQ4iUAWxlhkjglaNQc/edit#heading=h.trqab8y0kufp)
was created
- ran `sg rfc --public create "test public"` and a public
[RFC](https://docs.google.com/document/d/1K_ElZWyvCNV3QMGoBr9-h4L0h_2wswbVauEjmzD6shk/edit#heading=h.trqab8y0kufp)
was created
- ran `sg rfc list` and private RFCs were listed
- ran `sg rfc --public list` and public RFCs were listed
2024-07-18 14:12:28 +02:00
William Bezuidenhout
26c2b33262
sg: check for nil multiError (#63889)
Fixes https://github.com/sourcegraph/devx-support/issues/1097

## Test plan
Before
```
👉 [      step] Pretending to run step "github:pr"
   [ github:pr] set -eu
   [ github:pr] gh pr create \
   [ github:pr]   --fill \
   [ github:pr]   --draft \
   [ github:pr]   --title "(internal) release_patch: build v5.5.1220" \
   [ github:pr]   --body "Test plan: automated release PR, CI will perform additional checks"
   [ github:pr] echo "🚢 Please check the associated CI build to ensure the process completed".
   [ github:pr]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x20 pc=0x1059c1380]

goroutine 42 [running]:
github.com/sourcegraph/sourcegraph/dev/sg/internal/analytics.processEvents({0x10b4a71d8, 0x1400188eaf0}, 0x1400330a140, {{0x10b482ed8?, 0x140033141f8?}}, 0x140033080c0)
        github.com/sourcegraph/sourcegraph/dev/sg/internal/analytics/background.go:107 +0x320
main.init.func52.BackgroundEventPublisher.4({0x10b4a71d8, 0x1400188eaf0}, 0x1400330a140)
        github.com/sourcegraph/sourcegraph/dev/sg/internal/analytics/background.go:30 +0x14c
github.com/sourcegraph/sourcegraph/dev/sg/internal/background.Run.func1()
        github.com/sourcegraph/sourcegraph/dev/sg/internal/background/background.go:62 +0x74
created by github.com/sourcegraph/sourcegraph/dev/sg/internal/background.Run in goroutine 1
        github.com/sourcegraph/sourcegraph/dev/sg/internal/background/background.go:57 +0x174
```
After
```
👉 [      step] Pretending to run step "github:pr"
   [ github:pr] set -eu
   [ github:pr] gh pr create \
   [ github:pr]   --fill \
   [ github:pr]   --draft \
   [ github:pr]   --title "(internal) release_patch: build v5.5.1220" \
   [ github:pr]   --body "Test plan: automated release PR, CI will perform additional checks"
   [ github:pr] echo "🚢 Please check the associated CI build to ensure the process completed".
   [ github:pr]

deploy-sourcegraph-k8s on  main [?⇕] via 🐹 v1.22.3 took 5s
```

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-17 19:53:41 +00:00
William Bezuidenhout
658d12ea35
fix(sg): better err msg for when we fail to insert to bigquery (#63873)
Part of: https://github.com/sourcegraph/devx-support/issues/1093

If we get 3 errors in a row trying to write to bigquery ... chances are
we are not going to succeed. So we exit early.

## Test plan
CI
## Changelog
- sg: provide a better error message when we fail to insert into
bigquery
- sg: stop puslishing to bigquery if we get 3 errors in a row
2024-07-17 18:35:56 +02:00
Robert Lin
6d25e2d672
feat/sg/enterprise: add 'sg enterprise set-name' (#63832)
Testing for display-name setting which we recently added, and this is
useful in the interim to set display names on the go for subscriptions
EP already tracks.

note: I don't anticipate doing this for every field we make update-able,
especially since the next step(s) will be updating the UI

## Test plan

```
sg enterprise subscription set-name es_4dae04ba-5f5b-431a-b90b-e8e3dd449181 "robert's test subscription"
```
2024-07-17 09:30:54 -07:00
Robert Lin
61cb0dc807
feat/sg: support correct completions on 'sg start -cmd' (#63861)
`sg run` is supposed to be deprecated in favour of `sg start -cmd`, but
the `sg start` completions don't work with `-cmd` like `sg run` does.

This change updates `sg start` completion to check for the `-cmd` flag,
and if it is provided, offer completions for commands instead of
command_sets_ (the default `sg start` behaviour).

## Test plan

<img width="1023" alt="image"
src="https://github.com/user-attachments/assets/9b887180-f58f-4aef-9dbb-718c71ba15e6">

<img width="1077" alt="image"
src="https://github.com/user-attachments/assets/927b4562-fce1-48c0-a8c5-453bfc60fe35">

## Changelog

- Completions for `sg start -cmd` now offer valid suggestions.
2024-07-16 12:11:11 -07:00
Robert Lin
6212f2585c
chore/sg: clean up help formatting (#63860)
Noticed several `Usage` using newlines, which makes `-h` output pretty
annoying to read as it breaks up the formatting. It tickled me enough to
put a formatting check against it, and update the existing usages that
were incorrect, to use `Description` or `UsageText` instead :-)

## Test plan

CI, `sg -h` is pretty(er) again (but still very long)
2024-07-16 12:01:06 -07:00
Robert Lin
879646a20e
feat/sg/msp: helpful error on cloudsqlproxy port conflict (#63830)
Ported from https://github.com/sourcegraph/controller/pull/1622 :) 

## Test plan

n/a
2024-07-15 11:32:37 -07:00
William Bezuidenhout
d7db73f0cd
fix(nix/p4-fusion): update p4-fusion helix-api hashes (#63805)
Failed run here
https://github.com/sourcegraph/p4-fusion/actions/runs/9890851838/job/27320002177.

I tried looking at the sha256 hashes here -
https://filehost.perforce.com/perforce/r22.2/bin.macosx12arm64/SHA256SUMS

But there is no clear way to convert to the nix format. There is `nix
hash convert` but it's not available in my nix version.

So ... I took the values reported in the workflow and used them in this
PR

## Test plan
CI
## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-15 10:20:33 +02:00
William Bezuidenhout
55f5dc7d91
fix(sg): do not try to publish analytics when it is disabled (#63800)
The background publisher was started regardless if analytics was
disabled or not. This PR makes it so that we only publish analytics if
it is enabled.

To make it work and not duplicate the disabled analytics check, I moved
the usershell + background context creation to happen earlier.

## Test plan
CI and tested locally

## Changelog
* sg - only start the analytics background publisher when analytics are
enabled

---------

Co-authored-by: Jean-Hadrien Chabran <jh@chabran.fr>
2024-07-12 12:45:08 +02:00
Craig Furman
a20b0650b4
feat(appliance): self-update (#63780)
**chore(appliance): extract constant for configmap name**

To the reconciler, this is just a value, but to higher-level packages
like appliance, there is a single configmap that is an entity. Let's
make sure all high-level orchestration packages can reference our name
for it. This could itself be extracted to injected config if there was a
motivation for it.



**chore(appliance): extract NewRandomNamespace() in k8senvtest**

From reconciler tests, so that we can reuse it in self-update tests.



**feat(appliance): self-update**

Add a worker thread to the appliance that periodically polls release
registry for newer versions, and updates its own Kubernetes deployment.

If the APPLIANCE_DEPLOYMENT_NAME environment variable is not set, this
feature is disabled. This PR will be accompanied by one to the
appliance's helm chart to add this variable by default.



**fix(appliance): only self-update 2 minor versions above deployed SG**




**chore(appliance): self-update integration test extra case**

Check that self-update doesn't run when SG is not yet deployed.

https://linear.app/sourcegraph/issue/REL-212/appliance-can-self-upgrade
2024-07-11 17:59:39 +01:00
William Bezuidenhout
ccae82a85b
fix(sg): return different error types depending on secret failure (#63779)
If we failed getting a secret via a tool - we return CommandErr which
contains SecretErr
If we failed getting a secret via Google - we return GoogleSecretErr
which contains SecretErr

Depending on the error we get while trying to persist Analytics we
suggest different fixes the user can try.

Below is how it looks when we get a GoogleSecretErr

![Screenshot 2024-07-11 at 11 11
40](https://github.com/sourcegraph/sourcegraph/assets/1001709/12479561-c1f5-4de7-b00e-01a1fbb49ece)

## Test plan
Tested locally
<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-11 18:26:14 +02:00
Robert Lin
a07a1b9ed0
chore/sg: remove 'sg telemetry' and related docs (#63763)
Removes the `sg telemetry` command that pertains to the legacy V1
exporter that is specific to Cloud instances.

I got asked about this recently, and especially with the new `sg
analytics` for usage of the `sg` CLI, this has the potential to be
pretty confusing.

Part of https://linear.app/sourcegraph/issue/CORE-104

## Test plan

n/a

## Changelog

- `sg`: the deprecated `sg telemetry` command for allowlisting export of
V1 telemetry from Cloud instances has been removed. Use telemetry V2
instead.
2024-07-10 17:25:04 -07:00
Shivasurya
9e95499625
chore(security) : upgrade src-cli version to address CVE (#63750)
Docker images executor, executor-kubernetes, bundled-executor has
reported high/critical CVE-2024-24790 , CVE-2023-45288 reported on
golang stdlib. Upon testing, src version 5.3.0 was using `1.20.x` as per
e8e79e0311

This pull request attempts to upgrade src version to 5.4.0

## Test plan

- CI 🟢 
- src version should report 5.4.0 (I built the image locally and tested
it)
`docker run --platform linux/amd64 -it --entrypoint /bin/sh
executor:candidate`

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->

Upgrade src-cli version to 5.4.0 to address CVE-2024-24790 ,
CVE-2023-45288
2024-07-10 09:57:16 -04:00
William Bezuidenhout
ddc27b887f
feat(sg/cloud): trigger build on cloud-ephemeral pipeline (#63748)
Currently if a cloud ephemeral build is trigger it is triggered on the
`main` sourcegraph pipeline. Once a build a triggered and a commit is
subsequently pushed the previous build is cancelled - which means the
Cloud Ephemeral build is cancelled leading to a failed deployment.

In this PR, we instead trigger a build on the Cloud Ephemeral pipeline.
Which is the _exact_ pipeline as `sourcegraph` main but:
- sets the pipeline env to always have `CLOUD_EPHEMERAL=true`
- does not cancel previous builds

## Test plan
https://buildkite.com/sourcegraph/cloud-ephemeral/builds/1


## Changelog
* `sg cloud eph` will now trigger builds on the `cloud-ephemeral`
pipeline
2024-07-10 11:58:46 +02:00
Erik Seliger
41fdc5cc7c
symbols: Make symbols specific code internal (#63736)
This PR restructures the packages to move all symbols-only code into the
symbols service. This helps to reason better about which service is
accessing what datastores.

Test plan:

Just moved code, compiler and CI are happy.
2024-07-10 01:26:22 +02:00
Shivasurya
c3c706bc82
chore(security): Updated dind image to 27-0-3 (#63725)
<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

Patches CVE-2024-24790 by upgrading to 27-0-3 tag. However, the patched
version has CVE-2024-24791 😟 and it doesnt have patch.

## Test plan

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->
Build and test image locally.

### Instruction to build and test locally

- Go to `dev/oci_deps.bzl`
- Find the current tag example `docker:26.1.3-dind`
- Go to docker registry and search for updated tag and grab one example:
`docker:27.0.3-dind`
- docker pull --platform linux/amd64 docker:27.0.3-dind
- Add `platforms = ["linux/amd64"],` to the oci_pull for building and
testing locally
```bzl
  oci_pull(
        name = "upstream_dind_base",
        digest = "sha256:2632da0d24924b179adf1c2e6f4ea6fb866747e84baea6b2ffaa8bff982ce102",
        platforms = ["linux/amd64"],
    )
```
- Run `sg images build dind`
- For testing, run `docker run --rm -it --entrypoint /bin/sh -v
/var/run/docker.sock:/var/run/docker.sock dind:candidate`
- Test docker commands and pull and run image for testing

## Changelog

- Upgraded dind to 27.0.3 to patch CVE-2024-24790 vulnerability

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-09 12:59:18 -04:00
Jean-Hadrien Chabran
fea61ce01b
chore(local): sg analytics use the proper open wrapper (#63722)
We missed during the review that we are not using the `open` helper that
wraps using the right method depending on the OS, which means that `sg
analytics` doesn't work on Linux as is.

## Test plan

Locally tested.
2024-07-09 15:04:59 +00:00
William Bezuidenhout
5fd7947545
sg: when in CI we do not need to prompt for an identity (#63712)
There are cases when we use SG in CI and then we do not want to prompt
for identity

## Test plan
CI, unit tests and tested locally

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-09 15:58:44 +02:00
Noah S-C
e669330215
feat(sg): sqlite-backed local store for sg analytics (#63578)
Removes existing `sg analytics` command and replaces it with a
one-per-invocation sqlite backed approach. This is a local storage for
invocation events before theyre pushed to bigquery

## Test plan

```
sqlite> select * from analytics;
0190792e-af38-751a-b93e-8481290a18b6|1|{"args":[],"command":"sg help","flags":{"help":null,"sg":null},"nargs":0,"end_time":"2024-07-03T15:20:21.069837706Z","success":true}
0190792f-4e2b-7c35-98d6-ad73cab82391|1|{"args":["dotcom"],"command":"sg live","flags":{"live":null,"sg":null},"nargs":1,"end_time":"2024-07-03T15:21:04.563232429Z","success":true}
```

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->

---------

Co-authored-by: William Bezuidenhout <william.bezuidenhout@sourcegraph.com>
2024-07-09 12:47:49 +02:00
Noah S-C
d9dff1191a
feat(sg): one-time oauth login to persist user email for analytics (#63603)
Uses OAuth flow to fetch user's email as a one-time action, persisting
it in ~/.sourcegraph/whoami.json. Flow is only re-attempted if that file
doesnt exist (failed to read) or if the email is empty.

Code yoinked and adapted from @nelsonjr 's code for `sg rfc` 🙏 


![image](https://github.com/sourcegraph/sourcegraph/assets/18282288/bfcd315b-dcbd-412d-a53c-86479c8475c7)

## Test plan

Tested locally, see screenshots above

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->

---------

Co-authored-by: William Bezuidenhout <william.bezuidenhout@sourcegraph.com>
2024-07-09 12:07:17 +02:00
Jean-Hadrien Chabran
e223b3be41
chore(local): simplify sg teammate (#63667)
Drive by fix, dropped a few names who left the company and simplified
commands.

See DINF-106 

Before: `sg teammate time|details olaf` 
After: `sg teammate olaf` (shows both of the above) 

## Test plan

Locally tested + CI.
2024-07-09 10:29:37 +02:00
Robert Lin
28348e7c80
feat/msp: allow enablement of logical replication features for Datastream (#63092)
Adds a new `postgreSQL.logicalReplication` configuration to allow MSP to
generate prerequisite setup for integration with Datastream:
https://cloud.google.com/datastream/docs/sources-postgresql. Integration
with Datastream allows the Data Analytics team to self-serve data
enrichment needs for the Telemetry V2 pipeline.

Enabling this feature entails downtime (Cloud SQL instance restart), so
enabling the logical replication feature at the Cloud SQL level
(`cloudsql.logical_decoding`) is gated behind
`postgreSQL.logicalReplication: {}`.

Setting up the required stuff in Postgres is a bit complicated,
requiring 3 Postgres provider instances:

1. The default admin one, authenticated with our admin user
2. New: a workload identity provider, using
https://github.com/cyrilgdn/terraform-provider-postgresql/pull/448 /
https://github.com/sourcegraph/managed-services-platform-cdktf/pull/11.
This is required for creating a publication on selected tables, which
requires being owner of said table. Because tables are created by
application using e.g. auto-migrate, the workload identity is always the
table owner, so we need to impersonate the IAM user
3. New: a "replication user" which is created with the replication
permission. Replication seems to not be a propagated permission so we
need a role/user that has replication enabled.

A bit more context scattered here and there in the docstrings.

Beyond the Postgres configuration we also introduce some additional
resources to enable easy Datastream configuration:

1. Datastream Private Connection, which peers to the service private
network
2. Cloud SQL Proxy VM, which only allows connections to `:5432` from the
range specified in 1, allowing a connection to the Cloud SQL instance
2. Datastream Connection Profile attached to 1

From there, data team can click-ops or manage the Datastream Stream and
BigQuery destination on their own.

Closes CORE-165
Closes CORE-212

Sample config:

```yaml
  resources:
    postgreSQL:
      databases:
        - "primary"
      logicalReplication:
        publications:
          - name: testing
            database: primary
            tables:
              - users
```

## Test plan

https://github.com/sourcegraph/managed-services/pull/1569

## Changelog

- MSP services can now configure `postgreSQL.logicalReplication` to
enable Data Analytics team to replicate selected database tables into
BigQuery.
2024-07-05 18:24:44 +00:00
Jean-Hadrien Chabran
2dfeb486d5
fix(local): fix race in sg_start_test.go (#63642)
Fixes DINF-82; This was very much a rabbithole. A few things: 

- The race that @bobheadxi mentioned here
https://github.com/sourcegraph/sourcegraph/pull/63405#discussion_r1648180713
wasn't from `*output.Output` being unsafe, but `outputtest.Buffer` as it
happened again (see
[DINF-82](https://linear.app/sourcegraph/issue/DINF-82/devsgsg-test-failed-with-a-detected-race-condition))
- There something messed up with `cmds.start()`, which sometimes ends up
printing the command output _after_ the exit message instead of before.
- The crude `sort.Strings(want|have)` that was there already fixes that.
- And without the sleep, it's possible to read the output from the
`outputtest.Buffer` before the command outputs get written to it.
- The `time.Sleep(300 * time.Milliseconds)` _mitigates/hides_ that
problem.

At least, this shouldn't blow up in CI and buys us time to fix the whole
thing. We're tracking this in DINF-104. And out of 200 runs, I also
stumbled on a race in `progress_tty`, tracked in DINF-105 (that packages
is originally meant to be used by `src-cli` and was re-used for `sg` 3
years ago).

I'm pretty unhappy about the solution, but a bandage is better than
nothing. While ideally, we should really reconsider dropping
`std.Output` entirely in `sg` and use the good stuff from
github.com/charmbracelet instead because we don't want to spend too much
time on arcane terminal things ourselves, I'm much more about concerned
the concurrency issues mentioned above.

## Test plan

CI + `sg bazel test //dev/sg:sg_test --runs_per_test=100`
2024-07-04 19:11:10 +02:00
Geoffrey Gilmore
07beefe528
fix/internal/observation: make ErrCollector type threadsafe (#63496)
Closes https://linear.app/sourcegraph/issue/SRC-410/race-in-gitserver-observability

This PR adds a mutex to the internal/observation.ErrCollector type that makes it safe to use across multiple goroutines. 

(This could quite easily happen, as the FinishFunc's OnCancel method runs the logic that accesses/modifies ErrReporter in a separate goroutine:)

fa46a26f7a/internal/observation/observation.go (L156-L170)

## Test plan

CI now passes and doesn't report race conditions


## Changelog

- Fixed a threadsafety issue in the internal/observation.ErrCollector type
2024-07-03 11:10:28 -07:00
Jean-Hadrien Chabran
01d5b42cf7
chore(local): make sg handle empty secret file gracefully (#63614)
Previously, `sg` would trip on an empty `sg.secrets.json`. It now treats
it the same way as if the file wasn't there at all. Improved usage text
as I was there already.

## Test plan

CI + added a unit test + local test.

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-03 14:14:38 +00:00
Jean-Hadrien Chabran
f5bbbcb572
chore(local): sg warns about opposite default value on dev builds (#63612)
As I just reviewed a PR for `sg` about analytics, I've wasted 10m
wondering why I wasn't seeing anything (thought I might be on the wrong
branch, that type of things). Turned out, we obviously flip certain
default value for flags (such as disabling analytics) when running a dev
build.

`sg` now prints out a warning at the beginning stating which of those
are flipped out.

## Test plan

CI + local run 

![CleanShot 2024-07-03 at 15 15
57@2x](https://github.com/sourcegraph/sourcegraph/assets/10151/5af2fb3d-eaa3-4503-804f-8336435a86f4)

Warning sign is missing, but it's there, something wrong with my font. 

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-03 13:21:03 +00:00
Anish Lakhwara
4754325492
Chore(release): Calendar Updates (#63583)
<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->
Updated events to match [Release
Calendar](https://www.notion.so/sourcegraph/Sourcegraph-Releases-eee2a5384b0a4555adb51b439ddde35f?pvs=4)
for September and August. Manually updated July events (and updated the
`jsonc` file).

Also removed branch cut events and associated automation, since we don't
do that anymore.

## Test plan

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->
Manually tested

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
- chore(release): Update calendar events until September
- chore(release): Remove branch cut automation from `calendar.go`
2024-07-02 10:42:12 -04:00
William Bezuidenhout
098ad8ecf7
fix(ci): panic using correct err (#63599)
It was panicing using the wrong error value

## Test plan
CI
## Changelog
* ci - use correct err value to panic on
2024-07-02 14:16:08 +00:00
Jean-Hadrien Chabran
42f0eb87e5
chore(local): remove outdated dx command (#63595)
Removes some dead code that wasn't used anywhere. 

## Test plan

CI 

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-02 10:46:57 +00:00
Jean-Hadrien Chabran
ded610d887
chore(local): add FORBIDCOMMIT pragma to prevent accidental commits (#63581)
@chrsmith suggested this idea, which I like very much as well. 

Pretty straightforward: 

- if you're adding something you really don't want to commit and suspect
your future self to forget about it, you can add `FORBIDCOMMIT` anywhere
in your changes, and precommit will prevent you from accidentally
committing it.
  - check is case insensitive.

I went for this instead of `NOCOMMIT` because it could be legitimately
be used for a var with the number of commits for example. And that's not
really something we want to add a pragma to disable the string itself
for either.


## Test plan

![CleanShot 2024-07-01 at 19 44
31@2x](https://github.com/sourcegraph/sourcegraph/assets/10151/3ff3420e-4012-4018-a1e3-42ae2fb53cb4)
2024-07-01 18:27:26 +00:00
Robert Lin
c7a825303b
chore/linearhooks: use MSP rollouts (#63556)
See https://github.com/sourcegraph/managed-services/pull/1686

## Test plan

n/a
2024-07-01 18:24:40 +01:00
William Bezuidenhout
720b2ecdc2
fix(sg/bazel-do): use ci.sourcegraph.bazelrc with bazel-do (#63545)
Without `ci.sourcegraph.bazelrc` the bazel environment won't have the
right credentials to access the db. This adds the rc to the bazel-do
invocation.

For context - the `ci.sourcegraph.bazelrc` contains this following
```
# Needed for DB in CI
common --test_env=PGUSER=postgres
common --test_env=PGPASSWORD=postgres
common --test_env=PGSSLMODE=disable
common --test_env=PGDATABASE=postgres
```

## Test plan

https://buildkite.com/sourcegraph/sourcegraph/builds/280332#01905ef3-1fce-4d76-bf5b-0530dc434cff
<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog
* sg - ensure bazel-do invocations use the ci sourcegraph bazelrc
2024-06-28 13:14:26 +00:00
William Bezuidenhout
40dc6965e8
fix(sg): conditionally show protips (#63541)
Small improvement as reported here
https://github.com/sourcegraph/devx-support/issues/1068

## Test plan
Tested locally
```
sourcegraph on  wb/sg-bazel/rust-hint [$!+?] via 🐹 v1.22.4 via ❄️  impure (sourcegraph-dev-env) took 9m54s
❯ CARGO_BAZEL_ISOLATED=0 CARGO_BAZEL_REPIN_ONLY=crate_index go run ./dev/sg bazel configure rustdeps
✱ Invoking the following Bazel generating categories: rustdeps
👉 running command "bazel sync --only=crate_index"

sourcegraph on  wb/sg-bazel/rust-hint [$!+?] via 🐹 v1.22.4 via ❄️  impure (sourcegraph-dev-env) took 51s
❯ CARGO_BAZEL_ISOLATED=1 CARGO_BAZEL_REPIN_ONLY=crate_index go run ./dev/sg bazel configure rustdeps
✱ Invoking the following Bazel generating categories: rustdeps
👉 running command "bazel sync --only=crate_index"
💡 pro-tip: run with CARGO_BAZEL_ISOLATED=0 for faster (but less sandboxed) repinning.
```
## Changelog
* sg - conditionally show protips when running `sg bazel`
2024-06-28 12:11:07 +02:00
William Bezuidenhout
8fc3f11b80
fix(sg): reduce max interrupt count and os.Exit always (#63516)
* Once all the hooks have finished we now os.Exit ensuring anything else
non-process related quits.
* Reduce max interrupt count from 5 -> 2. Restoring what it was
previously. This might lead to dangling processes.


[Issue](https://linear.app/sourcegraph/issue/DINF-74/sg-address-sg-hanging-around-after-ctrlc)
<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

## Test plan
Tested locally
<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog
* sg - Always os.Exit once shutdown hooks have completed
* sg - Reduce max intterupt count from 5 to 2 to hard exit
2024-06-28 10:27:02 +02:00
Robert Lin
28496f42c2
fix/sg: fix 'sg enterprise' per-command flags (#63527)
Using `append` on a variable, then sharing that variable, surprisingly
seems to cause nondeterministic behaviour in the flags. This makes the
shared flag set a function so that each command gets its own set to
append to.

## Test plan

`sg enterprise subscription list -h` now has the correct flags
2024-06-27 20:00:45 +01:00
James Cotter
117fe09829
sg/msp: generate github action subscription matrix dynamically (#63526)
Currently the matrix is hardcoded in the msp repo. 
Service operators can forget to add or remove their service from the
list.

GitHub supports dynamically generating the matrix from a previous jobs
output
([example](https://josh-ops.com/posts/github-actions-dynamic-matrix/))
This PR adds an `sg msp subscription-matrix` command which will generate
the matrix we need

Part of CORE-202

## Test plan
Output
```
{"service":[{"id":"cloud-ops","env":"prod","category":"internal"},{"id":"gatekeeper","env":"prod","category":"internal"},{"id":"linearhooks","env":"prod","category":"internal"}]}
```
2024-06-27 19:52:01 +01:00
Robert Lin
3ec64db24a
feat/sg: add -auto-approve option for 'sg enterprise' updates (#63500)
Makes destructive updates usable in automation, such as GitHub actions

## Test plan

```
 sg enterprise subscription update-membership -subscription-instance-domain='bobheadxi.dev' --auto-approve '...'
```
2024-06-27 10:30:59 -07:00
Quinn Slack
dc478c82dd
chore(ci): remove Percy visual tests (#63515)
These are more frequently erroneous than helpful.

See
https://sourcegraph.slack.com/archives/C04MYFW01NV/p1719209633005499.

This eliminates a source of frustration and flakiness in pull requests
and removes a lot of code and Bazel complexity.

If we want to revive them, we can revert this commit. Note that
`client/web-sveltekit` does not use Percy, and if we want it to, we can
always revert this commit or start over from scratch if that's easier.


<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

## Test plan

CI

Co-authored-by: Jean-Hadrien Chabran <jean-hadrien.chabran@sourcegraph.com>
2024-06-27 16:20:06 +02:00
James Cotter
ea9c45df8f
msp/runtime: split contract into JobContract and ServiceContract (#63494)
Splits the runtime contract into a JobContract and ServiceContract.
This lets better handle initialisation such as env vars which is
conditional depending on the contract type.
## Test plan

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->
ci
2024-06-26 19:46:10 +00:00
Camden Cheek
06d172448d
Search: expose path matches on FileMatch (#63396)
This just exposes the matched path ranges on our FileMatch GraphQL
object. We already had this information, just did not expose it via the
API.
2024-06-26 08:23:28 -06:00
Quinn Slack
91bc23d8e1
support fast, simple sg start single-program-experimental-blame-sqs for local dev (#63435)
This makes it easier to run Sourcegraph in local dev by compiling a few
key services (frontend, searcher, repo-updater, gitserver, and worker)
into a single Go binary and running that.

Compared to `sg start` (which compiles and runs ~10 services), it's
faster to start up (by ~10% or a few seconds), takes a lot less memory
and CPU when running, has less log noise, and rebuilds faster. It is
slower to recompile for changes just to `frontend` because it needs to
link in more code on each recompile, but it's faster for most other Go
changes that require recompilation of multiple services.

This is only intended for local dev as a convenience. There may be
different behavior in this mode that could result in problems when your
code runs in the normal deployment. Usually our e2e tests should catch
this, but to be safe, you should run in the usual mode if you are making
sensitive cross-service changes.

Partially reverts "svcmain: Simplify service setup (#61903)" (commit
9541032292).


## Test plan

Existing tests cover any regressions to existing behavior. This new
behavior is for local dev only.
2024-06-24 21:12:47 +00:00
Craig Furman
b47c376cbe
fix(appliance): source versions from release registry (#63387)
Rather than hardcoding a few. Present the user with versions up to 2
minor revisions back from the version of the appliance itself, which
should be in lock-step with the rest of the monorepo.


Closes
https://linear.app/sourcegraph/issue/REL-199/populate-accurate-list-of-versions-to-install
2024-06-24 09:48:50 +00:00
Robert Lin
cb3a1e4dc8
feat/sg: add 'sg enterprise' commands for Cody Analytics (#63414)
Closes CORE-194 - added a bit more than strictly needed here, but this
PR adds:

- `sg enterprise subscription list`
- `sg enterprise subscription set-instance-domain`
- `sg enterprise update-membership`
- `sg enterprise license list`

## Test plan

<img width="1055" alt="image"
src="https://github.com/sourcegraph/sourcegraph/assets/23356519/48ec40b0-fbac-4513-9ad8-fc3174774ada">


![image](https://github.com/sourcegraph/sourcegraph/assets/23356519/806fd054-806b-4ecb-a969-32900112f368)
2024-06-21 16:29:31 -07:00
Noah S-C
7a9d2b02e4
chore(ci): emit compact executon log in CI (#63420)
Second attempt at https://github.com/sourcegraph/sourcegraph/pull/61760,
we can start using these to dig into action cache misses etc

## Test plan

CI passes green


## Changelog
2024-06-21 19:50:35 +01:00
Craig Furman
4641bc5023
chore(sg): extract releaseregistry client package (#63382)
In preparation for reuse elsewhere.
2024-06-21 10:34:52 +01:00
Robert Lin
78dcd57221
fix/sg: fix mangled log output from sg start and sg run (#63405)
Right now `sg run` / `sg start` can horribly mangle multi-line output. A
nicely annotated report from @unknwon:


![image](https://github.com/sourcegraph/sourcegraph/assets/23356519/38acbaf9-89dc-4d4b-9fd7-b601f5654240)

Replacing the "buffered process logger" thing with
https://github.com/bobheadxi/streamline which powers `sourcegraph/run`
etc (fairly reliably if I do say so myself) fixes this for a few cases
where I can reliably repro wonky misordered output 😁

## Test plan

`sg start dotcom` with `sg.config.overwrite.yaml`:

```yaml
commands:
  enterprise-portal:
    env:
      SRC_LOG_LEVEL: debug
      PG_QUERY_LOGGING: true
```

Log scope `pgx.devtracer` is consistently formatted  , even with high
volume of logs


![image](https://github.com/sourcegraph/sourcegraph/assets/23356519/5c46f94f-e388-477a-94d3-151d5a3c7468)

Also don't see anything suspicious happening after running for a while
2024-06-20 16:07:27 -07:00
Will Dollman
e24226a764
Publish images from patch release branches (#63379)
We currently don't publish images from the new-style patch release
branches like `5.4.5099`, as this is all performed using the new release
tooling.

In order to improve the release process, we (Security) would like to run
a daily scan of the current set of images built from the patch release
branch. Currently we only scan images built from `main`, but these
slowly diverge from the patch release branch in the 2 week window
between a monthly release and the patch release.

To give a specific example, we currently have no easy/automated way to
scan images from the `5.4.5099` branch that a release will be cut from
this afternoon until the release team run the internal release process.

This PR updates the pipeline so that whenever a new commit is pushed to
the patch release branch, it will publish a new set of images and
include the tag `<branch>-insiders`. Currently just pushing to
us.gcr.io, but equally could push to dockerhub.

Example of the jobfile for a matching branch after this PR:

`bazel --bazelrc=/tmp/aspect-generated.bazelrc
--bazelrc=.aspect/bazelrc/ci.sourcegraph.bazelrc run
//cmd/batcheshelper:candidate_push --stamp
--workspace_status_command=./dev/bazel_stamp_vars.sh -- --tag
dc438648b0 --tag dc438648b0cc_2024-06-20 --tag dc438648b0cc_279230
--tag will/5.4.9999-insiders --repository
us.gcr.io/sourcegraph-dev/batcheshelper && echo -e
'<tr><td>batcheshelper</td><td><code>us.gcr.io/sourcegraph-dev</code></td><td><code>dc438648b0cc</code>,
<code>dc438648b0cc_2024-06-20</code>, <code>dc438648b0cc_279230</code>,
<code>will/5.4.9999-insiders</code></td></tr>'
>>./annotations/pushed_images.md`

[Example buildkite
run](https://buildkite.com/sourcegraph/sourcegraph/builds/279230#_)
where the pattern was updated to match this branch, and pushing
non-candidate images was disabled.

This resolves one part of
[SEC-1734](https://linear.app/sourcegraph/issue/SEC-1734/scan-images-from-patch-release-branches)

<!-- 💡 To write a useful PR description, make sure that your description
covers:
- WHAT this PR is changing:
    - How was it PREVIOUSLY.
    - How it will be from NOW on.
- WHY this PR is needed.
- CONTEXT, i.e. to which initiative, project or RFC it belongs.

The structure of the description doesn't matter as much as covering
these points, so use
your best judgement based on your context.
Learn how to write good pull request description:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e?pvs=4
-->


## Test plan

- Manual testing of buildkite pipeline

<!-- All pull requests REQUIRE a test plan:
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->


## Changelog

<!--
1. Ensure your pull request title is formatted as: $type($domain): $what
2. Add bullet list items for each additional detail you want to cover
(see example below)
3. You can edit this after the pull request was merged, as long as
release shipping it hasn't been promoted to the public.
4. For more information, please see this how-to
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c?

Audience: TS/CSE > Customers > Teammates (in that order).

Cheat sheet: $type = chore|fix|feat $domain:
source|search|ci|release|plg|cody|local|...
-->

<!--
Example:

Title: fix(search): parse quotes with the appropriate context
Changelog section:

## Changelog

- When a quote is used with regexp pattern type, then ...
- Refactored underlying code.
-->
2024-06-20 15:46:37 +01:00
Robert Lin
2958abc326
fix/msp/postgresqlroles: wait for databases to be provisioned (#63362)
Wait for databases to be provisioned before granting database-specific
roles to the operator access user.

## Test plan

Re-apply fixed
https://sourcegraph.slack.com/archives/C05E2LHPQLX/p1718850688397579,
indicating a race condition on database creation. Diff looks good:

```diff
@@ -1447,10 +1472,15 @@
             "path": "cloudrun/cloudrun-postgresqlroles-msp_iam-operator_access_service_account_table_grant",
             "uniqueId": "cloudrun-postgresqlroles-msp_iam-operator_access_service_account_table_grant"
           }
         },
         "database": "msp_iam",
+        "depends_on": [
+          "google_sql_database.postgresql-database-enterprise-portal",
+          "google_sql_database.postgresql-database-enterprise_portal",
+          "google_sql_database.postgresql-database-msp_iam"
+        ],
         "object_type": "table",
         "objects": [
         ],
         "privileges": [
           "SELECT"
```

## Changelog

- MSP Cloud SQL: Fix race condition between database creation and role
grants for the read-only operator access user
2024-06-20 07:43:14 -07:00
Keegan Carruthers-Smith
d42a99b5a3
nix: use go1.22.4 (#63372)
Tired of seeing the go toolchain being easier to use than nix.

Test Plan: nix develop on linux amd64 and macbook arm64 followed by
running "go test ./internal/search" working. Also confirming that "go
env GOROOT" points into the nix store.
2024-06-20 11:12:17 +02:00
Joe Chen
b717fd518a
enterprise-portal: implement basic MSP IAM and RPCs (#63173)
Closes CORE-99, closes CORE-176

This PR is based off (and was also served as PoC of) [RFC 962: MSP IAM
framework](https://docs.google.com/document/d/1ItJlQnpR5AHbrfAholZqjH8-8dPF1iQcKh99gE6SSjs/edit).
It comes with two main parts:

1. The initial version of the MSP IAM SDK:
`lib/managedservicesplatform/iam`
- Embeds the [OpenFGA server
implementation](https://github.com/openfga/openfga/tree/main/pkg/server)
and exposes the a `ClientV1` for interacting with it.
- Automagically manages the both MSP IAM's and OpenFGA's database
migrations upon initializing the `ClientV1`.
![CleanShot 2024-06-18 at 15 09
24@2x](https://github.com/sourcegraph/sourcegraph/assets/2946214/387e0e28-a6c2-4664-b946-0ea4a1dd0804)
- Ensures the specified OpenFGA's store and automatization model DSL
exists.
- Utility types and helpers to avoid easy mistakes (i.e. make the
relation tuples a bit more strongly-typed).
- Decided to put all types and pre-defined values together to simulate a
"central registry" and acting as a forcing function for services to form
some sort of convention. Then when we migrate the OpenFGA server to a
separate standalone service, it will be less headache about
consolidating similar meaning types/relations but different string
literals.
1. The first use case of the MSP IAM:
`cmd/enterprise-portal/internal/subscriptionsservice`
	- Added/updated RPCs:
		- Listing enterprise subscriptions via permissions
		- Update enterprise subscriptions to assign instance domains
- Update enterprise subscriptions membership to assign roles (and
permissions)
- A database table for enterprise subscriptions, only storing the extra
instance domains as Enterprise Portal is not the
writeable-source-of-truth.

## Other minor changes

- Moved `internal/redislock` to `lib/redislock` to be used in MSP IAM
SDK.
- Call `createdb ...` as part of `enterprise-portal` install script in
`sg.config.yaml` (`msp_iam` database is a hard requirement of MSP IAM
framework).

## Test plan

Tested with gRPC UI:

- `UpdateEnterpriseSubscription` to assign an instance domain
- `UpdateEnterpriseSubscriptionMembership` to assign roles
- `ListEnterpriseSubscriptions`:
	- List by subscription ID
	- List by instance domain
	- List by view cody analytics permissions

---------

Co-authored-by: Robert Lin <robert@bobheadxi.dev>
2024-06-19 21:46:48 -04:00
Noah S-C
d237975918
chore(ci): instrument push_all.sh commands in honeycomb (#63350)
So I can measure the impact of changes on the individual `bazel run`
invocations

## Test plan

main dry-run and seeing the output
https://ui.honeycomb.io/sourcegraph/datasets/buildkite-pushall/result/bCLzgquaSdV?hideCompare

## Changelog
2024-06-19 18:16:21 +01:00
Camden Cheek
db7a268c34
Chore: remove search console (#63322)
The search console page is broken, is not used or maintained, and is
only referenced by a series of blog posts years ago. We have product
support to remove it.
2024-06-19 11:05:03 -06:00
Jean-Hadrien Chabran
b3b7936ffa
chore(local): simplify 'sg db' inline help (#63344)
Follow-up to https://github.com/sourcegraph/sourcegraph/pull/63320 as I
noticed that the `UsageText` didn't include `sg db default-site-admin`.
Additionally, it was quite verbose without providing much info, so I
just dropped it in favour of highlighting notable commands.
2024-06-19 14:56:13 +00:00
Noah S-C
a5a6a0dd23
feat(sg): command to add default site-admin with predefined access token (#63320)
Adds a subcommand to `sg db` called `default-site-admin` that creates a
site-admin user with user:pass `sourcegraph:sourcegraph` and a
predefined hard-coded token
`sgp_local_f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0`


## Test plan

`go run ./dev/sg -- db default-site-admin` with clean database
`" "` after having run that (when everything should be set)
`" "` when user exists but token doesnt

## Changelog
2024-06-19 15:02:55 +01:00
Varun Gandhi
3437f8253d
chore: Centralize languages package as source-of-truth (#63292)
This patch does a few things:

- Adds `go-enry` packages to depguard, so that people do not
  accidentally use enry APIs instead of the corresponding APIs
  in the `languages` package.
- Adds more tests for different functions in the languages package
  to ensure mutual consistency in how language<->extension mappings
  are handled.
- Adds tests for enry upgrades
- Adds comments with IDs so that related parts in the code can be
   pieced together easily
2024-06-18 13:10:24 +00:00
Noah S-C
8412e6b45d
chore(ci): remove buildchecker sunday summary posts (#63289)
https://linear.app/sourcegraph/issue/DINF-36/kill-automated-ci-report

## Test plan

Still compiles, meaning at best everything unused is gone, at worst
we've got unused stuff left over but nothing necessary still remaining


## Changelog
2024-06-17 13:05:39 +00:00
Vincent
add4baa455
chore(security): update dependencies (#63197)
This PR upgrades a bunch of Golang dependencies that have known security
issues.

## Test plan
CI tests, ran `sg start`.
2024-06-11 16:14:24 +01:00
William Bezuidenhout
9b37349981
sg: cloud eph - set max deployment name (#63202)
Encountered this error while doing my demo
```
{"SeverityText":"ERROR","Timestamp":1718110348252114099,"InstrumentationScope":"mi2.instance.create","Caller":"mi2/instance.go:478","Function":"main.glob..func26","Body":"new instance validation failed: slug (displayName) must be between 4 to 30 characters. Allowed characters are: lowercase letters, numbers, hyphen. Current: christoph-resolve-syntactic-symbol-at-request-range","Resource":{"service.name":"mi2","service.version":"2024-06-11-09-50-
```
So now we limit it to 30 chars and print a notice to inform the user
that it has been truncated

## Test plan
Tested locally
```
go run ./dev/sg cloud eph deploy --name 'christoph-resolve-syntactic-symbol-at-request-range_277899_2024-06-11_5.4-f04d3b973a19' --version 'christoph-resolve-syntactic-symbol-at-request-range_277899_2024-06-11_5.4-f04d3b973a19'
 Version "christoph-resolve-syntactic-symbol-at-request-range_277899_2024-06-11_5.4-f04d3b973a19" found in Cloud ephemeral registry
👉 Your deployment name has been truncated to be "christoph-resolve-syntactic-sy"
```

## Changelog
- sg - set a max length for cloud ephemeral deployment names
2024-06-11 16:12:17 +02:00
William Bezuidenhout
4f910fb360
sg: cloud eph - improve missing tag/version message (#63195)
Previous message didn't give you steps to get the version added. New
message directs you to discuss-dev-infra slack which will ultimately run
https://buildkite.com/sourcegraph/cloud-ephemeral-images


## Test plan
CI and tested locally 
```
go run ./dev/sg cloud eph deploy --version 1.1.1
⚠️ Whoops! Version "1.1.1" seems to be missing from the Cloud ephemeral registry. Please ask in #discuss-dev-infra to get the it added to the registry
 tag/version not in Cloud Ephemeral registry
exit status 1
```


## Changelog
* sg - improve messaging when an image is missing from Cloud ephemeral
registry
2024-06-11 10:53:52 +02:00
James Cotter
1712928bc5
msp/deploy: encode commit_message as base64 (#63165)
Encodes the commit_message as base64 to avoid issues with special
characters breaking the deploy command

Part of CORE-172

## Test Plan
CI

[_Created by Sourcegraph batch change
`jac/msp-rollout-base64`._](https://sourcegraph.sourcegraph.com/users/jac/batch-changes/msp-rollout-base64)
2024-06-07 23:31:42 +01:00
Robert Lin
7e9d8ec8dc
feat/cody-gateway: use Enterprise Portal for actor/productsubscriptions (#62934)
Migrates Cody Gateway to use the new Enterprise Portal's "read-only"
APIs. For the most part, this is an in-place replacement - a lot of the
diff is in testing and minor changes. Some changes, such as the removal
of model allowlists, were made down the PR stack in
https://github.com/sourcegraph/sourcegraph/pull/62911.

At a high level, we replace the data requested by
`cmd/cody-gateway/internal/dotcom/operations.graphql` and replace it
with Enterprise Portal RPCs:

- `codyaccessv1.GetCodyGatewayAccess`
- `codyaccessv1.ListCodyGatewayAccesses`

Use cases that previously required retrieving the active license tags
now:

1. Use the display name provided by the Cody Access API
https://github.com/sourcegraph/sourcegraph/pull/62968
2. Depend on the connected Enterprise Portal dev instance to only return
dev subscriptions https://github.com/sourcegraph/sourcegraph/pull/62966

Closes https://linear.app/sourcegraph/issue/CORE-98
Related to https://linear.app/sourcegraph/issue/CORE-135
(https://github.com/sourcegraph/sourcegraph/pull/62909,
https://github.com/sourcegraph/sourcegraph/pull/62911)
Related to https://linear.app/sourcegraph/issue/CORE-97

## Local development

This change also adds Enterprise Portal to `sg start dotcom`. For local
development, we set up Cody Gateway to connect to Enterprise Portal such
that zero configuration is needed - all the required secrets are sourced
from the `sourcegrah-local-dev` GCP project automatically when you run
`sg start dotcom`, and local Cody Gateway will talk to local Enterprise
Portal to do the Enterprise subscriptions sync.

This is actually an upgrade from the current experience where you need
to provide Cody Gateway a Sourcegraph user access token to test
Enterprise locally, though the Sourcegraph user access token is still
required for the PLG actor source.

The credential is configured in
https://console.cloud.google.com/security/secret-manager/secret/SG_LOCAL_DEV_SAMS_CLIENT_SECRET/overview?project=sourcegraph-local-dev,
and I've included documentation in the secret annotation about what it
is for and what to do with it:


![image](https://github.com/sourcegraph/sourcegraph/assets/23356519/c61ad4e0-3b75-408d-a930-076a414336fb)

## Rollout plan

I will open PRs to set up the necessary configuration for Cody Gateway
dev and prod. Once reviews taper down I'll cut an image from this branch
and deploy it to Cody Gateway dev, and monitor it closely + do some
manual testing. Once verified, I'll land this change and monitor a
rollout to production.

Cody Gateway dev SAMS client:
https://github.com/sourcegraph/infrastructure/pull/6108
Cody Gateway prod SAMS client update (this one already exists):

```
accounts=> UPDATE idp_clients
SET scopes = scopes || '["enterprise_portal::subscription::read", "enterprise_portal::codyaccess::read"]'::jsonb
WHERE id = 'sams_cid_018ea062-479e-7342-9473-66645e616cbf';
UPDATE 1
accounts=> select name, scopes from idp_clients WHERE name = 'Cody Gateway (prod)';
        name         |                                                              scopes                                                              
---------------------+----------------------------------------------------------------------------------------------------------------------------------
 Cody Gateway (prod) | ["openid", "profile", "email", "offline_access", "enterprise_portal::subscription::read", "enterprise_portal::codyaccess::read"]
(1 row)
```

Configuring the target Enterprise Portal instances:
https://github.com/sourcegraph/infrastructure/pull/6127

## Test plan

Start the new `dotcom` runset, now including Enterprise Portal, and
observe logs from both `enterprise-portal` and `cody-gateway`:

```
sg start dotcom
```

I reused the test plan from
https://github.com/sourcegraph/sourcegraph/pull/62911: set up Cody
Gateway external dependency secrets, then set up an enterprise
subscription + license with a high seat count (for a high quota), and
force a Cody Gateway sync:

```
curl -v -H 'Authorization: bearer sekret' http://localhost:9992/-/actor/sync-all-sources
```

This should indicate the new sync against "local dotcom" fetches the
correct number of actors and whatnot.

Using the local enterprise subscription's access token, we run the QA
test suite:

```sh
$ bazel test --runs_per_test=2 --test_output=all //cmd/cody-gateway/qa:qa_test --test_env=E2E_GATEWAY_ENDPOINT=http://localhost:9992 --test_env=E2E_GATEWAY_TOKEN=$TOKEN
INFO: Analyzed target //cmd/cody-gateway/qa:qa_test (0 packages loaded, 0 targets configured).
INFO: From Testing //cmd/cody-gateway/qa:qa_test (run 1 of 2):
==================== Test output for //cmd/cody-gateway/qa:qa_test (run 1 of 2):
PASS
================================================================================
INFO: From Testing //cmd/cody-gateway/qa:qa_test (run 2 of 2):
==================== Test output for //cmd/cody-gateway/qa:qa_test (run 2 of 2):
PASS
================================================================================
INFO: Found 1 test target...
Target //cmd/cody-gateway/qa:qa_test up-to-date:
  bazel-bin/cmd/cody-gateway/qa/qa_test_/qa_test
Aspect @@rules_rust//rust/private:clippy.bzl%rust_clippy_aspect of //cmd/cody-gateway/qa:qa_test up-to-date (nothing to build)
Aspect @@rules_rust//rust/private:rustfmt.bzl%rustfmt_aspect of //cmd/cody-gateway/qa:qa_test up-to-date (nothing to build)
INFO: Elapsed time: 13.653s, Critical Path: 13.38s
INFO: 7 processes: 1 internal, 6 darwin-sandbox.
INFO: Build completed successfully, 7 total actions
//cmd/cody-gateway/qa:qa_test                                            PASSED in 11.7s
  Stats over 2 runs: max = 11.7s, min = 11.7s, avg = 11.7s, dev = 0.0s

Executed 1 out of 1 test: 1 test passes.
```
2024-06-07 11:46:01 -07:00
William Bezuidenhout
8bb0ab54eb
release: never use build number in image family (#63157)
the executor image and docker mirror image should now follow the
following naming convention:

Image family:
`sourcegraph-executors-[nightly|internal|'']-<MAJOR>-<MINOR>`
Image name:
`sourcegraph-executor-[nightly|internal|'']-<MAJOR>-<MINOR>-<BUILD_NUMBER>`

example:
Image family: `sourcegraph-executors-5-4`
Image name: `sourcegraph-executor-5-4-277666`

## What happens during releases and _not_ releases?
#### Nightly
**`nightly` suffix**
Image family: `sourcegraph-executors-nightly-<MAJOR>-<MINOR>`
Image name:
`sourcegraph-executor-nightly-<MAJOR>-<MINOR>-<BUILD_NUMBER>`
#### Internal
**`internal` suffix**
Image family: `sourcegraph-executors-internal-<MAJOR>-<MINOR>`
Image name:
`sourcegraph-executor-internal-<MAJOR>-<MINOR>-<BUILD_NUMBER>`
#### Public / Promote to public

** No suffix **

Image family: `sourcegraph-executors-<MAJOR>-<MINOR>`
Image name: `sourcegraph-executor-<MAJOR>-<MINOR>-<BUILD_NUMBER>`

>  [!IMPORTANT]
> Should we keep the imagine name stable at
`sourcegraph-executor-<MAJOR>-<MINOR>-<BUILD_NUMBER>`
> and only change the family name? 
>
> **Why?**
>
> The Image family dictates the collection of images and that changes
each major minor and or release phase so there is really no use in
changing the image name too, except at a glance you can see from the
name what image family it belongs to?
## Test plan

<!-- All pull requests REQUIRE a test plan:
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->


## Changelog

<!--
1. Ensure your pull request title is formatted as: $type($domain): $what
2. Add bullet list items for each additional detail you want to cover
(see example below)
3. You can edit this after the pull request was merged, as long as
release shipping it hasn't been promoted to the public.
4. For more information, please see this how-to
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c?

Audience: TS/CSE > Customers > Teammates (in that order).

Cheat sheet: $type = chore|fix|feat $domain:
source|search|ci|release|plg|cody|local|...
-->

<!--
Example:

Title: fix(search): parse quotes with the appropriate context
Changelog section:

## Changelog

- When a quote is used with regexp pattern type, then ...
- Refactored underlying code.
-->
2024-06-07 17:23:24 +02:00
Erik Seliger
1287243cae
gitserver: Framework to support integration testing against gitserver (#62801)
This PR tinkers a bit with building a test helper to run integration
tests that are still ~lightweight against a real gitserver.
The caller can either clone a real repo to disk / embed it in the git
repo, or can create a small repo on the fly, and then get a running
gitserver gRPC server that returns all the data required.

These tests should only exist outside of cmd/ and internal/, as there is
a big potential to do cross-cmd imports from here, which can cause bad
coupling. But for just these tests, that should be fine.

The most trivial rockskip indexing job that I put in here to POC this
runs in 6.3s, including all setup and teardown. That seems very
reasonable to me.

Test plan:

The POC test passes.
2024-06-07 17:01:12 +02:00
William Bezuidenhout
f7271701d5
fix(sg): fix cloud eph suggested commands (#63093)
- suggested commands didn't have the `ephemeral` subcommand
- update expiry time to show in duration till expiry

## Test plan
Tested locally + CI

## Changelog
- fix suggested cloud ephemeral commands
- show duration till expiry for cloud ephemeral
2024-06-07 12:50:43 +02:00
Jan Hartman
aa615bc37f
feat(sg): add command to generate a dotcom user gateway access token (#63125)
We can now generate gateway access tokens from sg instead of having to
manually wrangle a script to do it every time. This will help with
making Cody Gateway easier to run locally.

## Test plan
Tested locally.

---------

Co-authored-by: William Bezuidenhout <william.bezuidenhout@sourcegraph.com>
2024-06-07 10:40:51 +00:00
Greg Magolan
27da7890fc
chore(bazel): fixup custom eslint test rule after bump to rules_js 2 (#63143)
This regressed in https://github.com/sourcegraph/sourcegraph/pull/63022
where the custom `gather_files_from_js_providers` function that was
copied over from rules_js 1.x was including runfiles.

Resolves eslint failures seen in
https://buildkite.com/sourcegraph/sourcegraph/builds/277072#018fe743-abac-44d8-911b-d5a7ed425413
and observed locally:

```
(07:19:15) INFO: From ESLint client/wildcard/wildcard_lib_eslint-output.txt:
  |  
  | Oops! Something went wrong! :(
  |  
  | ESLint: 8.57.0
  |  
  | ESLint couldn't find a configuration file. To set up a configuration file for this project, please run:
  |  
  | npm init @eslint/config
  |  
  | ESLint looked for configuration files in /tmp/bazel-working-directory/__main__/bazel-out/k8-fastbuild/bin/client/wildcard/src/components/Alert and its ancestors. If it found none, it then looked in your home directory.
  |  
  | If you think you already have a configuration file or if you need more help, please stop by the ESLint Discord server: https://eslint.org/chat

```

## Test plan

CI (check test logs)

## Changelog
2024-06-06 23:32:34 +01:00