From 030d6bd4c085ea8d1dc4e94ce4d5e69736df9114 Mon Sep 17 00:00:00 2001 From: Jonathan Amsterdam Date: Wed, 24 Mar 2021 19:21:20 -0400 Subject: internal/database: wrap OpenCensus sql driver The datbase/sql package provides a way to get at the underlying driver's connection. We will need that feature to access pgx's fast CopyFrom method. Unfortunately, we do not use the pgx driver directly. Instead, we wrap it in an OpenCensus driver for tracing and metrics. And that OpenCensus driver's connection does not allow us to dig into _it_ to retrieve the pgx connection that it wraps. Hence this dance: we must write our own driver and connection implementations. The driver return the connection, and the connection holds both the underlying (pgx) connection and the OpenCensus connection, to which it delegates. This CL is a no-op; everything behaves as before. But it lays the groundwork for a subsequent CL that will use pgx's CopyFrom. Change-Id: I5bf308aa23f07f20d1f6410ebb04cd6b9a5e0922 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/304630 Trust: Jonathan Amsterdam Run-TryBot: Jonathan Amsterdam TryBot-Result: kokoro Reviewed-by: Julie Qiu --- cmd/internal/cmdconfig/cmdconfig.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cmd') diff --git a/cmd/internal/cmdconfig/cmdconfig.go b/cmd/internal/cmdconfig/cmdconfig.go index e9d915b6..9600f925 100644 --- a/cmd/internal/cmdconfig/cmdconfig.go +++ b/cmd/internal/cmdconfig/cmdconfig.go @@ -98,8 +98,8 @@ func ExperimentGetter(ctx context.Context, cfg *config.Config) middleware.Experi func OpenDB(ctx context.Context, cfg *config.Config, bypassLicenseCheck bool) (_ *postgres.DB, err error) { defer derrors.Wrap(&err, "cmdconfig.OpenDB(ctx, cfg)") - // Wrap the postgres driver with OpenCensus instrumentation. - ocDriver, err := ocsql.Register(cfg.DBDriver, ocsql.WithAllTraceOptions()) + // Wrap the postgres driver with our own wrapper, which adds OpenCensus instrumentation. + ocDriver, err := database.RegisterOCWrapper(cfg.DBDriver, ocsql.WithAllTraceOptions()) if err != nil { return nil, fmt.Errorf("unable to register the ocsql driver: %v", err) } -- cgit v1.3