Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions service/submitqueue/core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 29 additions & 0 deletions service/submitqueue/core/dsn.go
Original file line number Diff line number Diff line change
@@ -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
}
41 changes: 41 additions & 0 deletions service/submitqueue/core/dsn_test.go
Original file line number Diff line number Diff line change
@@ -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")
})
}
}
4 changes: 2 additions & 2 deletions service/submitqueue/gateway/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion service/submitqueue/orchestrator/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading