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

Log UNIX socket address w/o port number #542

Merged
merged 1 commit into from
Nov 9, 2022
Merged
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
5 changes: 2 additions & 3 deletions cmd/icingadb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/pkg/errors"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
"net"
"os"
"os/signal"
"sync"
Expand Down Expand Up @@ -64,7 +63,7 @@ func run() int {
}
defer db.Close()
{
logger.Infof("Connecting to database at '%s'", net.JoinHostPort(cmd.Config.Database.Host, fmt.Sprint(cmd.Config.Database.Port)))
logger.Infof("Connecting to database at '%s'", utils.JoinHostPort(cmd.Config.Database.Host, cmd.Config.Database.Port))
err := db.Ping()
if err != nil {
logger.Fatalf("%+v", errors.Wrap(err, "can't connect to database"))
Expand All @@ -80,7 +79,7 @@ func run() int {
logger.Fatalf("%+v", errors.Wrap(err, "can't create Redis client from config"))
}
{
logger.Infof("Connecting to Redis at '%s'", net.JoinHostPort(cmd.Config.Redis.Host, fmt.Sprint(cmd.Config.Redis.Port)))
logger.Infof("Connecting to Redis at '%s'", utils.JoinHostPort(cmd.Config.Redis.Host, cmd.Config.Redis.Port))
_, err := rc.Ping(context.Background()).Result()
if err != nil {
logger.Fatalf("%+v", errors.Wrap(err, "can't connect to Redis"))
Expand Down
10 changes: 10 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/pkg/errors"
"golang.org/x/exp/utf8string"
"math"
"net"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -206,3 +207,12 @@ func MaxInt(x, y int) int {

return y
}

// JoinHostPort is like its equivalent in net., but handles UNIX sockets as well.
func JoinHostPort(host string, port int) string {
if strings.HasPrefix(host, "/") {
return host
}

return net.JoinHostPort(host, fmt.Sprint(port))
}