Commit Graph

37705 Commits

Author SHA1 Message Date
Jason Hawk Harris
cff1669bc1
Svelte: Perforce UI elements refactor (#64279)
## UI Updates for Perforce Depots and Git Repos

Fixes SRCH-530

**NOTE: This PR is a refactor of an earlier
[PR](https://github.com/sourcegraph/sourcegraph/pull/64014) that was
reverted. For that reason, the PR description is largely the same.**

This PR introduces changes to the UI to differentiate between Perforce
Depots and Git repositories. Below are the key changes included in this
commit:

### 1. Dynamic Top-Level Navigation

**For Perforce Depots:**

![Screenshot 2024-07-31 at 10 10 37
AM](https://github.com/user-attachments/assets/2d261b51-f8fa-4599-acae-3520d38996f3)

**For Git Repos:**

![Screenshot 2024-07-31 at 10 10 14
AM](https://github.com/user-attachments/assets/0f9ee3f7-918a-42d8-908f-04593ed52ebd)

### 2. Tabs on Revision Picker

**For Perforce Depots:**

Since we only need one tab for changelists, no tabs are shown.

![Screenshot 2024-07-31 at 10 20 24
AM](https://github.com/user-attachments/assets/f1006d56-67aa-41ab-a13b-905e157cb283)

**For Git Repos:**

We have tabs for Branches, Tags, and Commits.

![Screenshot 2024-07-31 at 10 23 02
AM](https://github.com/user-attachments/assets/38907d51-0407-4cd7-ad4c-1c5967dfddf3)

### 3. Commits/Changelists Page

**For Git Repos:**

The page displays Git commits.

![Screenshot 2024-07-31 at 10 26 23
AM](https://github.com/user-attachments/assets/85245d1d-708f-4d51-9da3-0425c3f085d0)

**For Perforce Depots:**

The page displays Perforce changelists.

![Screenshot 2024-07-31 at 10 26 39
AM](https://github.com/user-attachments/assets/2f6f16aa-d498-4763-949d-d1a13f9a26ac)

### 4. Vocabulary Adjustments

- We display either Git commit SHAs or Changelist IDs based on the
project type.
- For authorship, we use "submitted by" for Perforce and "committed by"
for Git.
- We refer to "Commits" for Git projects and "Changelists" for Perforce
projects.

**Examples:**

- **For Git Commits:**

![Screenshot 2024-07-31 at 10 37 08
AM](https://github.com/user-attachments/assets/ac15b0b3-4c85-4a4c-80c0-ec9384b72eca)

- **For Perforce Changelists:**

![Screenshot 2024-07-31 at 10 37 35
AM](https://github.com/user-attachments/assets/4230cb32-5285-4141-b374-f3ea23042e1d)

### 5. URL Mapping

URLs are now structured differently based on the project type:

- **Commits Page:**
  - Git: `/[repo-name]/-/commits`
  - Perforce: `/[repo-name]/-/changelists`
  
- **Individual Item Page:**
  - Git: `/[repo-name]/-/commit/[commit-hash]`
  - Perforce: `/[depot-name]/-/changelist/[changelist-ID]`

When viewing a specific commit or changelist:
- **Git:** `/[repo-name]@[git-commit-hash]`
- **Perforce:** `/[repo-name]@changelist/[changelist-id]`

_NOTE: The value displayed in the search field will also change
accordingly._


### What is left to be done?
**On repo search results, when searching a revision, we still show the
git commit SHA instead of the changelist ID for perforce depots:**
![Screenshot 2024-07-31 at 10 59 12
AM](https://github.com/user-attachments/assets/38bc2a3e-be8b-4585-9fe0-776149a7f230)

I plan to make a follow-up issue for this and begin work on it
immediately. It's a little trickier than the other changes because in
the RepositoryMatch type, there is no value that can help us determine
whether a project is a depot or a repo. We need to find another way to
fetch that data.

### Request for reviewers: 
1. Please try to break these new features and tell me what you find. I
stumbled on a number of little gotchas while working on this, and I'm
sure I've missed some.

## Test plan
<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->
- Manual/Visual testing
- Adjust e2e and integration tests to obtain a passing CI
- Test directly visiting a URL versus getting there via click
- Add unit tests for new/updated helper functions

---------

Co-authored-by: Camden Cheek <camden@ccheek.com>
2024-08-14 19:18:24 +00:00
Varun Gandhi
f403bfc1ff
chore: Bump autoindexing image SHAs (#64472) 2024-08-14 16:39:08 +00:00
Jean-Hadrien Chabran
1c3ba6eb85
chore(ci): lower concurrent jobs when pushing to dockerhub (#64469)
We're currently evaluating only pushing on Dockerhub when releasing, as
everything else uses GCR, but until then, we lower the concurrency to 4
when pushing there, and we keep 8 on the others.

Follow-up to https://github.com/sourcegraph/devx-support/issues/1163

## Test plan

CI
2024-08-14 16:23:39 +00:00
Robert Lin
6e828b0a14
feat/dotcom: use Enterprise Portal for all subscriptions UI (#64115)
Overview Loom:

1.
https://www.loom.com/share/988465de1c3a4caaa08fc6b22ffb74e5?sid=860f28cd-4dfb-4758-9bd9-d2f485ceb317
2. Announcement:
https://www.loom.com/share/8560388e0a4a404caf67d908820ed0d0?sid=6482815f-ac60-4251-95cc-307f527a60dd

tl;dr


![image](https://github.com/user-attachments/assets/542c5b64-5729-4a6a-91b2-e0373abb35fa)

![image](https://github.com/user-attachments/assets/9cc41a80-2ff1-4845-a290-823df242cd2e)

![image](https://github.com/user-attachments/assets/47c9a400-d091-416f-a85c-f1dcc93d880d)

TODO:

- [x] Fix the "edit instance type" input
- [x] ~Subscription view: reload on changing the Enterprise Portal
environment selector~ ->
https://linear.app/sourcegraph/issue/CORE-245/dotcom-subscriptions-ui-enterprise-portal-instance-selector-doesnt,
use a jank reload for now
- [x] CI

Closes
https://linear.app/sourcegraph/issue/CORE-100/enterprise-portal-migrate-away-from-dotcom-db-as-source-of-truth

## Test plan

Manual testing for UI via `sg start dotcom` ->
https://sourcegraph.test:3443/site-admin/dotcom/product/subscriptions

The PRs this PR is stacked on top of implement testing of the backend
capabilities
2024-08-14 15:32:22 +00:00
Robert Lin
fef7af964b
Revert "chore(local): dont buffer sg updatecheck commencement notice … (#64456)
…(#64329)"

This reverts commit c4fefc1fe6.

See thread
https://sourcegraph.slack.com/archives/C04MYFW01NV/p1723219276178049:
I'm consistently getting strange output after #64329, and building `sg`
from before that change seems to not have this problem.

## Test plan

```
go build -o ./sg ./dev/sg && ./sg install -f -p=false
SKIP_AUTO_UPDATE=false sg -skip-auto-update=false msp fleet
```

Output looks normal.

But then, reverting back to main:
```
sg update
sg msp fleet
```

Some odd character sequences show up as described in
https://sourcegraph.slack.com/archives/C04MYFW01NV/p1723219276178049
2024-08-14 08:04:02 -07:00
Keegan Carruthers-Smith
9981c14e40
migrations: avoid duplicate foreign key constraints when tenant_id re-run (#64465)
ALTER TABLE with a foreign key constraint will _always_ add the
constraint, which means we always require a table lock even if this
migration has run. So we check if the column exists first.

The motivation for this change was me noticing slow migrations against
S2, even though it had been migrated already. This speeds it up since it
avoids a bunch of locks.

In testing I kept running into issues with the lsif_* tables. We agreed
we will only migrate them later.

Test Plan: ran against my local instance and S2 multiple times and CI.
Also manually ran the down and up migration against dotcom
2024-08-14 16:57:32 +02:00
Julie Tibshirani
70e98dbcbd
Redis: expose KeyValue.WithPrefix (#64466)
This PR makes `WithPrefix` visible on the `KeyValue` interface.
Previously, we had other interface implementations that did not support
`WithPrefix`, but now `redisKeyValue` is the only implementation.
`WithPrefix` is currently just used in tests, but it's broadly useful
and will help clean up a bunch of places that wrap Redis and manually
add key prefixes.
2024-08-14 17:41:59 +03:00
Keegan Carruthers-Smith
3268ade126
migrations: commit between table locks and use when condition for triggers (#64462)
The improvement to the triggers I tried to ship yesterday failed on
dotcom. This is because it has the same issue as the tenant_id column
where we can't acquire the ShareRowExclusiveLock for multiple important
tables in a transaction without deadlocking. We use the same technique
where we commit and restart the transaction. This is safe to do since
even if it fails, the migration is idempotent and partial migration
still works.

Additionally after reading the documentation on triggers more deeply
[1], I noticed we can add in a WHEN clause to triggers. We already have
this in the functions, but this should be more efficient.

I didn't want to remove the condition from the functions just yet, since
that makes the migration more risky under partial failure.

## Test Plan

CI. Also added BEGIN and COMMIT to the migration than ran locally with

``` shell
psql -f migrations/frontend/1723557836_faster_soft_delete_trigger_for_permissions/up.sql
```


Then inspected the DB state for repo and had a good looking trigger come
back

```
\d+ repo
...snip
Triggers:
  trig_delete_user_repo_permissions_on_repo_soft_delete AFTER UPDATE
  OF deleted_at ON repo FOR EACH ROW WHEN (new.deleted_at IS NOT NULL
  AND old.deleted_at IS NULL) EXECUTE FUNCTION
  delete_user_repo_permissions_on_repo_soft_delete()
```

Additionally before landing I am going to manually run this migration on
S2 first, then on dotcom to see how it behaves when there is lots of
traffic and scale.
2024-08-14 15:38:35 +02:00
Qais Patankar
44f07c3966
Invalidate sessions on user deletion (#64445)
<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

When a user is deleted and then undeleted, the original web sessions
prior to the deletion are able to be reused. This is inconsistent with
the behaviour for access tokens: access tokens are revoked on user
deletion, but web sessions are not.

This makes it so that deleting the user account also forces a sign out
for that account.

It does this by setting `invalidated_sessions_at=now()`, which is
exactly the same thing that `InvalidateSessionsByIDs` does:


cbd12608b5/internal/database/users.go (L1040-L1045)

## Test plan

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

This change should be covered by the below existing test:
cbd12608b5/internal/database/users_test.go (L741)

## Changelog

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

* Deleting a user will now invalidate their web sessions
2024-08-14 12:00:10 +01:00
Erik Seliger
0aeb6fd0a0
tenant: Add test to verify that we don't regress on tables without tenant (#64368)
This test ensures that newly added tables also have the tenant_id
column. We will later extend this test to also check that RLS policies
exist, once we created them.

Test plan: Test passes, when I modify the new migration that adds
tenant_id everywhere to skip a table it fails with a nice error message.
2024-08-14 10:58:59 +00:00
Ólafur Páll Geirsson
1b1229c867
feat/API: implement /models and /models/{modelId} using TypeSpec (#64421)
Fixes CODY-3085
Fixes CODY-3086

Previously, there was no way for OpenAI clients to list the available
models on Sourcegraph or query metadata about a given model ID ("model
ref" using our internal terminology). This PR fixes that problem AND
additionally adds infrastructure to auto-generate Go models from a
TypeSpec specification.

[TypeSpec](https://typespec.io/) is an IDL to document REST APIs,
created by Microsoft. Historically, the Go code in this repository has
been the single source of truth about what exact JSON structures are
expected in HTTP request/response pairs in our REST endpoints. This new
TypeSpec infrastructure allows us to document these shapes at a higher
abstraction level, which has several benefits including automatic
OpenAPI generation, which we can use to generate docs on
sourcegraph.com/docs or automatically generate client bindings in
TypeScript (among many other use-cases).

I am planning to write an RFC to propose we start using TypeSpec for new
REST endpoints going forward. If the RFC is not approved then we can
just delete the new `tools/typespec_codegen` directory and keep the
generated code in the repo. It won't be a big difference in the end
compared our current manual approach of writing Go structs for HTTP
APIs.

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

## Test plan
See test cases. I additionally wrote a basic python script with the
official OpenAI client to test that it works with this endpoint. First,
I ran `sg start minimal`. Then I wrote this script
```py
import os
from openai import OpenAI
from dotenv import load_dotenv
import httpx

load_dotenv()

openai = OpenAI(
    # base_url="https://api.openai.com/v1",
    # api_key=os.getenv("OPENAI_API_KEY"),
    base_url="https://sourcegraph.test:3443/api/v1",
    api_key=os.getenv("SRC_ACCESS_TOKEN"),
    http_client=httpx.Client(verify=False)
)

def main():
    response = openai.models.list()
    for model in response.data:
        print(model.id)
if __name__ == "__main__":
    main()

```
Finally, I ran 
```
❯ python3 models.py
anthropic::unknown::claude-3-haiku-20240307
anthropic::unknown::claude-3-sonnet-20240229
fireworks::unknown::starcoder
```
<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

* New `GET /.api/llm/models` and `GET /.api/llm/models/{modelId}` REST
API endpoints to list available LLM models on the instance and to get
information about a given model. This endpoints is compatible with the
`/models` and `/models/{modelId}` endpoints from OpenAI.

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-14 10:47:00 +00:00
Julie Tibshirani
c222523fa5
Redis: remove some direct pool usages (#64447)
We want to discourage direct usage of the Redis pool in favor of routing
all calls through the main `KeyValue` interface. This PR removes several
usages of `KeyValue.Pool`. To do so, it adds "PING" and "MGET" to the
`KeyValue` interface.
2024-08-14 13:39:10 +03:00
Petri-Johan Last
d3a3d721d3
Add support for Bitbucket Server OAuth2 (#64179)
Docs here: https://github.com/sourcegraph/docs/pull/561

This PR adds support for using Bitbucket Server OAuth2 application links
for sign-in and permission syncing.

When used for permission syncing, the user's oauth token is used to
fetch user permissions (and now permissions are fetched via the server).

## Test plan

Tests added and updated.

## Changelog

- Sourcegraph now supports Bitbucket Server OAuth2 application links for
user sign-in and permission syncing.
2024-08-14 12:24:32 +02:00
Felix Kling
56e1f11f25
fix(svelte): Remove unnecessary console.log statement (#64463)
Did a ripgrep to see if there are any other `console.log` statements
that should be removed but this was the only one.

## Test plan

code inspection, trivial change
2024-08-14 10:22:14 +00:00
William Bezuidenhout
3b85035f56
chore: download - ensure dir exists when writing to dst (#64460)
Closes DINF-182

Before `sg start otel` would fail if `.bin` did not exist. We now create
the destination directory if it doesn't exist

## Test plan
1. `rm -rf .bin`
2. `sg start otel`

and unit tests + CI
## Changelog
* when downloading files, ensure the directory we download to exists
2024-08-14 09:14:40 +00:00
Craig Furman
bcb2e16d0b
feat(appliance): optionally load pinned releases file (#64441)
**chore(appliance): version list obtained from backend**

Instead of calling release registry directly from the frontend. This
commit is just preparation for a fallback mechanism for users that do
not want the external dependency on release registry.



**feat(appliance): optionally load pinned releases file**

Instead of calling release registry. This is a fallback mechanism for
airgap users.



**feat(appliance): respect pinned release versions during self-update**
2024-08-14 09:24:51 +01:00
Julie Tibshirani
ca6e72fe18
Redis: remove RedisKeyValue constructor (#64442)
This PR removes the `redispool.RedisKeyValue` constructor in favor of
the `New...KeyValue` methods, which do not take a pool directly. This
way callers won't create a `Pool` reference, allowing us to track all
direct pool usage through `KeyValue.Pool()`.

This also simplifies a few things:
* Tests now use `NewTestKeyValue` instead of dialing up localhost
directly
* We can remove duplicated Redis connection logic in Cody Gateway
2024-08-14 11:24:32 +03:00
Felix Kling
34ff925ed8
feat(svelte): Add cody chat page (#64448)
Closes #srch-906

This commit adds the cody chat page to svelte. This is simply reusing
the existing wrapper around the React component and renders it in a
standalone page.

When merged this will cause the cody chat page to be handled by new web
app on dotcom by default.

## Test plan

- Verified that chat loads and the tabs are clickable.
- Verified that the scroll behavior works as in the React app.
- Verified that the sidebar chat still works as expected (scroll
behavior, default context loading/switching)
2024-08-13 19:25:32 +00:00
Kalan
f9f3cd86ec
Add verbiage to direct Cody feedback to VSC/JB repos (#64454)
<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

## Test plan
N/A text only
<!-- 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-08-13 19:18:46 +00:00
Robert Lin
043e780590
feat/enterpriseportal: add license creation webhook (#64422)
Closes https://linear.app/sourcegraph/issue/CORE-241
Originally added in
https://github.com/sourcegraph/sourcegraph/pull/59214

This seems unused, but might be good to have for completedness-sake

## Test plan

Unit tests
2024-08-13 12:11:03 -07:00
Robert Lin
2649987bac
fix/enterpriseportal: [MUST REVERT LATER] relax scopes for write operations (#64453)
Staging this PR in case we don't find a way to unblock
https://sourcegraph.slack.com/archives/C079SAU0E72/p1723573784387739?thread_ts=1723566345.486509&cid=C079SAU0E72.
If this passes CI first, I'll roll this out to Enterprise Portal to
unblock TS/CE

This is needed because we can't roll out
https://github.com/sourcegraph/sourcegraph/pull/64450 due to a stuck
migration

## Test plan

n/a
2024-08-13 11:58:49 -07:00
Camden Cheek
3522dcf4af
Svelte: fix file tree guide lines (#64425)
I think I broke this when doing some refactoring to make the file tree
usable in the ref panel. Currently, the guide lines only go one level of
depth.
2024-08-13 10:33:34 -06:00
Robert Lin
27d0615a3d
dotcom: request write scopes for EP prod proxy (#64450)
doh

## Test plan

n/a
2024-08-13 16:14:57 +00:00
Robert Lin
adce59be48
fix/enterpriseportal: adjust job check frequency, tweak messaging (#64418)
- The time.Second frequency is too frequent to be checking if the job
should be run, I think I set this in testing
- Adjust the Slack messaging to say `Active license`
- Adjust the Slack messaging to include the Salesforce subscription ID

## Test plan

Tests
2024-08-13 09:11:08 -07:00
Keegan Carruthers-Smith
f2fa76a8fd
migrations: remove support for NoTransaction (#64432)
This is a partial revert commit of
cbd12608b5.

We added support for NoTransaction but it isn't needed anymore. In fact
avoiding transactions leads to issues like poisoning connections.

Test Plan: CI
2024-08-13 16:08:36 +00:00
William Bezuidenhout
26f14c0888
ci: set go mod tidy step timeout (#64449)
Closes DINF-198

## Test plan
CI
```
{
      "label": ":bazel:🧹 Go mod tidy",
      "key": "bazel-go-mod",
      "command": [
        "./dev/ci/bazel-gomodtidy.sh"
      ],
      "timeout_in_minutes": "5",
      "retry": {
        "automatic": [
          {
            "limit": 1,
            "exit_status": "*"
          },
          {
            "limit": 1,
            "exit_status": -1
          }
        ]
      },
      "agents": {
        "queue": "aspect-small"
      }
    },
```

## Changelog
2024-08-13 17:45:30 +02:00
Keegan Carruthers-Smith
9d2220ea33
migration: specify column for soft delete triggers (#64446)
We believe the migration to add tenant_id is failing on dotcom is due to
this trigger which runs for any possible change to a row. Instead it
only needs to run if the deleted_at column changes. So this migration
just adjusts each trigger to only run if deleted_at is changed.

We don't need to change the trigger function, since the trigger
functions only read deleted at.

If this doesn't resolve our issue, we will need to look into a statement
level trigger for all our triggers.

Test Plan: CI and then will test safely on larger instances.
2024-08-13 15:03:49 +00:00
Shivasurya
3cb7ab8c6a
Support SAST Scanning with both GHAS and Custom post processing script (#64423)
This pull request supports buildkite semgrep sast scan to work on both
GHAS and with custom post processing script. This script checks if GHAS
is enabled or not and runs the semgrep scan and process the result. This
way we could support repositories without GHAS enabled.

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

## Test plan

- CI 🟢 
- sast scans are reported without any issues

<!-- 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
-->
- chore(security): Support SAST Scanning with both GHAS and Custom post
processing script
2024-08-13 09:43:09 -04:00
Felix Kling
9890086f94
fix(web): Show 'Find implementation' button for languages that support it (#64440)
Fixes srch-882

I noticed that the button wasn't shown anymore (neither in Svelte nor in
React). It seems that this broke when we switched from using the file
extension to getting the language(s) from the server.
The server sends back capitalized names which we compare against
lowercase IDs.

If there there is a new/modern way to find out whether a language
support 'find implementation' or not, please let me know. For the time
being this seems to be a simple fix to get it working again like it
before. Alternatively we can also compare the stylized name.

## Test plan

Hovering over a Go interface (e.g.
https://sourcegraph.sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/internal/conf/server.go?L12)
shows the 'find implementations' button in the hovercard again)
2024-08-13 15:40:03 +02:00
Felix Kling
3e734549c7
fix(svelte): Fix tooltip in hovercards (#64443)
Fixes srch-744

It seems that the code for testing whether the target element is part of
the layout didn't work in hovercards because it (possibly?) runs before
the hovercard is rendered.
Moving the logic to `onMount` + `await tick()` seem to work, although
that might still be a coincidence.

## Test plan

Hovering over the 'precise' badge shows the corresponding tooltip.
2024-08-13 15:39:35 +02:00
Felix Kling
df91f98feb
fix(svelte): Show tools section in top navigation sidebar mode (#64438)
Fixes srch-901

The CSS for sidebar mode wasn't updated after introducing the tools
menu.


## Test plan

Manual visual testing.
2024-08-13 13:24:36 +00:00
Felix Kling
9667975db6
fix(svelte): Show focus style when tabbing through search query examples (#64439)
## Test plan

Manual testing.
2024-08-13 12:11:28 +00:00
Keegan Carruthers-Smith
e93b69bef2
migrations: use COMMIT AND CHAIN for tenant_id (#64431)
We dived into our go postgres driver and when executing a migration it
is executed as a "simple query". Postgres in this case automatically
wraps the collection of statements in a transaction, unless it contains
transaction statements. So our last attempt at removing the transaction
failed.

In this attempt we use COMMIT AND CHAIN after each table alter. What
this does is commit the current transaction and then starts it up again.
From the perspective of the go driver, it is as if there was only one
transaction. We then switch the migration to using a transaction to
ensure the go drivers clean up the postgres connection in case of
failure.

IE if a query manually starts a transaction and does not clean up, the
connection will be marked as broken for the next person who gets the
connection from the pool. By wrapping in go's transaction code the
connection will be properly cleaned up.

Test Plan: All continuous environments have already succeeded or failed
on this migration number. So we will manually run this again against
them with the migrator code to ensure the same code paths. If they
succeed we will keep code as is, otherwise we will rollback.

Additionally we did lots of adhoc testing to understand the
characteristics of go and transaction handling.

Co-authored-by: Erik Seliger <erikseliger@me.com>
2024-08-13 11:59:59 +00:00
Ólafur Páll Geirsson
7b1bc10a30
chore/API: speed up edit/test feedback loop for llmapi module (#64437)
Previously, it took ~6 seconds for a single edit/test/debug feedback
loop in the `llmapi` module. After this change, it's now 1-2s.

The reason the feedback loop was slow was that we depended on the
`//cmd/frontend/internal/modelconfig` target, which transitively brings
in `graphqlbackend` and all the migration code, which adds huge overhead
to Go link times. It was relatively easy to untangle this dependency so
I went ahead and removed it to boost my local feedback loop.

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

## Test plan
Green CI.

To measure the timing, I ran the tests, made a tiny change and ran the
tests against to measure the total time to build+test.

```
# Before
❯ time go test -timeout 30s github.com/sourcegraph/sourcegraph/cmd/frontend/internal/llmapi
ok  	github.com/sourcegraph/sourcegraph/cmd/frontend/internal/llmapi	2.394s
go test -timeout 30s   4.26s user 4.73s system 166% cpu 5.393 total

# After
❯ time go test -timeout 30s github.com/sourcegraph/sourcegraph/cmd/frontend/internal/llmapi
ok  	github.com/sourcegraph/sourcegraph/cmd/frontend/internal/llmapi	0.862s
go test -timeout 30s   1.20s user 1.21s system 135% cpu 1.774 total
```
<!-- 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-08-13 11:48:15 +00:00
Noah S-C
d4fa539b31
Revert "chore(ci): rework build-tracker to use redis instead of in-memory store of build results" (#64436)
Reverts sourcegraph/sourcegraph#64304

Number of redis related issues cropped up live

## Test plan

CI
2024-08-13 13:22:41 +02:00
Bolaji Olajide
4d57eb1188
fix(sg): make sg gen output more readable (#64406)
Closes DINF-78

The output of `sg gen` is a bit hard to read when there's an error, this
is because the new line character `\n` isn't rendered as a new line. It
turns out the `%q` formatting directive used to quote a string doesn't
render the `\n` character as a new line.

| Before |
|---|
| ![CleanShot 2024-08-12 at 11 17
57@2x](https://github.com/user-attachments/assets/e03ec503-e437-4b68-80b3-fe34ac8848fb)
|

| After  |
|---|
| ![CleanShot 2024-08-12 at 10 53
35@2x](https://github.com/user-attachments/assets/5b7aac63-27b6-4de0-9c56-3b739f0ee0f9)
|

I also added a func to extract error messages from a bazel command to
avoid long output message when a bazel command fails and give the user
relevant messages related to the error.

| Before  |
|---|


https://github.com/user-attachments/assets/2d029ec1-5804-41bf-a675-8642e169ea80


| After  |
|---|
| ![CleanShot 2024-08-12 at 14 45
59@2x](https://github.com/user-attachments/assets/7d567fd6-de37-48aa-b2b5-03dc591fc77a)
|

## Test plan

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

* Manual testing

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-13 06:22:21 -05:00
Noah S-C
67f30a9d7a
chore(ci): rework build-tracker to use redis instead of in-memory store of build results (#64304)
Currently, build-tracker keeps track of consecutive build failures
through an in-memory store of failed builds. As this gets deployed more
frequently on MSP, we lose state more frequently which would result in
incorrect results. Instead, we can use redis as our external store as
well as for locking using redsync

## Test plan

Unit tests have been updated, but proper testing will require live
traffic

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-13 10:32:09 +00:00
Ólafur Páll Geirsson
47b66397da
feat/API: move from /api/v1 to /.api/llm (#64435)
Fixes CODY-3269

Previously, the OpenAI-compatible API endpoints had paths like
`/api/v1/chat/completions`, which went against an existing convention of
keeping all APIs under the `/.api` prefix. We have a fair amount of
internal tooling centered around the assumption that APIs have the
`/.api` prefix so this PR corrects the mistake and moves the
`/api/v1/chat/completions` endpoint to `/.api/llm/chat/completions`.

I went with the prefix `/.api/llm` since these allow clients to interact
with LLM features like `/chat/completions` or listing model information.
These APIs happen to be compatible with OpenAI APIs but I think it will
be more confusing to add something like "openai" or "openaicomptable" in
the API endpoint. We can just document on our website that these
endpoints are compatible with OpenAI clients.

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

## Test plan

Green CI. I also manually confirmed that I was able to use an OpenAI
client to send requests to the new APIs.
<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

* Moved `/api/v1/chat/completions` to `/.api/llm/chat/completions`. The
functionality is unchanged.

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-13 10:21:27 +00:00
Erik Seliger
6914068c8c
migrationtests: Actually run in a transaction when in test mode (#64434)
When we added a migration that actually relies on the promised property
of migrations always running inside a transaction, we noticed that the
memoryStore implementation we use in the dbtest package does not
actually start a transaction. This implements transactions for the
memorystore as well, to make it pass.

Test plan: Our migration now passes, and dbtest performance with and
without this change is the same.
2024-08-13 10:07:06 +00:00
Christoph Hegemann
a80ad938ce
fix: return all search-based results if no syntactic provenance is requested (#64330)
Closes
https://linear.app/sourcegraph/issue/GRAPH-797/return-all-search-based-results-if-syntactic-is-not-requested

Making sum-types like a caveman...

## Test plan

Manual testing via API. I can't make the web app do a search-based
usages request at the moment.
2024-08-13 10:52:56 +02:00
Ólafur Páll Geirsson
70aa6908ea
fix/API: make requests to /api/console work again (#64429)
Fixes CODY-3267

Previously, requests to `/api/` matched the new `publicrestapi` module,
which meant that requests to the GraphQL `/api/console` no longer
worked. This PR fixes the problem by narrowing the prefix-match to
`/api/v1` so that it no longer matches `/api/console`.

I kept the scope of this PR narrow and only fixed the /api/console bug.
I will share a separate RFC to seek input on the tradeoffs between
/api/v1 and /.api. I can make that change separately if there's wide
consensus in #wg-architecture that we want to keep all API endpoints
(public and internal-facing) under /.api.

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

## Test plan

Ran `sg start minimal` and confirmed that I'm able to visit the URL
https://sourcegraph.test:3443/api/console

On the main branch, the same URL leads to a 404 page.

I also confirmed that the `/api/v1/chat/completions` endpoint still
works as expected.

```hurl
POST https://sourcegraph.test:3443/api/v1/chat/completions
Content-Type: application/json
Authorization: Bearer {{token}}
{
  "model": "anthropic::unknown::claude-3-sonnet-20240229",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Respond with \"no\" and nothing else"
        }
      ]
    }
  ],
  "temperature": 1,
  "max_tokens": 256,
  "top_p": 1,
  "frequency_penalty": 0,
  "presence_penalty": 0
}
```
```sh
❯ hurl hurl-scratchpad/openai-sg.hurl
{"id":"chat-1727acdf-6850-4387-950b-2e89850071fa","choices":[{"finish_reason":"end_turn","index":0,"message":{"content":"no","role":"assistant"}}],"created":1723536215,"model":"anthropic::unknown::claude-3-sonnet-20240229","system_fingerprint":"","object":"chat.completion","usage":{"completion_tokens":0,"prompt_tokens":0,"total_tokens":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
-->
2024-08-13 10:04:40 +02:00
Julie Tibshirani
2bbd84fac4
Redis: refactor key prefixing (#64411)
Our redis `KeyValue` interface has a built-in way to prefix all keys.
This is helpful for integration tests, to contain all keys within a test
namespace.

This PR solidifies the implementation by pushing down the prefixing as
much as possible. In doing so, it fixes a bug with the `Keys()` method
where we forgot to prefix the pattern. This makes it easier to add new
methods to the interface without forgetting to add the prefix.
2024-08-13 10:13:02 +03:00
Keegan Carruthers-Smith
cbd12608b5
database: run tenant_id migration outside of a transaction (#64410)
We hit a deadlock when deploying this migration to s2. This is because
within our transaction of the migration we likely didn't obtain table
locks in the same order as a transaction in our application code.

So this commit introduces a new migration metadata field
"noTransaction". The documentation for migrator says you should create a
migration per needed transactions. However, this would require us to
create 100s of migrations. We believe the better approach is introducing
this field and barely advertising it.

When reading the code which actually runs migrations, there is no extra
logic done outside of BEGIN; run_migration; COMMIT; so this change is
safe.

We update the migrations to avoid duplicating the function name we
introduce in case something goes wrong (now that the transaction could
leak out the function name).

Test Plan: The actual migrations are tested by go test. I added a test
assertion that we don't call Transact, but to be honest that is super
sketchy. However, we couldn't actually find any test fixtures which
actually run against the DB. So that would require a much deeper
investment for how simple the code change is.

Co-authored-by: Erik Seliger <erikseliger@me.com>
2024-08-13 07:08:19 +02:00
Michael Lin
20f22d29f0
sg/cloud: fix eph cmd typo (#64427)
fixed typo. these commands are under `sg cloud eph`

## Test plan

CI
2024-08-13 06:53:07 +02:00
Jacob Pleiness
b5d7a4f598
fix(release): add minor step to internal release create command (#64377)
<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

This PR adds the ability to use `--type minor` when running `sg release
create` during the release process.

For the time being this step is the _same_ as `--type patch` which is
the default, however this allows us to differentiate the two types now
and prepares for when/if the two types diverge. This also clears up the
some confusion as the `sg release` command _can_ accept `--type minor`
already and one would expect that to be the choice when you are in fact
cutting a minor type.

Closes:
https://linear.app/sourcegraph/issue/REL-351/sourcegraphsourcegraph64377-fixrelease-add-minor-step-to-internal

## Test plan

Tested locally with `--type minor` tag.

```shell
➜  sourcegraph git:(08-08-jdp_release_minor-flag-addition) sg release create --version 5.6.877 --type minor
👉 [     setup] Finding release manifest in "."
   [     setup] No explicit branch name was provided, assuming current branch is the target: 08-08-jdp_release_minor-flag-addition
   [     setup] Found manifest for "sourcegraph" (github.com/sourcegraph/sourcegraph)
   [      meta] Owners: @sourcegraph/release
   [      meta] Repository: github.com/sourcegraph/sourcegraph
👉 [      vars] Variables
   [      vars] version="v5.6.877"
   [      vars] tag="5.6.877"
   [      vars] config="{\"version\":\"v5.6.877\",\"inputs\":\"\",\"type\":\"minor\"}"
   [      vars] git.branch="08-08-jdp_release_minor-flag-addition"
   [      vars] is_development="false"
.... Stuff here
   [ buildkite] Build created, see:
   [ buildkite] "https://buildkite.com/sourcegraph/sourcegraph/builds/287192"
   [      step] Step "buildkite" succeeded
```

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

## Changelog

Internal change, N/A

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-12 19:48:18 -04:00
Camden Cheek
a9b536cbcd
Chore: fix default value for clientSearchResultRanking (#64420)
The search clients [default to using Zoekt's
ranking](https://sourcegraph.com/github.com/sourcegraph/sourcegraph@f010787579fc0b88ef945a6cfd0091c58eefceeb/-/blob/client/web-sveltekit/src/routes/search/FileContentSearchResult.svelte?L29-29)
if this setting is unset, but it's documented as defaulting to ordering
by line number. Just fixes the default in the schema, which is only used
for documentation.
2024-08-12 22:47:08 +00:00
Varun Gandhi
74f4831aa3
chore: Replace gitserver.Client -> minimalGitserver in codenav (#64416)
In codenav, we use very few APIs from gitserver, so let's use a more
narrow interface (which we can potentially fake in the future) instead
of depending on gitserver.Client directly.
2024-08-12 16:40:36 -04:00
Keegan Carruthers-Smith
6a28eb85bb
tenant: set pprof label for tenant (#64338)
In the future this will allow us to attribute stack traces collected by
pprof to a tenant. This only sets it for the http middleware. I am
unsure how to achieve the same thing for grpc, since that uses
propogators.

Test Plan: captured a goroutine profile and saw some goroutines with a
tenant label

---------

Co-authored-by: Erik Seliger <erikseliger@me.com>
2024-08-12 19:40:26 +00:00
Keegan Carruthers-Smith
520444ef61
linters: update go-critic to latest (#64419)
I was tired of seeing this warning when running gazelle:

  gazelle: finding module path for import github.com/go-critic/go-critic/framework/linter: go: downloading github.com/go-critic/go-critic v0.11.4
  go: module github.com/go-critic/go-critic@upgrade found (v0.11.4), but does not contain package github.com/go-critic/go-critic/framework/linter

This updated go-critic to the latest version which makes the warning go
away since it now uses the new package path.

Test Plan: gazelle is happy and CI is happy
2024-08-12 21:30:49 +02:00
Robert Lin
cec288dc89
fix/enterpriseportal, fix/codygateway: zero-value durations and missing active licenses (#64378)
This change ensure we correctly handle:

1. In Enterprise Portal, where no active license is available, we return
ratelimit=0 intervalduration=0, from the source `PLAN` (as this is
determined by the lack of a plan)
2. In Cody Gateway, where intervalduration=0, we do not grant access to
that feature

## Test plan

Unit tests
2024-08-12 11:49:54 -07:00