Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CORE-2238] Loki in testpachd fast-follow #9913

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
01b334b
add logs and proxy server
jrockway Mar 29, 2024
c0ef120
add MutateContext option to TestPachdOption
jrockway Mar 29, 2024
6b37e0c
add a TestPachdOption for logging to Loki
jrockway Mar 29, 2024
c531ee1
add -loki option to testpachd binary
jrockway Mar 29, 2024
73c5815
cleanup loki tmpdir
jrockway Mar 29, 2024
19ddc28
enable rpc logging; make sure testpachd binary's Run gets the loki co…
jrockway Mar 29, 2024
653b179
Merge branch 'master' into jonathan/core-2238-loki-in-testpachd
robert-uhl Apr 2, 2024
5b5ac2c
Unify context, wait on completion
robert-uhl Apr 3, 2024
de0c9a4
Handle verbosity
robert-uhl Apr 3, 2024
820a96c
Merge branch 'jonathan/core-2238-loki-in-testpachd' into rau/core-223…
robert-uhl Apr 3, 2024
eb2925c
Split log batching and cleaning
robert-uhl Apr 3, 2024
7fc1f43
Pull pachctl context restoration into its own function
robert-uhl Apr 3, 2024
fd7e870
Use Loki to log when building test pachd
robert-uhl Apr 3, 2024
969b2d8
Remove cleanup from main
robert-uhl Apr 3, 2024
08ee07f
Run testpachd in a goroutine
robert-uhl Apr 3, 2024
ebcae9c
Delint
robert-uhl Apr 3, 2024
182c7cd
Switch nontest dockertestenv PostgreSQL from cleanup
robert-uhl Apr 3, 2024
c820c29
Remove cleanup
robert-uhl Apr 3, 2024
0fc35f0
Gazelle
robert-uhl Apr 3, 2024
11530c9
Merge branch 'untangle-testpachd' into rau/core-2238-loki-in-testpachd
robert-uhl Apr 3, 2024
37b4b6f
Merge branch 'master' into jonathan/core-2238-loki-in-testpachd
robert-uhl Apr 3, 2024
e9ab0a8
Merge branch 'jonathan/core-2238-loki-in-testpachd' into rau/core-223…
robert-uhl Apr 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 0 additions & 26 deletions src/internal/cleanup/BUILD.bazel

This file was deleted.

56 changes: 0 additions & 56 deletions src/internal/cleanup/cleanup.go

This file was deleted.

52 changes: 0 additions & 52 deletions src/internal/cleanup/cleanup_test.go

This file was deleted.

