cmd,private,satellite: add application_name to metabase connections

Currently the metainfo/metabase DB connections are missing the proper
application_name in order to differentiate and filter queries on the DB
side for analytics.
Without it, it is very time-consuming to correlate processes and their load.

This change adds the "check" on DB connection init and passes the fallbacks
in all places to catch connection strings, that do not set it.

Change-Id: Iea5cea8658bc63778ff89038e5c1c352bf482cfd
This commit is contained in:
Stefan Benten 2022-02-20 22:29:41 +01:00
parent 0178a13743
commit 321bf26c85
No known key found for this signature in database
GPG Key ID: EF6B5218ACEF6057
13 changed files with 21 additions and 2 deletions

View File

@ -155,7 +155,7 @@ func Delete(ctx context.Context, log *zap.Logger, config Config) (err error) {
func findOrphanedSegments(ctx context.Context, log *zap.Logger, config Config) (_ []uuid.UUID, err error) {
defer mon.Task()(&ctx)(&err)
metabaseDB, err := metabase.Open(ctx, log.Named("metabase"), config.MetabaseDB, metabase.Config{})
metabaseDB, err := metabase.Open(ctx, log.Named("metabase"), config.MetabaseDB, metabase.Config{ApplicationName: "metabase-orphaned-segments"})
if err != nil {
return nil, errs.New("unable to connect %q: %w", config.MetabaseDB, err)
}

View File

@ -115,6 +115,7 @@ func test(t *testing.T, prepare func(t *testing.T, ctx *testcontext.Context, raw
require.NoError(t, err)
metabaseDB, err := satellitedbtest.CreateMetabaseDBOnTopOf(ctx, log, metabaseTempDB, metabase.Config{
ApplicationName: "satellite-test",
MinPartSize: 5 * memory.MiB,
MaxNumberOfParts: 10000,
})

View File

@ -59,7 +59,7 @@ func VerifyCommand(log *zap.Logger) *cobra.Command {
ctx, cancel := process.Ctx(cmd)
defer cancel()
mdb, err := metabase.Open(ctx, log.Named("mdb"), metabaseDB, metabase.Config{})
mdb, err := metabase.Open(ctx, log.Named("mdb"), metabaseDB, metabase.Config{ApplicationName: "metabase-verify"})
if err != nil {
return Error.Wrap(err)
}

View File

@ -39,6 +39,7 @@ func cmdAdminRun(cmd *cobra.Command, args []string) (err error) {
}()
metabaseDB, err := metabase.Open(ctx, log.Named("metabase"), runCfg.Config.Metainfo.DatabaseURL, metabase.Config{
ApplicationName: "satellite-admin",
MinPartSize: runCfg.Config.Metainfo.MinPartSize,
MaxNumberOfParts: runCfg.Config.Metainfo.MaxNumberOfParts,
})

View File

@ -45,6 +45,7 @@ func cmdAPIRun(cmd *cobra.Command, args []string) (err error) {
}()
metabaseDB, err := metabase.Open(ctx, log.Named("metabase"), runCfg.Config.Metainfo.DatabaseURL, metabase.Config{
ApplicationName: "satellite-api",
MinPartSize: runCfg.Config.Metainfo.MinPartSize,
MaxNumberOfParts: runCfg.Config.Metainfo.MaxNumberOfParts,
})

View File

@ -60,6 +60,7 @@ func cmdFetchPieces(cmd *cobra.Command, args []string) (err error) {
}()
metabaseDB, err := metabase.Open(ctx, log.Named("metabase"), runCfg.Metainfo.DatabaseURL, metabase.Config{
ApplicationName: "satellite-pieces-fetcher",
MinPartSize: runCfg.Config.Metainfo.MinPartSize,
MaxNumberOfParts: runCfg.Config.Metainfo.MaxNumberOfParts,
})

View File

@ -37,6 +37,7 @@ func cmdGCRun(cmd *cobra.Command, args []string) (err error) {
}()
metabaseDB, err := metabase.Open(ctx, log.Named("metabase"), runCfg.Metainfo.DatabaseURL, metabase.Config{
ApplicationName: "satellite-gc",
MinPartSize: runCfg.Config.Metainfo.MinPartSize,
MaxNumberOfParts: runCfg.Config.Metainfo.MaxNumberOfParts,
})

View File

@ -393,6 +393,7 @@ func cmdRun(cmd *cobra.Command, args []string) (err error) {
}()
metabaseDB, err := metabase.Open(ctx, log.Named("metabase"), runCfg.Metainfo.DatabaseURL, metabase.Config{
ApplicationName: "satellite-core",
MinPartSize: runCfg.Config.Metainfo.MinPartSize,
MaxNumberOfParts: runCfg.Config.Metainfo.MaxNumberOfParts,
})
@ -480,6 +481,7 @@ func cmdMigrationRun(cmd *cobra.Command, args []string) (err error) {
}
metabaseDB, err := metabase.Open(ctx, log.Named("metabase"), runCfg.Metainfo.DatabaseURL, metabase.Config{
ApplicationName: "satellite-migration",
MinPartSize: runCfg.Config.Metainfo.MinPartSize,
MaxNumberOfParts: runCfg.Config.Metainfo.MaxNumberOfParts,
})

View File

@ -40,6 +40,7 @@ func cmdRepairerRun(cmd *cobra.Command, args []string) (err error) {
}()
metabaseDB, err := metabase.Open(ctx, log.Named("metabase"), runCfg.Metainfo.DatabaseURL, metabase.Config{
ApplicationName: "satellite-repairer",
MinPartSize: runCfg.Config.Metainfo.MinPartSize,
MaxNumberOfParts: runCfg.Config.Metainfo.MaxNumberOfParts,
})

View File

@ -476,6 +476,7 @@ func (planet *Planet) newSatellite(ctx context.Context, prefix string, index int
}
metabaseDB, err := satellitedbtest.CreateMetabaseDB(context.TODO(), log.Named("metabase"), planet.config.Name, "M", index, databases.MetabaseDB, metabase.Config{
ApplicationName: "satellite-testplanet",
MinPartSize: config.Metainfo.MinPartSize,
MaxNumberOfParts: config.Metainfo.MaxNumberOfParts,
})

View File

@ -2740,6 +2740,7 @@ func TestCommitObject(t *testing.T) {
func TestCommitObjectWithIncorrectPartSize(t *testing.T) {
metabasetest.RunWithConfig(t, metabase.Config{
ApplicationName: "satellite-test",
MinPartSize: 5 * memory.MiB,
MaxNumberOfParts: 1000,
}, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
@ -3072,6 +3073,7 @@ func TestCommitObjectWithIncorrectPartSize(t *testing.T) {
func TestCommitObjectWithIncorrectAmountOfParts(t *testing.T) {
metabasetest.RunWithConfig(t, metabase.Config{
ApplicationName: "satellite-test",
MinPartSize: 5 * memory.MiB,
MaxNumberOfParts: 3,
}, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {

View File

@ -29,6 +29,7 @@ var (
// Config is a configuration struct for part validation.
type Config struct {
ApplicationName string
MinPartSize memory.Size
MaxNumberOfParts int
}
@ -63,6 +64,11 @@ func Open(ctx context.Context, log *zap.Logger, connstr string, config Config) (
return nil, Error.New("unsupported implementation: %s", connstr)
}
connstr, err = pgutil.CheckApplicationName(connstr, config.ApplicationName)
if err != nil {
return nil, Error.Wrap(err)
}
rawdb, err := tagsql.Open(ctx, driverName, connstr)
if err != nil {
return nil, Error.Wrap(err)

View File

@ -54,6 +54,7 @@ func Run(t *testing.T, fn func(ctx *testcontext.Context, t *testing.T, db *metab
)
RunWithConfig(t, metabase.Config{
ApplicationName: "satellite-test",
MinPartSize: config.MinPartSize,
MaxNumberOfParts: config.MaxNumberOfParts,
}, fn)
@ -67,6 +68,7 @@ func Bench(b *testing.B, fn func(ctx *testcontext.Context, b *testing.B, db *met
ctx := testcontext.New(b)
defer ctx.Cleanup()
db, err := satellitedbtest.CreateMetabaseDB(ctx, zaptest.NewLogger(b), b.Name(), "M", 0, dbinfo.MetabaseDB, metabase.Config{
ApplicationName: "satellite-bench",
MinPartSize: 5 * memory.MiB,
MaxNumberOfParts: 10000,
})