Commit Graph

17 Commits

Author SHA1 Message Date
Joe Chen
2589fef13e
lib/background: upgrade Routine interface with context and errors (#62136)
This PR is a result/followup of the improvements we've made in the [SAMS repo](https://github.com/sourcegraph/sourcegraph-accounts/pull/199) that allows call sites to pass down a context (primarily to indicate deadline, and of course, cancellation if desired) and collects the error returned from `background.Routine`s `Stop` method.

Note that I did not adopt returning error from `Stop` method because I realize in monorepo, the more common (and arguably the desired) pattern is to hang on the call of `Start` method until `Stop` is called, so it is meaningless to collect errors from `Start` methods as return values anyway, and doing that would also complicate the design and semantics more than necessary.

All usages of the the `background.Routine` and `background.CombinedRoutines` are updated, I DID NOT try to interpret the code logic and make anything better other than fixing compile and test errors.

The only file that contains the core change is the [`lib/background/background.go`](https://github.com/sourcegraph/sourcegraph/pull/62136/files#diff-65c3228388620e91f8c22d91c18faac3f985fc67d64b08612df18fa7c04fafcd).
2024-05-24 10:04:55 -04:00
Noah S-C
9b6ba7741e
bazel: transcribe test ownership to bazel tags (#62664) 2024-05-16 15:51:16 +01:00
Robert Lin
f8ca00dd11
pubsub: add narrower TopicPublisher interface, ensure Stop in telemetry-gateway (#58974)
We currently don't call `Stop` on the pub/sub client, which is pretty important because I think it actually does buffering by default: https://sourcegraph.com/github.com/googleapis/google-cloud-go@6eb769621618a965abeabf11e6315bdb8be9b050/-/blob/pubsub/topic.go?L122-137

This change adds a `TopicPublisher` interface with write-only methods so that we don't accidentally Stop the client at callsites, and adds a Stop to telemetry-gateway. I'll follow up with another change to update Pings to the MSP runtime and apply a Stop there as well
2023-12-14 12:32:48 -08:00
Robert Lin
4b7dd27614
telemetry-gateway: add attributes to pubsub events (#58837)
This might make it easier to the team to work with the incoming data, and could be useful for some degree of tagging.
2023-12-07 15:18:45 -08: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
Robert Lin
9579bf120c
telemetry-gateway: copy range variable (#57237)
Co-authored-by: Joe Chen <joe@sourcegraph.com>
2023-10-02 10:54:28 -04:00
Robert Lin
c050dd75e9
pubsub: downgrade logging client to debug (#56928) 2023-09-22 10:25:28 -07:00
Robert Lin
e835a66c76
telemetrygateway: add exporter and service (#56699)
This change adds:

- telemetry export background jobs: flagged behind `TELEMETRY_GATEWAY_EXPORTER_EXPORT_ADDR`, default empty => disabled
- telemetry redaction: configured in package `internal/telemetry/sensitivemetadataallowlist`
- telemetry-gateway service receiving events and forwarding it to a pub/sub topic (or just logging it, as configured in local dev)
- utilities for easily creating an event recorder: `internal/telemetry/telemetryrecorder`
Notes:

- all changes are feature-flagged to some degree, off by default, so the merge should be fairly low-risk.
- we decided that transmitting the full license key continues to be the way to go. we transmit it once per stream and attach it on all events in the telemetry-gateway. there is no auth mechanism at the moment
- GraphQL return type `EventLog.Source` is now a plain string instead of string enum. This should not be a breaking change in our clients, but must be made so that our generated V2 events do not break requesting of event logs

Stacked on https://github.com/sourcegraph/sourcegraph/pull/56520

Closes https://github.com/sourcegraph/sourcegraph/issues/56289
Closes https://github.com/sourcegraph/sourcegraph/issues/56287

## Test plan

Add an override to make the export super frequent:

```
env:
  TELEMETRY_GATEWAY_EXPORTER_EXPORT_INTERVAL: "10s"
  TELEMETRY_GATEWAY_EXPORTER_EXPORTED_EVENTS_RETENTION: "5m"
```

Start sourcegraph:

```
sg start
```

Enable `telemetry-export` featureflag (from https://github.com/sourcegraph/sourcegraph/pull/56520)

Emit some events in GraphQL:

```gql
mutation {
  telemetry {
    recordEvents(events:[{
      feature:"foobar"
      action:"view"
      source:{
        client:"WEB"
      }
      parameters:{
        version:0
      }
    }]) {
      alwaysNil
    }
  }
```

See series of log events:

```
[         worker] INFO worker.telemetrygateway-exporter telemetrygatewayexporter/telemetrygatewayexporter.go:61 Telemetry Gateway export enabled - initializing background routines
[         worker] INFO worker.telemetrygateway-exporter telemetrygatewayexporter/exporter.go:99 exporting events {"maxBatchSize": 10000, "count": 1}
[telemetry-g...y] INFO telemetry-gateway.pubsub pubsub/topic.go:115 Publish {"TraceId": "7852903434f0d2f647d397ee83b4009b", "SpanId": "8d945234bccf319b", "message": "{\"event\":{\"id\":\"dc96ae84-4ac4-4760-968f-0a0307b8bb3d\",\"timestamp\":\"2023-09-19T01:57:13.590266Z\",\"feature\":\"foobar\", ....
```

Build:

```
export VERSION="insiders"
bazel run //cmd/telemetry-gateway:candidate_push --config darwin-docker --stamp --workspace_status_command=./dev/bazel_stamp_vars.sh -- --tag $VERSION --repository us.gcr.io/sourcegraph-dev/telemetry-gateway
```

Deploy: https://github.com/sourcegraph/managed-services/pull/7

Add override:

```yaml
env:
  # Port required. TODO: What's the best way to provide gRPC addresses, such that a
  # localhost address is also possible?
  TELEMETRY_GATEWAY_EXPORTER_EXPORT_ADDR: "https://telemetry-gateway.sgdev.org:443"
```

Repeat the above (`sg start` and emit some events):

```
[         worker] INFO worker.telemetrygateway-exporter telemetrygatewayexporter/exporter.go:94 exporting events {"maxBatchSize": 10000, "count": 6}
[         worker] INFO worker.telemetrygateway-exporter telemetrygatewayexporter/exporter.go:113 events exported {"maxBatchSize": 10000, "succeeded": 6}
[         worker] INFO worker.telemetrygateway-exporter telemetrygatewayexporter/exporter.go:94 exporting events {"maxBatchSize": 10000, "count": 1}
[         worker] INFO worker.telemetrygateway-exporter telemetrygatewayexporter/exporter.go:113 events exported {"maxBatchSize": 10000, "succeeded": 1}
```
2023-09-20 05:20:15 +00:00
Joe Chen
c4cef7a49d
updatecheck: make Pub/Sub client an argument instead of global var (#55536)
This PR refactors the `internal/updatecheck` package a bit so that the
global state to store the Pub/Sub client is removed (the result of the
preceding PR https://github.com/sourcegraph/sourcegraph/pull/55524), and
can be pass down to lower-level helper function as an argument.

This is necessary for
https://github.com/sourcegraph/sourcegraph/pull/55467 to hold a Pub/Sub
client on the call site in order to use `pubsub.TopicClient`'s helper
functions (i.e. `Ping`) while still being able to reuse most of the code
logic from the `internal/updatecheck` package.

## Test plan

CI
2023-08-03 13:30:29 -04:00
Joe Chen
60c1f0bb31
pubsub: refactoring the package to be modular (#55524)
This PR refactors the `internal/pubsub` package to be more modular and
other things:

1. Let the call sites make the decision of the client lifecycle.
- The fact that it looks like more global states are created is because
call sites that holding states need to be refactored as well, but out of
scope for the purpose of this PR.
1. Expose the client so more helpful methods can be made available.
- Here only the `Ping` method is added, which will later be used for
health-checking purpose.
1. We were creating a new "publish stream" for every single message we
publish, which is the "anti-pattern" based on the docstring of the
`Topic` method and my reading of its implementation:
![CleanShot 2023-08-02 at 10 28
56@2x](https://github.com/sourcegraph/sourcegraph/assets/2946214/46d4b2e5-61f5-4fad-878f-13c770fbe8df)
1. Also see inline review comments.

## Test plan

1. Request access to the GCP project telligentsourcegraph through
Entitle
1. Add the following to the `sg.config.overwrite.yaml`:
	```yaml
	commandsets:
	  dotcom:
	    env:
	      PUBSUB_PROJECT_ID: 'telligentsourcegraph'
PUBSUB_TOPIC_ID: 'server-update-checks-test' # for pings
PUBSUB_DOTCOM_EVENTS_TOPIC_ID: 'server-update-checks-test' # for event
logging
	```
1. Run `sg start dotcom`
1. For event logging
	- Pull the message and visit the https://sourcegraph.test:3443
<img width="1546" alt="CleanShot 2023-08-02 at 11 09 17@2x"
src="https://github.com/sourcegraph/sourcegraph/assets/2946214/a3c102b1-293b-4cc2-9c2c-028ac613fdf9">
1. For pings
- Pull the message and do `curl
https://sourcegraph.test:3443/.api/updates?site=df0eed23-0e8c-4721-9849-147d20d59911&version=6.0.1`
<img width="581" alt="CleanShot 2023-08-02 at 11 11 19@2x"
src="https://github.com/sourcegraph/sourcegraph/assets/2946214/185c24ab-2837-4090-8248-a701487c8dc0">
2023-08-02 12:22:29 -04:00
Jean-Hadrien Chabran
bc5490c4bb
bazel: introduce build files for Go (#46770) 2023-01-23 14:00:01 +01:00
Eric Fritz
7148009913
errors: Introduce internal package (#30558) 2022-02-07 15:03:45 +00:00
Eric Fritz
07a025836d
dx: Use cockroachdb/errors over stdlib errors (#22684) 2021-07-08 14:55:34 -05:00
Tomás Senart
568de455d0
pubsub: Use explicit credentials file (#16695)
Instead of relying on the global environment variable
GOOGLE_APPLICATION_CREDENTIALS, which is used by every Google Cloud
library.

Once we roll this out and remove the explicit
GOOGLE_APPLICATION_CREDENTIALS from deploy-sourcegraph-dot-com,
profiling should work.
2020-12-12 15:41:23 +01:00
Eric Fritz
6c27843425
chore: Cleanup packages (#13833) 2020-09-17 09:59:16 -05: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
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