1 change: 0 additions & 1 deletion src/internal/dockertestenv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ go_library(
visibility = ["//src:__subpackages__"],
deps = [
"//src/internal/backoff",
"//src/internal/cleanup",
"//src/internal/dbutil",
"//src/internal/errors",
"//src/internal/log",
Expand Down
88 changes: 51 additions & 37 deletions src/internal/dockertestenv/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

"github.com/pachyderm/pachyderm/v2/src/internal/backoff"
"github.com/pachyderm/pachyderm/v2/src/internal/cleanup"
"github.com/pachyderm/pachyderm/v2/src/internal/dbutil"
"github.com/pachyderm/pachyderm/v2/src/internal/errors"
"github.com/pachyderm/pachyderm/v2/src/internal/log"
Expand Down Expand Up @@ -124,16 +123,39 @@ func NewTestDBConfig(t testing.TB) DBConfig {
}

// NewTestDBConfigCtx returns a DBConfig for an environment outside of tests.
func NewTestDBConfigCtx(ctx context.Context) (config DBConfig, cleaner *cleanup.Cleaner, _ error) {
func NewTestDBConfigCtx(ctx context.Context) (DBConfig, error) {
var (
dbName = testutil.GenerateEphemeralDBName()
dexName = testutil.UniqueString("dex")
config = DBConfig{
Direct: PostgresConfig{
Host: postgresHost(),
Port: postgresPort,
User: DefaultPostgresUser,
Password: DefaultPostgresPassword,
DBName: dbName,
},
PGBouncer: PostgresConfig{
Host: PGBouncerHost(),
Port: PGBouncerPort,
User: DefaultPostgresUser,
Password: DefaultPostgresPassword,
DBName: dbName,
},
Identity: PostgresConfig{
Host: PGBouncerHost(),
Port: PGBouncerPort,
User: DefaultPostgresUser,
Password: DefaultPostgresPassword,
DBName: dexName,
},
}
)
cleaner = new(cleanup.Cleaner)

if err := backoff.Retry(func() error {
return EnsureDBEnv(ctx)
}, backoff.NewConstantBackOff(time.Second*3)); err != nil {
return config, cleaner, errors.Wrap(err, "wait for database to be created")
return config, errors.Wrap(err, "wait for database to be created")
}

db, err := dbutil.NewDB(
Expand All @@ -142,45 +164,37 @@ func NewTestDBConfigCtx(ctx context.Context) (config DBConfig, cleaner *cleanup.
dbutil.WithHostPort(PGBouncerHost(), PGBouncerPort),
dbutil.WithDBName(DefaultPostgresDatabase))
if err != nil {
return config, cleaner, errors.Wrap(err, "NewDB")
return config, errors.Wrap(err, "NewDB")
}
cleaner.AddCleanup("close db connection", db.Close)
defer db.Close()

if err := testutil.CreateEphemeralDBNontest(ctx, db, dbName); err != nil {
return config, cleaner, errors.Wrapf(err, "CreateEphemeralDB(%v)", dbName)
return config, errors.Wrapf(err, "CreateEphemeralDB(%v)", dbName)
}
cleaner.AddCleanupCtx("cleanup pach database", func(ctx context.Context) error {
return errors.Wrapf(testutil.CleanupEphemeralDB(ctx, db, dbName), "cleanup database %v", dbName)
})
if err := testutil.CreateEphemeralDBNontest(ctx, db, dexName); err != nil {
return config, cleaner, errors.Wrapf(err, "CreateEphemeralDB(%v)", dexName)
return config, errors.Wrapf(err, "CreateEphemeralDB(%v)", dexName)
}
cleaner.AddCleanupCtx("cleanup dex database", func(ctx context.Context) error {
return errors.Wrapf(testutil.CleanupEphemeralDB(ctx, db, dexName), "cleanup database %v", dbName)
})
return DBConfig{
Direct: PostgresConfig{
Host: postgresHost(),
Port: postgresPort,
User: DefaultPostgresUser,
Password: DefaultPostgresPassword,
DBName: dbName,
},
PGBouncer: PostgresConfig{
Host: PGBouncerHost(),
Port: PGBouncerPort,
User: DefaultPostgresUser,
Password: DefaultPostgresPassword,
DBName: dbName,
},
Identity: PostgresConfig{
Host: PGBouncerHost(),
Port: PGBouncerPort,
User: DefaultPostgresUser,
Password: DefaultPostgresPassword,
DBName: dexName,
},
}, cleaner, nil
return config, nil
}

func (config DBConfig) Cleanup(ctx context.Context) error {
db, err := dbutil.NewDB(
dbutil.WithMaxOpenConns(1),
dbutil.WithUserPassword(DefaultPostgresUser, DefaultPostgresPassword),
dbutil.WithHostPort(PGBouncerHost(), PGBouncerPort),
dbutil.WithDBName(DefaultPostgresDatabase))
for _, c := range []PostgresConfig{config.Direct, config.Identity} {
if err != nil {
log.Error(ctx, "opening", zap.String("db", c.DBName), zap.Error(err))
continue
}
if err := testutil.CleanupEphemeralDB(ctx, db, c.DBName); err != nil {
log.Error(ctx, "deleting", zap.String("db", c.DBName), zap.Error(err))
continue
}

}
return errors.Wrap(db.Close(), "closing database")
}

// NewTestDB creates a new database connection scoped to the test.
Expand Down
25 changes: 23 additions & 2 deletions src/internal/lokiutil/testloki/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
load("@rules_go//go:def.bzl", "go_library", "go_test")

# gazelle:go_test file

go_library(
name = "testloki",
testonly = 1,
srcs = ["testloki.go"],
srcs = [
"logger.go",
"testloki.go",
],
data = [
"config.yaml",
"//tools/loki",
Expand All @@ -14,10 +18,14 @@ go_library(
"//src/internal/errors",
"//src/internal/log",
"//src/internal/lokiutil/client",
"//src/internal/pachconfig",
"//src/internal/pachd",
"//src/internal/pctx",
"//src/internal/promutil",
"//src/internal/randutil",
"@in_gopkg_yaml_v3//:yaml_v3",
"@org_uber_go_zap//:zap",
"@org_uber_go_zap//zapcore",
"@rules_go//go/runfiles:go_default_library",
"@rules_go//go/tools/bazel:go_default_library",
],
Expand All @@ -34,3 +42,16 @@ go_test(
"@com_github_google_go_cmp//cmp",
],
)

go_test(
name = "logger_test",
size = "small",
srcs = ["logger_test.go"],
deps = [
":testloki",
"//src/internal/pachd",
"//src/internal/pctx",
"//src/logs",
"@org_golang_google_protobuf//encoding/protojson",
],
)