diff --git a/service/submitqueue/core/BUILD.bazel b/service/submitqueue/core/BUILD.bazel index 74d63f0fa..e8f14b040 100644 --- a/service/submitqueue/core/BUILD.bazel +++ b/service/submitqueue/core/BUILD.bazel @@ -2,20 +2,27 @@ load("@rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", - srcs = ["queuepause.go"], + srcs = [ + "dsn.go", + "queuepause.go", + ], importpath = "github.com/uber/submitqueue/service/submitqueue/core", visibility = ["//visibility:public"], deps = [ "//submitqueue/extension/queuepause:go_default_library", "//submitqueue/extension/queuepause/file:go_default_library", "//submitqueue/extension/queuepause/noop:go_default_library", + "@com_github_go_sql_driver_mysql//:go_default_library", "@org_uber_go_zap//:go_default_library", ], ) go_test( name = "go_default_test", - srcs = ["queuepause_test.go"], + srcs = [ + "dsn_test.go", + "queuepause_test.go", + ], embed = [":go_default_library"], deps = [ "//submitqueue/entity:go_default_library", diff --git a/service/submitqueue/core/dsn.go b/service/submitqueue/core/dsn.go new file mode 100644 index 000000000..80e67d72f --- /dev/null +++ b/service/submitqueue/core/dsn.go @@ -0,0 +1,29 @@ +// Copyright (c) 2026 Uber Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package core + +import ( + "github.com/go-sql-driver/mysql" +) + +// DescribeDSN returns the host and database of a MySQL DSN, omitting +// credentials and parameters. It returns "" when the DSN cannot be parsed. +func DescribeDSN(dsn string) string { + cfg, err := mysql.ParseDSN(dsn) + if err != nil { + return "" + } + return cfg.Addr + "/" + cfg.DBName +} diff --git a/service/submitqueue/core/dsn_test.go b/service/submitqueue/core/dsn_test.go new file mode 100644 index 000000000..3ccd7ab66 --- /dev/null +++ b/service/submitqueue/core/dsn_test.go @@ -0,0 +1,41 @@ +// Copyright (c) 2026 Uber Technologies, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package core + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestDescribeDSN(t *testing.T) { + tests := []struct { + name string + dsn string + want string + }{ + {name: "credentials and parameters omitted", dsn: "root:secret@tcp(h:3306)/db?parseTime=true", want: "h:3306/db"}, + {name: "no password", dsn: "root@tcp(h:3306)/db", want: "h:3306/db"}, + {name: "unparsable", dsn: "not a dsn", want: ""}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := DescribeDSN(tt.dsn) + assert.Equal(t, tt.want, got) + assert.NotContains(t, got, "root") + assert.NotContains(t, got, "secret") + }) + } +} diff --git a/service/submitqueue/gateway/server/main.go b/service/submitqueue/gateway/server/main.go index eca086794..20898fa3c 100644 --- a/service/submitqueue/gateway/server/main.go +++ b/service/submitqueue/gateway/server/main.go @@ -296,8 +296,8 @@ func run() error { defer mysqlQueue.Close() logger.Info("initialized dependencies", - zap.String("app_dsn", appDSN), - zap.String("queue_dsn", queueDSN), + zap.String("app_db", core.DescribeDSN(appDSN)), + zap.String("queue_db", core.DescribeDSN(queueDSN)), ) // Subscriber name for the log-topic consumer. It must be unique per running diff --git a/service/submitqueue/orchestrator/server/main.go b/service/submitqueue/orchestrator/server/main.go index 86474a0bf..d2d01d0e6 100644 --- a/service/submitqueue/orchestrator/server/main.go +++ b/service/submitqueue/orchestrator/server/main.go @@ -193,7 +193,7 @@ func run() error { } defer mysqlQueue.Close() - logger.Info("initialized queue", zap.String("dsn", queueDSN)) + logger.Info("initialized queue", zap.String("queue_db", core.DescribeDSN(queueDSN))) // Subscriber name for consumer group identity subscriberName := os.Getenv("HOSTNAME")