sourcegraph/cmd
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
..
batcheshelper Move batcheshelper out of enterprise (#54923) 2023-07-13 19:46:09 +02:00
blobstore uploadstore: list with prefix (#56538) 2023-09-15 14:49:02 +02:00
bundled-executor Build bundled-executor with shell build tag again (#55792) 2023-08-11 21:39:32 +02:00
cody-gateway telemetrygateway: add exporter and service (#56699) 2023-09-20 05:20:15 +00:00
executor Move executor-kubernetes out of enterprise (#56449) 2023-09-08 16:24:05 +02:00
executor-kubernetes Move executor-kubernetes out of enterprise (#56449) 2023-09-08 16:24:05 +02:00
frontend telemetrygateway: add exporter and service (#56699) 2023-09-20 05:20:15 +00:00
github-proxy app: Move out of enterprise and merge with cmd/sourcegraph-oss (#56447) 2023-09-08 16:23:46 +02:00
gitserver Enable "Test connection" for Perforce code hosts (#56697) 2023-09-19 13:19:00 -07:00
loadtest bzl: set version on bins, not lib + add missing (#54030) 2023-06-23 14:06:58 +02:00
migrator release: sourcegraph@5.1.8 (#56405) 2023-09-06 14:33:43 -07:00
pings pings: pass down request context to Ping methods (#56731) 2023-09-19 17:38:38 +02:00
precise-code-intel-worker app: Move out of enterprise and merge with cmd/sourcegraph-oss (#56447) 2023-09-08 16:23:46 +02:00
repo-updater Remove GitHub proxy service (#56485) 2023-09-14 19:43:40 +02:00
searcher grpc: enable by default by inverting experimental feature flag (#56738) 2023-09-18 15:37:42 -07:00
server Remove GitHub proxy service (#56485) 2023-09-14 19:43:40 +02:00
sitemap Include the last sub-sitemap in the sitemap index (#56526) 2023-09-14 09:13:57 +09:00
sourcegraph update code references to "Sourcegraph App" -> "Cody App" (#56747) 2023-09-19 12:31:12 -10:00
symbols app: Move out of enterprise and merge with cmd/sourcegraph-oss (#56447) 2023-09-08 16:23:46 +02:00
telemetry-gateway telemetrygateway: add exporter and service (#56699) 2023-09-20 05:20:15 +00:00
worker globallimiter: Improve reliability (#56577) 2023-09-13 15:29:44 +02:00
README.md Reminder to keep architecture diagram in-sync (#36869) 2022-06-08 19:40:36 -07:00

This directory contains Sourcegraph services and binaries.

When a services is added, removed, or when a service's dependencies change, update our architecture diagram.