Commit Graph

46 Commits

Author SHA1 Message Date
Noah S-C
9b6ba7741e
bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
Keegan Carruthers-Smith
331368375b
search: support draining Zoekt instances (#62005)
This PR implements support for draining a zoekt replica via including its hostname in the comma-separated environment variable INDEXED_SEARCH_DRAIN_SERVERS on sourcegraph-frontend.

The way this functionality is implemented is via adjusting the endpoint map we use when making assignment of repos. We still report the hostname as part of the list of endpoints. However, the endpoint is left out of the consistent hash which maps the repositories to endpoints.

Our interactions with zoekt are already designed to do smooth rebalancing when the set of endpoints changes. We have logic to only remove repos from a replica once its new endpoint has it, and we support deduplication of search results across endpoints.

Co-authored-by: Stefan Hengl <stefan@sourcegraph.com>
2024-04-18 15:40:54 +02:00
Petri-Johan Last
0b5e7fd490
Replace all traditional for-loops (#60988) 2024-03-11 16:05:47 +02:00
William Bezuidenhout
1ae6cc6bfd
logger: update log lib and remove use of description (#57690)
* log: remove use of description paramter in Scoped

* temporarily point to sglog branch

* bazel configure + gazelle

* remove additional use of description param

* use latest versions of zoekt,log,mountinfo

* go.mod
2023-10-18 17:29:08 +02:00
Milan Freml
c31e079b5b
[chore] Refactored to use common pointers helper functions (#53441)
Originally I started working on this because of
[comment on another
PR](https://github.com/sourcegraph/sourcegraph/pull/53373#discussion_r1228058455).
I quickly wrote an implementation of Ptr and NonZeroPtr. Then I started
refactoring existing code only to find out that @efritz already beat me
to it. But Erics implementation was hidden in
internal/codeintel/resolvers/utils.go

Moved all of the Ptr functions to `pointers` package instead and
refactored all existing code that I could find to use it instead of
redefining the same functions all the time.

Usage is mostly in tests, so hopefully the impact is not as huge as the
diff size might suggest.



## Test plan

A whole lot of unit tests.
2023-06-14 16:48:44 +02:00
Jean-Hadrien Chabran
3d36d34b3d
ci: re-enable race detection (#52776)
The previous approach to enable race detection was too radical and
accidently led to build our binaries with the race flage enabled, which
caused issues when building images down the line.

This happened because putting a `test --something` in bazelrc also sets
it on `build` which is absolutely not what we wanted. Usually folks get
this one working by having a `--stamp` config setting that fixes this
when releasing binaries, which we don't at this stage, as we're still
learning Bazel.

Luckily, this was caught swiftly. The current approach insteads takes a
more granular approach, which makes the `go_test` rule uses our own
variant, which injects the `race = "on"` attribute, but only on
`go_test`.


## Test plan

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

CI, being a main-dry-run, this will cover the container building jobs,
which were the ones failing.

---------

Co-authored-by: Alex Ostrikov <alex.ostrikov@sourcegraph.com>
2023-06-05 20:41:47 +02:00
Dave Try
2b8fa079f0
bazel: fix buf files (#49444)
fix protoc-gen-go version
2023-03-15 20:21:38 +00:00
Dave Try
293385d5dd
bazel: update timeouts to suppress warnings (#49399)
Updates all of the BUILD fields with timeouts to suppress warnings and
reduce log spam.


## Test plan

Green CI
2023-03-15 15:04:16 +02:00
Jean-Hadrien Chabran
bc5490c4bb
bazel: introduce build files for Go (#46770) 2023-01-23 14:00:01 +01:00
Keegan Carruthers-Smith
1212512844
endpoint: allow empty Maps to disable Zoekt (#46280)
The only service discovery we support is via k8s. We want to ensure that
is working, so we have the invariant that if its empty we make all Map
lookups fail. However, this means that even if we explicitly wanted an
empty Map those would also fail (once communicated via config's
ServiceConnections).

This moves the enforcement of the invariant from the discovery loop to
just the k8s discovery code. Now our ServiceConnections based discovery
can return an empty list.

Additionally this allows us to simplify the condition around how we take
discovered endpoints/errors and update the map. This is because in all
functions on Map if err is non-nil we return the error.

This commit also allows an empty value for zoekt address. Explicitly setting
an empty value disables zoekt.

Test Plan: go test and manual testing with zoekt disabled.
2023-01-11 10:32:58 +02:00
Dave Try
b7023d7720
endpoint: migrate to sg/log (#45369)
* migrate to sg/log

* Update internal/endpoint/k8s.go

Co-authored-by: William Bezuidenhout <william.bezuidenhout@sourcegraph.com>

* Update internal/endpoint/k8s.go

Co-authored-by: William Bezuidenhout <william.bezuidenhout@sourcegraph.com>

* fix top and child scope

* fix frontend call to new endpont

* fix backticks

* fix symbols

* refactor

* last fixes after feedback

* white space

* fix var assignment

* refactor new

* Revert "endpoint: migrate to sg/log (#45210)"

This reverts commit ab82c6ab1e.

Co-authored-by: William Bezuidenhout <william.bezuidenhout@sourcegraph.com>
2022-12-07 19:27:22 +00:00
Dave Try
ab82c6ab1e
endpoint: migrate to sg/log (#45210)
* migrate to sg/log

* Update internal/endpoint/k8s.go

Co-authored-by: William Bezuidenhout <william.bezuidenhout@sourcegraph.com>

* Update internal/endpoint/k8s.go

Co-authored-by: William Bezuidenhout <william.bezuidenhout@sourcegraph.com>

* fix top and child scope

* fix frontend call to new endpont

* fix backticks

* fix symbols

* refactor

* last fixes after feedback

* white space

* fix var assignment

Co-authored-by: William Bezuidenhout <william.bezuidenhout@sourcegraph.com>
2022-12-07 11:35:15 -05:00
Keegan Carruthers-Smith
d41f4209d6
endpoint: only support rendezvous hashing (#43528)
Additionally we remove a bunch of benchmarking code which existed in
validating this was the best hash for us to use. This will also remove
some log spam about which hash we are using.

Test Plan: CI
2022-10-27 09:17:42 +00:00
Erik Seliger
179409b297
service discovery: make zoekt and searcher available outside of frontend (#43309)
Co-authored-by: Thorsten Ball <mrnugget@gmail.com>
2022-10-26 18:05:02 +02:00
Keegan Carruthers-Smith
27569d1fc7
all: run gofmt -s -w from 1.19 (#41629)
gofmt in go1.19 does a lot of reformating of godoc strings, mostly to
make them more consistent around lists.

Test Plan: CI
2022-09-13 07:44:06 +00:00
Keegan Carruthers-Smith
18f487ccaa
all: use any instead of interface{} (#35102)
Now that we require go1.18, we can use a builtin type alias for
"interface{}": "any". I've updated all code except lib, which can be
imported by external modules. That is currently pinned at go1.16.
Additionally I had to rerun generate since rewriting generated go code
will fail CI.

  find -name '*.go' | xargs gofmt -s -r 'interface{} -> any' -w
  git checkout lib
  go generate ./...

Test Plan: CI will exercise that the code still compiles. Otherwise this
is a noop.
2022-05-09 10:59:39 +02:00
Keegan Carruthers-Smith
ee0c70114f
endpoint: recover from errors in discovery (#31225)
If an error is returned by discovery we never recover from it. Currently
a customer is working around this by restarting our frontend. This can
happen frequently at smaller scales if a roll out temporary takes down
all endpoints in a service.

Test Plan: Added a unit test which exercised the bug. The test failed
until the fix.
2022-02-16 14:32:46 +00:00
Eric Fritz
7148009913
errors: Introduce internal package (#30558) 2022-02-07 15:03:45 +00:00
Keegan Carruthers-Smith
f8789cc74a
endpoint: add tests for k8s endpoint creation (#25151)
This tests the important bit which takes a k8s resource objects and
generates the list of endpoints.
2021-09-21 16:27:47 +02:00
Keegan Carruthers-Smith
7c4a7572ce
endpoint: use serviceName when constructing StatefulSet pod names (#25146)
We incorrectly assumed the serviceName was always the same as the
StatefulSet name. We now correctly construct the pod name as described
by the kubernetes documentation.
2021-09-21 10:12:55 +02:00
Ryan Slade
50505cea74
Add benchmarks for hashing functions (#24829) 2021-09-10 10:35:12 +02:00
Tomás Senart
f68632192a
endpoints: default to rendezvous hashing (#24190)
* endpoints: default to rendezvous hashing

Does what it says on the tin.

* fixup! fix test
2021-08-23 18:17:04 +02:00
Tomás Senart
bc3f7c54b1
endpoint: switch rendezvous hash func to xxhash (#24143)
* endpoint: switch rendezvous hash func to xxhash

* fixup! go mod tidy
2021-08-19 14:57:54 +00:00
Tomás Senart
e04a2b64c2
gitserver: discover endpoints dynamically in k8s (#24094)
* gitserver: discover endpoints dynamically in k8s

This commit makes it so GitServers in ServiceConnections are discovered
dynamically in Kubernetes clusters. We re-use the service discovery code
from the endpoint package, without leveraging the consistent hashing
part yet, which is for the time being still handled in gitserver client
(i.e. AddrForRepo).

* fixup! address feedback
2021-08-19 14:45:15 +00:00
Tomás Senart
b896fb50c6
endpoint: add rendezvous hashing support (#23921)
* endpoint: add rendezvous hashing support

This commit adds rendezvous hashing support to the endpoint package with
the aim to make it the default in a follow up PR. It's currently
protected by an environment variable which I plan to set on dogfood for
testing.

Additionally, it paves the way for increasing the replication factor by
adding a `GetN` method to map, which I used to replace the previous
`exclude` paramater to `Get` (used only by searcher). Actually raising
replication factor for Zoekt will come later.

Here is the output of the tests, which shows much better distribution,
and illustrates the data movement needed when changing hash function and
cluster sizes.

I think it's OK for us to shepherd this to prod next week and treat it like
and index version bump, and to write some release notes for customers to expect
some downtime in the next upgrade.

* fixup! Lint
2021-08-18 13:19:23 +02:00
Tomás Senart
2e119923e7 endpoint: better logging 2021-08-13 15:56:59 +02:00
Tomás Senart
9c8642bd8a endpoint: Better logging 2021-08-13 13:58:32 +02:00
Tomás Senart
3478f19d80
endpoints: improved k8s statefulset support now with ports (#23889)
* Revert "Revert "endpoint: improve k8s stateful set support (#23852)""

This reverts commit 7dc29e29db.

* endpoints: construct endpoint URL correctly

The last PR introduced a bug by not using u.endpointURL like before. So
we were missing port numbers and the service name in each endpoint.

Facepalm.

* Revert "Revert "endpoints: properly name the discovery function (#23883)""

This reverts commit acb5c1f728.
2021-08-13 12:27:38 +02:00
Tomás Senart
7dc29e29db Revert "endpoint: improve k8s stateful set support (#23852)"
This reverts commit 96b48182fd.
2021-08-13 11:48:00 +02:00
Tomás Senart
acb5c1f728 Revert "endpoints: properly name the discovery function (#23883)"
This reverts commit b52acce8f7.
2021-08-13 11:47:51 +02:00
Tomás Senart
b52acce8f7
endpoints: properly name the discovery function (#23883) 2021-08-13 09:00:33 +00:00
Tomás Senart
96b48182fd
endpoint: improve k8s stateful set support (#23852)
* endpoint: improve k8s stateful set support

This commit improves the k8s stateful set support by not using service
endpoints and instead generating a static list from the replica count.

It also refactors the package to isolate k8s things from the Map.

* fixup! Fix tests

* fixup! Lazy discovery

* fixup! Get rid of NotReadyAddresses
2021-08-13 10:19:19 +02:00
Tomás Senart
23928f5cd9
endpoint: include not ready k8s endpoints (#23760)
* endpoint: include not ready k8s endpoints

This commit adds support for including not ready kubernetes endpoints
discovered via the k8s api, which we need to avoid temporary reshuffling
of repo assignments to indexed search replicas.

* fixup! Fix test
2021-08-11 14:05:52 +02:00
Eric Fritz
abdf10d285
dx: Vet use of errors (#22704) 2021-07-12 19:51:38 +00:00
Indradhanush Gupta
a1075bf6b8
all: Replace github.com/pkg/errors with github.com/cockroachdb/errors (#21684)
In this commit, along with moving to
github.com/cockroachdb/errors, we update a few tests and some
error checks in non-test code.

List of files that have code changes apart from changes in the
error package import:

    enterprise/internal/batches/sources/gitlab.go
    enterprise/internal/batches/sources/gitlab_test.go
    internal/conf/client.go
    internal/store/store_test.go

Co-authored-by: ᴜɴᴋɴᴡᴏɴ <joe@sourcegraph.com>
2021-06-11 13:49:21 +05:30
Ryan Slade
ef76c4a285
chore: Deprecate usage of ioutil package (#21796)
The package was deprecated in Go 1.16:
https://golang.org/doc/go1.16#ioutil

A CI check was also added so that we don't import it again in the future.
2021-06-07 14:33:02 +02:00
Keegan Carruthers-Smith
e97462c866
endpoint: handle error from client.Watch (#19122)
This is the likely source of the panics we have been seeing in
production occasionally. Was accidently introduced in our switch to
client-go.
2021-03-15 20:26:45 +02:00
Dax McDonald
ac37bb2ab2
Switch to k8s client-go (#15486)
* Drop github.com/ericchiang/k8s for the official client

* Remove github.com/ericchiang/k8s from endpoints

* small fixes

* tests pass

* dependency update

* update ns func

* mod

* tidy

* pin dependency

* Update cmd/frontend/internal/app/debugproxies/scanner.go

Co-authored-by: Keegan Carruthers-Smith <keegan.csmith@gmail.com>

* Update cmd/frontend/internal/app/debugproxies/scanner.go

Co-authored-by: Keegan Carruthers-Smith <keegan.csmith@gmail.com>

* comments

Co-authored-by: Keegan Carruthers-Smith <keegan.csmith@gmail.com>
Co-authored-by: Alex Russell-Saw <alexrussellsaw@gmail.com>
2021-02-12 11:41:15 +00:00
Keegan Carruthers-Smith
54a3283247
all: add keegancsmith to CODENOTIFY for many pkgs (#14241)
Random assortment of packages I am interested in being notified about.
2020-09-29 11:03:53 +02:00
Keegan Carruthers-Smith
c03c8d4758
endpoint: prom metric and debug logs for k8s service discovery (#12434) 2020-07-23 17:21:17 +02:00
Keegan Carruthers-Smith
73349c78bb
all: migrate to github.com/inconshreveable/log15 (#9245)
We currently use gopkg.in/inconshreveable/log15.v2, which points to
github.com/inconshreveable/log15. However, recently goimports started inserting
github.com domain instead of the gopkg.in domain. This also seems to be the
preferred import path based on the documentation / import paths in the log15.
2020-03-24 15:16:26 +02:00
Yohix
b43ca485e7
Fix typos across sourcegraph repo (#8847) 2020-03-07 07:51:26 +02:00
Keegan Carruthers-Smith
72c54b9b06
endpoint: Ignore empty Hostname from endpoints (#6330)
In production we are getting empty hostnames from the searcher endpoints. When
manually running `kubectl get endpoints -o json searcher` the `hostname` field
is not set. However, the k8s client library we are using may be marshalling
the field anyways for some reason. Either way this is causing searcher
unavailability in production.
2019-11-01 11:23:58 +02:00
Keegan Carruthers-Smith
e18b3d5d14
endpoint: Discover statefulset hostnames (#6295)
Pods in a stateful set have DNS addresses of the form podname.servicename. We
can discover this by inspecting the endpoints from the headless service. They
will have the Hostname field set on the endpoint address object. Note: only if
podname.servicename is a valid address will hostname be set.

Additionally we support `rpc://` scheme. When using the rpc scheme, we return
address strings instead (ie hostname:port). This is what our rpc package
expects.

This allows us to dynamically discover the pods in the indexed-search
statefulset. This will allow kubernetes administrators to scale the
indexed-search statefulset without needing to update the INDEXED_SEARCH_SERVERS
configuration. Note: This commit does not update the default for that yet.

In future we could use this for gitservers as well (more testing required
though, for example we don't want to use this if a gitserver has to be marked as
ready).
2019-11-01 06:22:20 +02:00
Keegan Carruthers-Smith
51df73d31e
endpoint: Introduce Static and GetMany function (#6142)
Static is the same behaviour as calling endpoint.New with space separated
arguments, but instead the type is lifted from parsing a string into a go
slice.

GetMany will be used by our horizontal sharding to more efficiently map the
set of repositories to shards.

Both changes are useful for the changes in zoekt horizontal sharding.
2019-10-22 13:04:27 +02:00
Nick Snyder
85fba22315
Rename pkg to internal (#5898)
* git mv pkg internal

* fix imports in Go files

find ./ -type f -name '*.go' -exec sed -i '' -e 's/sourcegraph\/pkg\//sourcegraph\/internal\//g' {} \;

* fix imports in scripts

find ./ -type f -name '*.sh' -exec sed -i '' -e 's/sourcegraph\/pkg\//sourcegraph\/internal\//g' {} \;

* fix launch.sh

* go fmt ./...

* fix CODEOWNERS
2019-10-07 15:36:41 -07:00