Skip to content

Commit

Permalink
PMM-13543 Fix socket path failure. (#969)
Browse files Browse the repository at this point in the history
* PMM-13543 Fix socket path failure.

* PMM-13543 Address golangci review.
  • Loading branch information
BupycHuk authored Nov 19, 2024
1 parent 3252dcf commit de9f4b3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions exporter/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ func OverallTargetsHandler(exporters []*Exporter, logger *logrus.Logger) http.Ha
registry.MustRegister(gc)
}

hostlabels := prometheus.Labels{
"instance": e.opts.NodeName,
hostlabels := prometheus.Labels{}
if e.opts.NodeName != "" {
hostlabels["instance"] = e.opts.NodeName
}

gw := NewGathererWrapper(registry, hostlabels)
Expand Down
11 changes: 7 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,17 @@ func main() {
}

func buildExporter(opts GlobalFlags, uri string, log *logrus.Logger) *exporter.Exporter {
uri = buildURI(uri, opts.User, opts.Password, log)
uri = buildURI(uri, opts.User, opts.Password)
log.Debugf("Connection URI: %s", uri)

uriParsed, _ := url.Parse(uri)
var nodeName string
if uriParsed.Port() != "" {
switch {
case uriParsed == nil:
nodeName = ""
case uriParsed.Port() != "":
nodeName = net.JoinHostPort(uriParsed.Hostname(), uriParsed.Port())
} else {
default:
nodeName = uriParsed.Host
}

Expand Down Expand Up @@ -295,7 +298,7 @@ func buildURIManually(uri string, user string, password string) string {
return uri
}

func buildURI(uri string, user string, password string, log *logrus.Logger) string {
func buildURI(uri string, user string, password string) string {
defaultPrefix := "mongodb://" // default prefix

if !strings.HasPrefix(uri, defaultPrefix) && !strings.HasPrefix(uri, "mongodb+srv://") {
Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func TestBuildURI(t *testing.T) {
}
for _, tc := range tests {
t.Run(tc.situation, func(t *testing.T) {
newURI := buildURI(tc.origin, tc.newUser, tc.newPassword, logrus.New())
newURI := buildURI(tc.origin, tc.newUser, tc.newPassword)
assert.Equal(t, tc.expect, newURI)
})
}
Expand Down

0 comments on commit de9f4b3

Please sign in to comment.