Commit Graph

37130 Commits

Author SHA1 Message Date
Ólafur Páll Geirsson
7bc210bd4e Cody: add support for neovim, cody-cli, eclipse, and visualstudio clients (#63851)
Fixes CODY-2884

Previously, the server could respond with a 406 error when encountering
clients with the following names: cody-cli, eclipse, and visualstudio.
This error seems to only happen for enterprise clients. This PR fixes
the problem by adding special cases for these clients like we already
have for jetbrains and cody web.

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

## Test plan

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

## Changelog

- Fix HTTP 406 error when using the Neovim Cody plugin with Enterprise
instances
<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-16 15:31:58 +02:00
Vova Kulikov
20adc60d67
[Backport-5.5.x]: Move Cody Web to beta (#63806) (#63808)
Closes

https://linear.app/sourcegraph/issue/CODY-2847/change-experimental-labels-to-beta

## Test plan
- Check that the cody web page and cody web side panel have beta badges

(cherry-picked from commit fbb0a1fec1)

## Test plan
- Check that the side-panel Cody and Cody Chat page have beta product
status badges
2024-07-15 12:07:10 -07:00
Release Bot
308624f144
[Backport 5.5.x] Context: return lines around symbol match (#63788)
This PR fixes an important bug in #62976, where we didn&#39;t properly
map the
symbol line match to the return type. Instead, we accidentally treated
symbol
matches like file matches and returned the start of the file.

## Test plan

Add new unit test for symbol match conversion. Extensive manual testing.
<br> Backport 004eb0fd83 from #63773

Co-authored-by: Julie Tibshirani <julietibs@apache.org>
2024-07-11 16:14:52 -04:00
Release Bot
174c08c8c2
[Backport 5.5.x] fix/alertmanager: downgrade prometheus/common to fix generated config (#63793)
The OTEL upgrade https://github.com/sourcegraph/sourcegraph/pull/63171
bumps the `prometheus/common` package too far via transitive deps,
causing us to generate configuration for alertmanager that altertmanager
doesn&#39;t accept, at least until the alertmanager project cuts a new
release with a newer version of `promethues/common`.

For now we forcibly downgrade with a replace. Everything still builds,
so we should be good to go.

## Test plan
`sg start` and `sg run prometheus`. On `main`, editing
`observability.alerts` will cause Alertmanager to refuse to accept the
generated configuration. With this patch, all is well it seems - config
changes go through as expected. This is a similar test plan for
https://github.com/sourcegraph/sourcegraph/pull/63329

## Changelog

- Fix Prometheus Alertmanager configuration failing to apply
`observability.alerts` from site config <br> Backport
ffa873f3ad from #63790

Co-authored-by: Robert Lin <robert@bobheadxi.dev>
2024-07-11 15:49:58 -04:00
Release Bot
8ee41490b9
[Backport 5.5.x] release/bug: generate a new stitched migration graph (#63769)
This will correct6 upgrade path for mvu plan creation

## Test plan

CI test



## Changelog


 <br> Backport cb19d6f0a9 from #63764

Co-authored-by: Warren Gifford <warren@sourcegraph.com>
2024-07-10 22:01:36 +00:00
Release Bot
344169fd47
[Backport 5.5.x] chore(release): bump stitch graph generation (#63768)
Missing bit for the minor release version bump

## Test plan

CI


 <br> Backport 087ad83995 from #63767

Co-authored-by: Jean-Hadrien Chabran <jean-hadrien.chabran@sourcegraph.com>
2024-07-10 21:00:59 +00:00
Anish Lakhwara
d47b4cc48b
fix(build): update wolfi image lock for otel (#63755)
<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->
We need to update the wolfi lock image for
https://github.com/sourcegraph/sourcegraph/pull/63171 in order for `sg
run` to work

We've made all the changes to the deployment repos for this to be pushed
out in the release today.

## 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
-->
- fix(build): update wolfi lock for otel-collector
2024-07-10 10:23:11 -07:00
Bolaji Olajide
c712d8d087
chore: add changelog entry for Batch Changes <> GitHub apps integration (#63756)
Changelog update

## Test plan

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

## Changelog

* Batch Changes: GitHub apps can now be added as a credential for
authentication and interacting with changesets.
[#31533](https://github.com/sourcegraph/sourcegraph/issues/31533)
2024-07-10 16:26:01 +00:00
Robert Lin
7d91894a01
chore/otel-collector: upgrade to v0.103.0, remove jaegerexporter (#63171)
Thread:
https://sourcegraph.slack.com/archives/C1JH2BEHZ/p1717797870638299

One problem caused by this upgrade is that the [deprecated
`jaegerexporter`](https://github.com/open-telemetry/opentelemetry-specification/pull/2858)
no longer builds at all with the last published version, so for the
upgrade to go through it must be removed. I've updated local `sg start`
to work with this change, but some Release team support is needed for
deployment configuration + customer-facing docs changes:
https://sourcegraph.slack.com/archives/C1JH2BEHZ/p1718143249191349?thread_ts=1717797870.638299&cid=C1JH2BEHZ,
since current guidance asks customers to configure `jaegerexporter`.

Part of https://linear.app/sourcegraph/issue/SEC-1680

Closes https://linear.app/sourcegraph/issue/CORE-177

## Test plan

Followed steps shared in
https://sourcegraph.slack.com/archives/C04MYFW01NV/p1718136211292469 to
run locally, since `sg run jaeger otel-collector` alone is insufficient
to get updated images:

```diff
diff --git a/wolfi-images/opentelemetry-collector.yaml b/wolfi-images/opentelemetry-collector.yaml
index b995a3d531b..76de80d4f84 100644
--- a/wolfi-images/opentelemetry-collector.yaml
+++ b/wolfi-images/opentelemetry-collector.yaml
@@ -7,7 +7,11 @@ contents:
     - mailcap
 
     ## opentelemetry-collector packages
-    - opentelemetry-collector@sourcegraph
+    - opentelemetry-collector@branch
+  keyring:
+    - https://packages.sgdev.org/sourcegraph-melange-dev.rsa.pub
+  repositories:
+    - '@branch https://packages.sgdev.org/branches/otel-collector-upgrade'
 
 paths:
   - path: /otel-collector
```

plus `sg wolfi lock opentelemetry-collector` will make `sg run
otel-collector` use the correct image.

**The above diffs SHOULD NOT be committed. The lock should happen
post-merge.**

Spot-checked some traces locally with:

```
sg run jaeger otel-collector
sg start
```


![image](https://github.com/sourcegraph/sourcegraph/assets/23356519/dff88d5a-db9a-4039-b7ba-682e120bdc41)


![image](https://github.com/sourcegraph/sourcegraph/assets/23356519/7e553894-0026-47de-ae38-ba5502b94c63)


## Changelog 

- OpenTelemetry Collector: Upgraded OpenTelemetry Collector to v0.103.0
- OpenTelemetry Collector: The [deprecated `jaegerexporter` has been
removed](https://github.com/open-telemetry/opentelemetry-specification/pull/2858).
Users of `exporter: { jaeger: ... }` in the OpenTelemetry Collector
should use `exporter: { otlp/jaeger: ... }` to send traces directly to
Jaeger via its OTLP receiver.
- Users of the default Jaeger configurations now need to provide
`JAEGER_OTLP_GRPC_PORT` as well as the existing `JAEGER_HOST`
configuration.

---------

Co-authored-by: Anish Lakhwara <anish+github@lakhwara.com>
Co-authored-by: Anish Lakhwara <anish+git@lakhwara.com>
2024-07-10 09:01:41 -07:00
Petri-Johan Last
23128d1489
fix(perforce) Fix support for p4breaker workaround scripts (#63611) 2024-07-10 17:39:54 +02:00
Camden Cheek
52ebd70bd0
Chore: remove gorilla/schema (#63738)
We created a decoder that was never used, but the package is otherwise
unused. It recently had a CVE, so this just removes it so it's no longer
part of our security surface area.
2024-07-10 15:36:37 +00:00
Craig Furman
824116eca8
chore(appliance): SetupEnvtest returns k8s config, not client (#63749)
Make SetupEnvtest slightly lower-level by asking callers to construct
their own client from the returned k8s REST config. This is because
there are 2 kinds of official kubernetes client in Go - a
kubernetes.Clientset and a client.Client. The latter is
more-traditionally used in operators, because it's what a
ControllerManager.GetClient() returns, and indeed this is what our
reconciler uses.

We ended up using a kubernetes.Clientset in the envtest-using golden
tests for the reconciler, because its mechanics for listing resources
were simpler. Now, I want to reuse SetupEnvtest somewhere that needs a
client.Client. We could undertake work to use only one flavor of
kubernetes client, but this commit seems like a decent low-cost first
step.
2024-07-10 14:59:09 +01:00
Bolaji Olajide
43f907f8a9
fix(batches): enable check for creating source as non credential (#63751)
This check was wrong as we create a non-credential source only when the
ChangesetSource strategy isn't `GitHubApp`

## 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-07-10 13:58:13 +00: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
Christoph Hegemann
d3df71ef98
Adds a test for search-based usages (#63610)
Closes
https://linear.app/sourcegraph/issue/GRAPH-726/test-syntactic-and-search-based-usages

Testing just the search-based usages just requires mocking the
SearchClient, which works out nicely.

## Test plan

The whole PR is just a test
2024-07-10 13:22:53 +00:00
Jean-Hadrien Chabran
2645a9b04d
chore(migrator): bump migration archive (#63752)
Routine update, as this is still a manual process.

## Test plan

CI
2024-07-10 15:10:32 +02:00
Nelson Araujo
08ed73cd3d
Convert Appliance Maintenance UI to Bazel (#63661)
Write Bazel machinery for the Appliance maintenance UI.

## Test plan

- `bazel build ...` passes
- `pnpm run dev` launches app successfully

---------

Co-authored-by: Jean-Hadrien Chabran <jh@chabran.fr>
2024-07-10 13:47:18 +02: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
Varun Gandhi
743134a193
docs: Fix inaccuracies in RangeInput GraphQL docs (#63640) 2024-07-10 09:47:10 +00:00
sourcegraph-buildkite
8efbdc2d49
security: Auto-update package lockfiles for Sourcegraph base images (#63606)
Automatically generated PR to update package lockfiles for Sourcegraph
base images.

Built from Buildkite run
[#281769](https://buildkite.com/sourcegraph/sourcegraph/builds/281769).
## Test Plan
- CI build verifies image functionality

Co-authored-by: Buildkite <buildkite@sourcegraph.com>
2024-07-10 09:21:27 +01:00
Felix Kling
a8639c1328
chore(svelte): Update cody web version (#63747)
Similar to https://github.com/sourcegraph/sourcegraph/pull/63742 this
updates to the latest cody web version in the new web app.

## Test plan

Manual testing
2024-07-10 07:58:21 +00:00
Michael Bahr
bd1488167f
fix: remove watch path that's gone (#63746)
https://github.com/sourcegraph/sourcegraph/pull/63736 removed rockskip
files, which lead to `sg start` failing because it was still watching
those. This PR removes the watch and lets `sg start` succeed again.

## Test plan

Existing CI, manual test of `sg start`

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-10 06:56:25 +00:00
Vova Kulikov
fea468bd14
Bump cody-web-experimental to 0.2.4 (#63742)
Follow up for https://github.com/sourcegraph/cody/pull/4826

In the latest release, 0.2.4, we fixed the problem that @fkling found
about links
[here](https://linear.app/sourcegraph/issue/SRCH-633/links-in-the-prompt-has-incorrect-url-in-cody-web#comment-b9427c46);
cody assistance can render links in its response via markdown, and in
0.2.3, these links had deep link vscode command, which didn't work
properly in cody web. Now it renders plain links when it's rendered for
Cody Web.

## Test plan
- Check that links that Cody assistance provides work properly and don't
have any deep links command

<!-- 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-09 21:23:08 -06:00
Erik Seliger
2e392e0e89
Unexport some externally irrelevant symbols from uploadstore (#63647)
These symbols aren't used outside of the package, so unexporting them
for a cleaner API surface.

Test plan:

Go compiler doesn't complain.
2024-07-10 02:45:02 +02:00
Erik Seliger
9435fde3a2
Remove unused package (#63646)
This package isn't in use anymore, so cleaning it up.

Test plan:

Go compiler doesn't complain.
2024-07-10 02:30:28 +02:00
Erik Seliger
eb39e68761
scheduler: Simplify query for uncloned repos (#63681)
Since we removed on-demand cloning, the scheduler is now expected to always contain all repositories. Thus, we no longer need to constrain the set of uncloned repos to a ginormous ID list.

Test plan:

CI still passes.
2024-07-10 02:24:32 +02:00
Erik Seliger
8bc8ad27bd
phabricator: Move syncer to worker (#63682)
This syncer doesn't depend on anything in repo updater, so we're moving it to worker instead, where it can selectively be disabled and is properly monitored.

Test plan:

CI passes, code review.
2024-07-10 02:24:18 +02:00
Erik Seliger
ac0d497315
Remove old cache cleanup method (#63645)
We have been using v2 data since >5 years now, this should be safe to
remove.

As a side-effect, we have one less background task running in frontend,
which means it ran N times in horizontally scaled environments, which
isn't exactly useful.

Test plan:

Code review.
2024-07-10 02:04:53 +02:00
Erik Seliger
a32b6131f3
codygateway: Use only one redis pool and make REDIS_ENDPOINT a clear requirement in config (#63625)
Currently, nothing really tells that Cody Gateway needs redis, the env
var for finding the address is hidden somewhere deep in the redispool
package.
In practice, we only use one redis instance, but at some point we
started using both redispool.Cache and redispool.Store, which means we
maintain two connection pools, leading to more than expected
connections.

Test plan:

Code review and CI.
2024-07-10 01:54:24 +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
Erik Seliger
169db11ce6
rcache: Explicitly pass redis pool to use (#63644)
Recently, this was refactored to also allow using the redispool.Store.
However, that makes it very implicit to know where something is being
written, so instead we pass down the pool instance at instantiation.

This also gives a slightly better overview of where redispool is
actually required.

Test plan: CI passes.
2024-07-10 01:23:19 +02:00
Erik Seliger
60dc37d1a5
symbols: Minor code cleanup (#63708)
Was reading through the service, found these things and figured why not
commit them.

Test plan:

CI.
2024-07-10 01:22:03 +02:00
Stephen Gutekanst
bd3baef6e0
pass ModelConfigInfo down to client.Get() for self-hosted-models (#63739)
This PR has a single goal: pass a new `ModelConfigInfo` type, which has
the `Provider` and `Model` we should use to serve a completions request,
down into `client.Get()`

This PR explicitly only handles the case we care about for Self-hosted
models, and all pieces of logic that I expect will be
replaced/superseded by your work @chrsmith are annotated with `//
TODO(slimsag): self-hosted-models:` comments so we can easily find and
remove them when your work is ready.

Every location I have modified has been carefully wrapped in an if
statement like `if conf.Get().SiteConfig().ModelConfiguration != nil` to
ensure that this change _only_ affects people who set the new
`"modelConfiguration"` site config property.

## Test plan

1. Configured `"modelConfiguration"` and removed `"completions"` in my
dev instances' site config.
2. Used VS Code chat to confirm I see this codepath is connected
end-to-end and I get a `TODO` error back:

<img width="679" alt="image"
src="https://github.com/sourcegraph/sourcegraph/assets/3173176/d3c07ffe-7ec2-4ad9-9251-2272ce36d44b">

## Changelog

N/A

---------

Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
2024-07-09 15:30:37 -07:00
Felix Kling
82372119fe
fix(svelte): Prefill search home page query input with (default) context filter (#63740)
Closes srch-103

Currently we don't show the global context filter on the search home
page or the search results page (global context is the default context).

This commit does two things:

- It prefills the search input on the search homepage with the user's
default context (like the React app)
- It the logic that pre-processed the search query and removed the
context filter if it was global.

In other words we simplify the query logic by showing/submitting the
search query as is. Notably this doesn't affect how the search input
works on repo pages.


## Test plan

- Opening the search home page pre-fills the query input with the
default search context
- Submitting a query without a `context:` filter does not add a
`context:` filter to the URL or the search input
- If a query contains `context:global` that filter is preserved in the
query input (it wasn't before)
2024-07-09 22:02:04 +00:00
Felix Kling
b9dd3a774d
chore(svelte): Use MDI icons for seach input pattern type toggles (#63733)
We don't like the style/alignment of the Lucide case sensitivity and
regex icons (the structural search icon seems fine). This commit
switches them back to the MDI icons that we used before.

Solution or temporary workaround (tbd) for srch-544


## Test plan

Manual testing.
2024-07-09 21:56:00 +00:00
Matthew Manela
4c3985e16f
feat(Source): Properly render multi-line changelist messages from Perforce (#63728)
Fixes SRC-431

Mutli-line perforce changelist descriptions were not being handle since
the code implicitly assumed they could not exist. This change enables
support for them.


## Screenshots

**Changelist view with both single and multiline commits**

![image](https://github.com/sourcegraph/sourcegraph/assets/304410/8c7ead01-fdec-461c-826b-83013f89ad77)

**Changelist view with expanded commit message**

![image](https://github.com/sourcegraph/sourcegraph/assets/304410/a16c8637-7180-4631-88cb-39b4cc49a74c)

**Individual changelist item**

![image](https://github.com/sourcegraph/sourcegraph/assets/304410/c63f0a49-f6a9-430c-9caf-0480c17bb64e)


## Test plan
1. Update unit tests
2. Validate both P4 and non-p4 commits work
3. Validate on s2

## Changelog

- Properly render multi-line perforce changelist descriptions
2024-07-09 17:52:05 -04:00
Robert Lin
28f797e866
feat/enterpriseportal: database layer for subscriptions upsert (#63703)
Implements upsert for all the subscriptions fields in the DB client. As
part of this I generalized the logic for building upsert DB interactions
into a new `upsert` package, because this pattern is a common one we'll
need to implement to maintain various AIP-update-compliant endpoints,
which specifies various upsert behaviours: https://google.aip.dev/134

Part of CORE-216
Part of CORE-156

## Test plan

Integration tests against DB
2024-07-09 14:35:00 -07:00
Robert Lin
d7ab268385
feat/dotcom: add Enterprise Portal auth proxy (#63652)
Part of https://linear.app/sourcegraph/issue/CORE-211

This introduces authenticated proxies that allow dotcom site admins
access to dev and production Enterprise Portal instances, authenticated
with client credentials issued to the dotcom instance. The medium-term
goal is to use this proxy so that we can use the existing subscriptions
UI, backed by the new Enteprise Portal deployments (e.g.
https://github.com/sourcegraph/sourcegraph/pull/63653, tracking issue:
https://linear.app/sourcegraph/issue/CORE-100/enterprise-portal-migrate-away-from-dotcom-db-as-source-of-truth),
until we have a dedicated UI for Enterprise Portal
(https://linear.app/sourcegraph/project/kr-p-enterprise-portal-user-interface-dadd5ff28bd8)

This is required until we ship
https://linear.app/sourcegraph/project/kr-p1-streamlined-role-assignment-via-sams-and-entitle-2f118b3f9d4c/overview,
which will allow SAMS to be the source-of-truth for who is a site admin
in Sourcegraph.com. Once we have that information, we can use the user's
SAMS session directly in Enterprise Portal to authorize access to
Enterprise Portal data.

## Test plan

Set up `dev-private` with dev credentials:
https://github.com/sourcegraph/dev-private/pull/101

`sg start dotcom`, create a personal access token, and try to make
ConnectRPC requests matching the spec to the new endpoints:

```sh
# Local
curl --header "Content-Type: application/json" --header "authorization: token sgp_local_..." --data '{"filters":[{"filter":{"is_archived":false}}]}' -v  \
    https://sourcegraph.test:3443/.api/enterpriseportal/local/enterpriseportal.subscriptions.v1.SubscriptionsService/ListEnterpriseSubscriptions
# Dev
curl --header "Content-Type: application/json" --header "authorization: token sgp_local_..." --data '{"filters":[{"filter":{"is_archived":false}}]}' -v  \
    https://sourcegraph.test:3443/.api/enterpriseportal/dev/enterpriseportal.subscriptions.v1.SubscriptionsService/ListEnterpriseSubscriptions
```

Note that the URL path after `/.api/enterpriseportal/dev/`, i.e.
`/enterpriseportal.subscriptions.v1.SubscriptionsService/ListEnterpriseSubscriptions`,
and the shape of the parameters, are all the same as if you curl'd the
Enterprise Portal API directly, per the Connect protocol:
https://connectrpc.com/docs/protocol/

Both local and dev reach out to the existing SAMS dev deployment for
credentials, so the `dev-private` credentials work OOTB for both.

---------

Co-authored-by: Andre Eleuterio <andreeleuterio@users.noreply.github.com>
2024-07-09 13:46:59 -07:00
Felix Kling
160d1bf56d
chore(svelte): Update to latest cody web version (#63732)
Yet another PR to get cody web up-to-date in the new web app.

## Test plan
Manual testing.
2024-07-09 20:22:18 +00:00
Chris Smith
232cfcb097
Several refactoring to prepare for rolling out modelconfig (#63731)
This PR bundles several small refactoring to make it easier to review
the pending "refactor completion APIs to read from modelconfig".

Going commit-by-commit:

[Export the ValidateModelRef
function](3c949a88d0)

This just exports a validation function that was previously private from
the `internal/modelconfig` package. We'll be using this to sanity check
the `ModelRef` that is returned from the "getModelsFn".


[Add modelconfig.{InitMock,
ResetMock}](f807f40bf5)

In order to update the `frontend/internal/httpapi/completions` unit
tests, we need to have changes to the site configuration data _ALSO_
update the global `modelconfig.Service`. Typically this would happen by
a "config watcher" that gets registered, but we don't do that as part of
unit tests.

So instead, I just added some clunky `InitMock() error` and `ResetMock()
error` functions to support unit testing. If you have a better idea for
how to expose this behavior, I'm all ears.

[Move fireworks-specific API types into
types.go](bb02ccba45)

Moves the API data types for the `fireworks` client into their own file,
just to keep things tidy.

[Refactor completion
clients](02a5e3bfc9)

This is a bit involved, but from a high-level, we are just passing the
`types.CompletionRequest` object "lower" into the call stack. Rather
than only return the `.Parameters` field
(`types.CompletionRequestParameters`).

This is necessary, because I plan on adding another field to
`types.CompletionRequest` (to include the `modelconfig.Provider` and
`modelconfig.Model` data). So this change just does some of the work for
that now, resulting in a smaller and easier to review diff later.

Also, in some cases I moved the calls to
`tokenManager.UpdateTokenCountsFromModelUsage` into a dedicated function
to simplify the callsites.

## Test plan

Existing unit tests

## Changelog

NA
2024-07-09 13:16:36 -07:00
Erik Seliger
df4c636dc5
squirrel: Correctly use request context (#63729)
The ctx parameter was unused, and I noticed that the parser is called
without the request context. Fixing that here.

Test plan:

Code review and CI.
2024-07-09 22:06:01 +02:00
Camden Cheek
5d8286b90f
Backend: add line index (#63726)
This adds a line index utility. Frequently, I want to be able to
efficiently index a file to extract a specific line or range of lines,
but it's surprisingly tricky to get exactly right given weird
definitions of "what even is a line" and edge conditions around
out-of-bounds and such.

So this adds a general-purpose utility to pre-calculate the locations of
lines in the file, making extracting a line range a zero-allocation,
`O(1)` operation.

Not implemented: the same index can also be used to find the line that
contains an offset, which I've also needed to do before. But I'll save
that for when I actually have an immediate use for it.
2024-07-09 19:59:42 +00:00
Felix Kling
0fc4d2811a
feat(svelte): Add reblame support to blame column (#63727)
Closes srch-612

This commit adds a link next to the blame commit message that allows
reblaming to a prior commit if available.

It extends the existing blame extension. This won't have any affect on
the React app because it doesn't pass the configuration option needed to
add the extra gutter.

Some notes:

- I originally used the tooltip component instead of `title` but somehow
it starts to break when scrolling the document (tooltips don't show up
anymore). I don't know if CodeMirror does anything to the DOM elements
that causes this to fail.
- The reblame URL also selected the corresponding line so that the
correct line is scrolled into view.


## Test plan

Manual testing
2024-07-09 21:30:14 +02:00
Erik Seliger
fab128120d
searcher: Modernize entrypoint and gRPC server (#63700)
This PR does a bit of cleanup / alignment with other services, most
notably:

- Loads config via the config method of the shared routine package plus
tests for default config values
- Listens on HTTP using the existing httpserver package
- Makes it clear what gitserver methods are used by calling them at the
entry function instead of passing the whole client down
- Adds exhaustive request logging for better auditability (and found an
unused field which I removed)
- Rename log to logger
- Add the common stack of HTTP middlewares for actor, client etc
propagation

Test plan:

Unit tests still pass. CI is green and I was able to run unindexed
searches locally.
2024-07-09 21:10:11 +02:00
Stephen Gutekanst
071de9e33e
modelconfig: handle converting site config JSON -> internal data types (#63706)
This causes the `modelconfig` package to actually begin converting the
new `"modelConfiguration"` site config which was introduced in #63654
into the internal data types we use for model configuration.

This is all pretty straightforward / lame type conversion code, but
carefully written to preserve all the semantics we care about.

## Test plan

Written very carefully, and confirmed that this query:

```
curl -H "Authorization: token $(cat ~/local-token)" https://sourcegraph.test:3443/.api/modelconfig/supported-models.json
```

returns what I would expect with this site configuration:

<details>
<summary>site config</summary>

```
  // Setting this field means we are opting into the new Cody model configuration system which is in beta.
  "modelConfiguration": {
    // Disable use of Sourcegraph's servers for model discovery
    "sourcegraph": null,

    // Configure the OpenAI-compatible API endpoints that Cody should use to provide
    // mistral and bigcode (starcoder) models.
    "providerOverrides": [
      {
        "displayName": "Mistral",
        "id": "mistral",
        "serverSideConfig": {
          "type": "openaicompatible",
          "endpoint": "...",
          "accessToken": "...",
        },
      },
      {
        "displayName": "Bigcode",
        "id": "bigcode",
        "serverSideConfig": {
          "type": "openaicompatible",
          "endpoint": "...",
          "accessToken": "...",
        },
      },
    ],

    // Configure which exact mistral and starcoder models we want available
    "modelOverridesRecommendedSettings": [
      "bigcode::v1::starcoder2-7b",
      "mistral::v1::mixtral-8x7b-instruct"
    ],

    // Configure which models Cody will use by default
    "defaultModels": {
      "chat": "mistral::v1::mixtral-8x7b-instruct",
      "fastChat": "mistral::v1::mixtral-8x7b-instruct",
      "codeCompletion": "bigcode::v1::starcoder2-7b",
    }
  }
```

</details>

We could certainly use more unit tests here to prevent potential future
regressions, I can add those in a future PR.

## Changelog

Has no effect on users unless they opt into the early-access
`"modelConfiguration"` site config feature.

---------

Signed-off-by: Stephen Gutekanst <stephen@sourcegraph.com>
Co-authored-by: Chris Smith <chrsmith@users.noreply.github.com>
2024-07-09 11:40:32 -07:00
Matthew Manela
814aceb46f
feat(search): Make search aware of perforce changelist id mapping (#63563)
https://linear.app/sourcegraph/issue/SPLF-116/perforce-searching-by-perforce-changelist-id

## Details
We have had requests from our customers using Perforce to be able to
search inside of a changelist id. For a commit sha we support doing this

```
context:global repo:^perforce-sgdev-org/rhia-depot-test$@345c17c` some text
```

But for perforce they want to do the same thing but with the change list
ids. Which would look like this

```
context:global repo:^perforce-sgdev-org/rhia-depot-test$@changelist/83732` some text
```

To support this, I am attempting to smartly detect when we should do a
DB round trip and look up the proper mapping. I built a simple heuristic
that is
1. Is perforce changelist mapping feature flag enabled
2. Is this a perforce repo?
3. Is the revision request a integer ?

This mapping is just a best effort, if it fails it just falls back on
current behavior.

We are doing with a syntax of `@changelist/CL_ID` instead of supporting
`@CL_ID` to future proof us. This lookup focuses on finding the mapping
in the DB but in the future we may want to pre-create these refs in the
db duing mapping of perforce CLs to git commits.

## Limitations
This works well in testing however, the repo name@changelist/rev we
return contains the sha

![image](https://github.com/sourcegraph/sourcegraph/assets/304410/a673b9bd-d11f-4b36-bd95-c21ab8a5c4af)


I investigated changing this but it would required a larger change in
resolving the stream results. While that would be nice to have, I
decided to keep this minimal for now and add that later if needed

## Test plan

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

## Changelog
- For perforce depots, support searching within a specific changelist by
specifying a ref like `context:global repo:^repo/name$@changelist/83854`
2024-07-09 14:01:05 -04:00
Robert Lin
64ebfca904
fix/client/dev: update proxy overwrite to respect authProviders (#63624)
Closes https://linear.app/sourcegraph/issue/CORE-213

The existing overwrite stripping `window.context.authProviders` sourced
from a proxied API down to only built-in providers makes it impossible
to reliably run `sg start web-standalone` against Sourcegraph.com (and
likely other Sourcegraph instances). The docstring says:

> Only username/password auth-provider provider is supported with the
standalone server.

However, you _can_ log in with other OAuth2 providers locally, so it
doesn't make sense to remove them from the context. This PR removes the
overwrite so that we can log in to Sourcegraph.com with a locally
running web app, and talk to Cody and all that good stuff.

## How to log in to OAuth providers with `sg start web-standalone`

IIRC what happens:

1. Click "Sign in" -> go to OAuth2 provider -> log in
2. OAuth2 provider issues callback to the Sourcegraph instance, telling
it that you logged in
3. OAuth2 provider redirects you to the instance to confirm your session
- for SAMS in dotcom:

```
https://sourcegraph.com/.auth/callback?code=sams_ac_...
```

This redirect will surface an error, like so:

> Authentication failed. Try signing in again (and clearing cookies for
the current site). The error was: state parameter did not match the
expected value (possible request forgery).

This happens because you get redirected to an absolute URL, which will
be `sourcegraph.com` (the upstream Sourcegraph instance), which won't
match the cookie you get issued (`sourcegraph.test`). We just need to
make sure it matches and send the code to the callback through our local
proxy:

```diff
- https://sourcegraph.com/.auth/callback?code=sams_ac_...
+ https://sourcegraph.test:3443/.auth/callback?code=sams_ac_...
```

And everything will work :) I confirmed this works for e.g. logging into
S2 with GitHub as well, using the callback issued by GitHub.

We cannot make this the default behaviour, because the redirect URL is
usually configured in the OAuth provider. An example GitHub OAuth
application configuration:


![image](https://github.com/sourcegraph/sourcegraph/assets/23356519/c437cec4-f4e3-4915-acd9-b2002a55ce24)

Note their guidance on valid values:
https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps#redirect-urls
- we must provide a single, absolute URL


This is very similar to the process used to log in to private Cloud
instances, e.g.
https://cloud-ops.sgdev.org/dashboard/environments/prod/instances/src-bd02273f6b90d1d1beee#log-in-to-the-instance-ui
(scroll to bottom of this section), which indicates we've thought about
similar cases before and found that this was the best way

## Test plan


https://www.loom.com/share/6cb3b3ca475b4b9392aa4b11938e76e6?sid=d99fcb59-4308-45c7-9f68-af9ac44c4e7e
2024-07-09 10:27:54 -07: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
William Bezuidenhout
767614bc68
chore(redis): set max active redis connections to 1000 (#63718)
When active client is 0, there is no limit to the amount of active
clients which can lead to Redis quickly reaching it's MaxClient (10000
by default)

For more context see [this slack
thread](https://sourcegraph.slack.com/archives/C05EMJM2SLR/p1720448507809479)

## Test plan
CI


## Changelog
* redis-pool: set max active clients to 1000
<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-09 18:21:51 +02:00
Michael Bahr
b28879a3e7
chore: reword headline from tokens to credentials (#63714)
Updates a headline to better reflect that we now use more than just
tokens.

## Test plan

Existing CI

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-07-09 15:48:56 +00:00