Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
msp/runtime: add OpenTelemetry, make submodule (#58518)
Browse files Browse the repository at this point in the history
This change:

1. Renames `lib/managedservicesplatform/service` to `lib/managedservicesplatform/runtime` - I've been referring to it as runtime, and we use the word "service" a lot already, so this makes it easier to refer to and is more descriptive.
2. Makes everything under `lib/managedservicesplatform` a separate submodule from `lib` - the MSP runtime contributes a lot of dependencies to `lib`, and I don't think we should keep bloating `lib` to add more functionality to MSP.
3. Adds OpenTelemetry tracing and metrics configuration similar to the setup used by Cody Gateway and Telemetry Gateway
  • Loading branch information
bobheadxi authored and vovakulikov committed Dec 12, 2023
1 parent 78b773f commit aa2c060
Show file tree
Hide file tree
Showing 25 changed files with 978 additions and 199 deletions.
2 changes: 1 addition & 1 deletion cmd/msp-example/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ go_library(
visibility = ["//visibility:private"],
deps = [
"//cmd/msp-example/internal/example",
"//lib/managedservicesplatform/service",
"//lib/managedservicesplatform/runtime",
],
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/msp-example/internal/example/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ go_library(
deps = [
"//lib/background",
"//lib/errors",
"//lib/managedservicesplatform/service",
"//lib/managedservicesplatform/runtime",
"@com_github_sourcegraph_log//:log",
"@io_gorm_driver_postgres//:postgres",
"@io_gorm_gorm//:gorm",
Expand Down
10 changes: 5 additions & 5 deletions cmd/msp-example/internal/example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ import (

"github.com/sourcegraph/sourcegraph/lib/background"
"github.com/sourcegraph/sourcegraph/lib/errors"
"github.com/sourcegraph/sourcegraph/lib/managedservicesplatform/service"
"github.com/sourcegraph/sourcegraph/lib/managedservicesplatform/runtime"
)

type Config struct {
StatelessMode bool
Variable string
}

func (c *Config) Load(env *service.Env) {
func (c *Config) Load(env *runtime.Env) {
c.StatelessMode = env.GetBool("STATELESS_MODE", "false", "if true, disable dependencies")
c.Variable = env.Get("VARIABLE", "13", "variable value")
}

type Service struct{}

var _ service.Service[Config] = Service{}
var _ runtime.Service[Config] = Service{}

func (s Service) Name() string { return "example" }
func (s Service) Version() string { return "dev" }
func (s Service) Initialize(
ctx context.Context,
logger log.Logger,
contract service.Contract,
contract runtime.Contract,
config Config,
) (background.CombinedRoutine, error) {
logger.Info("starting service")
Expand Down Expand Up @@ -83,7 +83,7 @@ func (s *httpRoutine) Stop() {
// initDB connects to a database 'primary' based on a DSN provided by contract.
// It then sets up a few example databases using Gorm, in a manner similar to
// https://github.com/sourcegraph/accounts.sourcegraph.com
func initDB(ctx context.Context, contract service.Contract) error {
func initDB(ctx context.Context, contract runtime.Contract) error {
sqlDB, err := contract.GetPostgreSQLDB(ctx, "primary")
if err != nil {
return errors.Wrap(err, "GetPostgreSQLDB")
Expand Down
4 changes: 2 additions & 2 deletions cmd/msp-example/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main

import (
"github.com/sourcegraph/sourcegraph/lib/managedservicesplatform/service"
"github.com/sourcegraph/sourcegraph/lib/managedservicesplatform/runtime"

"github.com/sourcegraph/sourcegraph/cmd/msp-example/internal/example"
)

func main() {
service.Run[example.Config](example.Service{})
runtime.Start[example.Config](example.Service{})
}
18 changes: 9 additions & 9 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2261,8 +2261,8 @@ def go_dependencies():
name = "com_github_go_logr_logr",
build_file_proto_mode = "disable_global",
importpath = "github.com/go-logr/logr",
sum = "h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=",
version = "v1.2.4",
sum = "h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=",
version = "v1.3.0",
)
go_repository(
name = "com_github_go_logr_stdr",
Expand Down Expand Up @@ -3013,8 +3013,8 @@ def go_dependencies():
name = "com_github_googlecloudplatform_opentelemetry_operations_go_detectors_gcp",
build_file_proto_mode = "disable_global",
importpath = "github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp",
sum = "h1:/o9L4jKKshKO6U4q6e5oo0SkVtF5DDNLGK+liqsDt+w=",
version = "v1.16.1",
sum = "h1:tk85AYGwOf6VNtoOQi8w/kVDi2vmPxp3/OU2FsUpdcA=",
version = "v1.20.0",
)
go_repository(
name = "com_github_googlecloudplatform_opentelemetry_operations_go_exporter_metric",
Expand Down Expand Up @@ -3251,7 +3251,7 @@ def go_dependencies():
build_file_proto_mode = "disable_global",
importpath = "github.com/grpc-ecosystem/grpc-gateway/v2",
patch_args = ["-p1"],
patches = ["//third_party/com_github_grpc_ecosystem_grpc_gateway_v2:grpc_gateway.patch"],
# patches = ["//third_party/com_github_grpc_ecosystem_grpc_gateway_v2:grpc_gateway.patch"],
sum = "h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms=",
version = "v2.16.0",
)
Expand Down Expand Up @@ -5347,8 +5347,8 @@ def go_dependencies():
name = "com_github_prometheus_client_model",
build_file_proto_mode = "disable_global",
importpath = "github.com/prometheus/client_model",
sum = "h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY=",
version = "v0.4.0",
sum = "h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=",
version = "v0.5.0",
)
go_repository(
name = "com_github_prometheus_common",
Expand Down Expand Up @@ -5383,8 +5383,8 @@ def go_dependencies():
name = "com_github_prometheus_procfs",
build_file_proto_mode = "disable_global",
importpath = "github.com/prometheus/procfs",
sum = "h1:5EAgkfkMl659uZPbe9AS2N68a7Cc1TJbPEuGzFuRbyk=",
version = "v0.11.0",
sum = "h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI=",
version = "v0.11.1",
)
go_repository(
name = "com_github_prometheus_prometheus",
Expand Down
6 changes: 6 additions & 0 deletions doc/dependency_decisions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -564,3 +564,9 @@
:why:
:versions: []
:when: 2023-09-06 22:04:27.722891000 Z
- - :ignore
- "./lib/managedservicesplatform"
- :who:
:why: Internal module
:versions: []
:when: 2023-09-23 22:04:27.722891000 Z
16 changes: 11 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ replace (
// We publish 'lib' as a package for import in other tooling.
// When developing Sourcegraph itself, this replace uses the local package instead of a pushed version.
github.com/sourcegraph/sourcegraph/lib => ./lib
// We publish 'lib/managedservicesplatform' as a sub-package for import
// private services developed in other repositories, and to avoid bloating
// the more lightweight 'lib' package.
// When developing Sourcegraph itself, this replace uses the local package instead of a pushed version.
github.com/sourcegraph/sourcegraph/lib/managedservicesplatform => ./lib/managedservicesplatform
// We publish 'monitoring' as a package for import in other tooling.
// When developing Sourcegraph itself, this replace uses the local package instead of a pushed version.
github.com/sourcegraph/sourcegraph/monitoring => ./monitoring
Expand Down Expand Up @@ -182,7 +187,7 @@ require (
github.com/sourcegraph/run v0.12.0
github.com/sourcegraph/scip v0.3.1-0.20230627154934-45df7f6d33fc
github.com/sourcegraph/sourcegraph/dev/ci/images v0.0.0-20220203145655-4d2a39d3038a
github.com/sourcegraph/sourcegraph/lib v0.0.0-20230810200548-f8a32bcbd9e3
github.com/sourcegraph/sourcegraph/lib v0.0.0-20231122233253-1f857814717c
github.com/stretchr/testify v1.8.4
github.com/temoto/robotstxt v1.1.2
github.com/throttled/throttled/v2 v2.12.0
Expand Down Expand Up @@ -276,6 +281,7 @@ require (
github.com/sourcegraph/managed-services-platform-cdktf/gen/google v0.0.0-20230822024612-edb48c530722
github.com/sourcegraph/managed-services-platform-cdktf/gen/google_beta v0.0.0-20231106184355-f739cf8e1d49
github.com/sourcegraph/managed-services-platform-cdktf/gen/random v0.0.0-20230822024612-edb48c530722
github.com/sourcegraph/sourcegraph/lib/managedservicesplatform v0.0.0-00010101000000-000000000000
github.com/vektah/gqlparser/v2 v2.4.5
go.opentelemetry.io/collector/config/confighttp v0.81.0
go.opentelemetry.io/collector/config/configtelemetry v0.81.0
Expand All @@ -291,7 +297,7 @@ require (
cloud.google.com/go/trace v1.10.3 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.16.1 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.20.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.41.0 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
Expand Down Expand Up @@ -457,7 +463,7 @@ require (
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.2.4
github.com/go-logr/logr v1.3.0
github.com/go-logr/stdr v1.2.2
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.20.3 // indirect
Expand Down Expand Up @@ -547,9 +553,9 @@ require (
github.com/pkg/profile v1.6.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pquerna/cachecontrol v0.1.0 // indirect
github.com/prometheus/client_model v0.4.0
github.com/prometheus/client_model v0.5.0
github.com/prometheus/common/sigv4 v0.1.0 // indirect
github.com/prometheus/procfs v0.11.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/pseudomuto/protoc-gen-doc v1.5.1
github.com/pseudomuto/protokit v0.2.1 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DataDog/zstd v1.5.0 h1:+K/VEwIAaPcHiMtQvpLD4lqW7f0Gk3xdYZmI1hD+CXo=
github.com/DataDog/zstd v1.5.0/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.16.1 h1:/o9L4jKKshKO6U4q6e5oo0SkVtF5DDNLGK+liqsDt+w=
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.16.1/go.mod h1:Xx0VKh7GJ4si3rmElbh19Mejxz68ibWg/J30ZOMrqzU=
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.20.0 h1:tk85AYGwOf6VNtoOQi8w/kVDi2vmPxp3/OU2FsUpdcA=
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.20.0/go.mod h1:Xx0VKh7GJ4si3rmElbh19Mejxz68ibWg/J30ZOMrqzU=
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.41.0 h1:VahL5SjDdCas8mMKARolw2vvBsuLc5oV7XNSbxeMQP8=
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.41.0/go.mod h1:T8qLlq6KznHWwp8FEbfw+p7mX/+dezSvUy3PXfTnp4c=
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.17.0 h1:DwGeS/9k9xdpnvVQuJF+L9bYNFvBCmCWlDA8d8opoZY=
Expand Down Expand Up @@ -572,8 +572,8 @@ github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
Expand Down Expand Up @@ -1470,8 +1470,8 @@ github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY=
github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
github.com/prometheus/common v0.32.1 h1:hWIdL3N2HoUx3B8j3YN9mWor0qhY/NlEKZEaXxuIRh4=
github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls=
github.com/prometheus/common/sigv4 v0.1.0 h1:qoVebwtwwEhS85Czm2dSROY5fTo2PAPEVdDeppTwGX4=
Expand All @@ -1481,8 +1481,8 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ=
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/prometheus/procfs v0.11.0 h1:5EAgkfkMl659uZPbe9AS2N68a7Cc1TJbPEuGzFuRbyk=
github.com/prometheus/procfs v0.11.0/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI=
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
github.com/prometheus/prometheus v0.40.5 h1:wmk5yNrQlkQ2OvZucMhUB4k78AVfG34szb1UtopS8Vc=
github.com/prometheus/prometheus v0.40.5/go.mod h1:bxgdmtoSNLmmIVPGmeTJ3OiP67VmuY4yalE4ZP6L/j8=
github.com/prometheus/statsd_exporter v0.22.7 h1:7Pji/i2GuhK6Lu7DHrtTkFmNBCudCPT1pX2CziuyQR0=
Expand Down
21 changes: 6 additions & 15 deletions lib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/sourcegraph/sourcegraph/lib
go 1.19

require (
cloud.google.com/go/cloudsqlconn v1.5.1
github.com/Masterminds/semver v1.5.0
github.com/charmbracelet/glamour v0.5.0
github.com/cockroachdb/errors v1.11.1
Expand All @@ -17,7 +16,6 @@ require (
github.com/grafana/regexp v0.0.0-20221123153739-15dc172cd2db
github.com/hexops/autogold/v2 v2.0.3
github.com/jackc/pgconn v1.14.0
github.com/jackc/pgx/v5 v5.5.0
github.com/json-iterator/go v1.1.12
github.com/klauspost/pgzip v1.2.5
github.com/mattn/go-isatty v0.0.18
Expand All @@ -30,7 +28,7 @@ require (
github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf
github.com/sourcegraph/log v0.0.0-20231018134238-fbadff7458bb
github.com/sourcegraph/scip v0.3.1-0.20230627154934-45df7f6d33fc
github.com/stretchr/testify v1.8.2
github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.23.7
github.com/xeipuuv/gojsonschema v1.2.0
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53
Expand All @@ -43,8 +41,11 @@ require (
)

require (
cloud.google.com/go/compute v1.23.2 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
)

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
Expand All @@ -68,10 +69,7 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/hexops/valast v1.4.3 // indirect
Expand All @@ -83,7 +81,6 @@ require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.2 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jdxcode/netrc v0.0.0-20210204082910-926c7f70242a // indirect
github.com/jhump/protocompile v0.0.0-20220216033700-d705409f108f // indirect
github.com/jhump/protoreflect v1.12.1-0.20220417024638-438db461d753 // indirect
Expand Down Expand Up @@ -125,16 +122,10 @@ require (
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/oauth2 v0.14.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.4.0 // indirect
golang.org/x/tools v0.10.0 // indirect
google.golang.org/api v0.150.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20231030173426-d783a09b4405 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/grpc v1.59.0 // indirect
gotest.tools/v3 v3.0.3 // indirect
mvdan.cc/gofumpt v0.4.0 // indirect
Expand Down
Loading

0 comments on commit aa2c060

Please sign in to comment.