-
Notifications
You must be signed in to change notification settings - Fork 428
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
add user and password to uri if the uri does not contain user password #560
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
improve compatibility, make the change do impact less
@ShashankSinha252 passing both CI (FeatureBuild) and metrics test |
@ShashankSinha252 are there any more changes that should be made by me? |
Hello, @naughtyGitCat! Thank you for your contribution! We would love to send you some gifts. Please, contact us at community-team@percona.com with your mailing address, phone number (for delivery only) and T-shirt size. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @naughtyGitCat can I ask what you mean by exposing URL
in the original issue? In case we expose the full URL in logs it's a problem, but the solution you made probably won't help, because they're still in the URL variable. So it would be good to understand how do you expose URL?
exporter/exporter.go
Outdated
e.opts.EnableDiagnosticData = false | ||
e.opts.EnableDBStats = false | ||
e.opts.EnableCollStats = false | ||
e.opts.EnableTopMetrics = false | ||
e.opts.EnableReplicasetStatus = false | ||
e.opts.EnableIndexStats = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it related to the issue we are solving in this PR?
it would be good to write some logs here to show that we are disabling collectors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is a separate issue.
if we run the exporter to monitoring arbiter role instance. the exporter will be hung to stuck.
It seems I should make a separate issue and pr. if possible, i will learn how to separate commits from pr before this week ends
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @naughtyGitCat can I ask what you mean by
exposing URL
in the original issue? In case we expose the full URL in logs it's a problem, but the solution you made probably won't help, because they're still in the URL variable. So it would be good to understand how do you expose URL?
- my purpose is to try to expose the monitored instance url, the benefit is easily identifying the exporter instance target DB instance. a host maybe runs multi exporter instances to monitor multi different DB instances. currently, the exporter can not easily identify which DB it belongs to.
- by adding url, we can safely expose the url info, and hide the user pass info by the env value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to expose URL in mongodb_exporter logs/metrics or somehow else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to expose URL in mongodb_exporter logs/metrics or somehow else?
I want to expose the url in cmdline, which can be easily identified by ps
command, the log or metric need more works to fetch url info. hard to manipulate exporter instance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aha, ok, it makes sense
main.go
Outdated
log.Debugf("Prepending mongodb:// to the URI") | ||
// IF user@pass not contained in uri AND custom user and pass supplied in arguments | ||
// DO concat a new uri with user and pass arguments value | ||
if !strings.Contains(opts.URI, "@") && opts.User != "" && opts.Password != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be two separate ifs, in case we have data source value like username:password@host:port
without mongodb://
prefix this if will be skipped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in my modification, I removed possible exits mongodb://
prefix. and after the user password re parse logic, the prefix will be added back when this if
ends.
and, in username:password@host:port
without mongodb://
circumstances, this if
(aka my modifcation) will not be triggered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, and it changes current behavior and breaks backward compatibility, because before your changes we were prepending mongodb://
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, U are right, I will change it to achieve backward compatibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have taken a look on changes carefully,
in this pr,
I add two new arguments user
and password
.
for backward compatibility, the two new user
and password
arguments will be an empty string when not supplied, this if
clause will not be triggered.
only when using new user
and password
argument is supplied and there is no user and pass in origin URI. this if
will be triggered.
besides, if the user and password are both supplied in the origin URI and arguments(env or --user --pass), the exporter will take the URI one. (if
not triggered )
the user, pass value in URI will have more priority than arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we extract whole this logic and write a test so it will be clear what's wrong
the case which was working and won't work. username:password@host:port
should be converted to mongodb://username:password@host:port
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haven extracted logic, and write a test. 1cdf1a6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but the check is stucked by
ok github.com/percona/mongodb_exporter/internal/tu 0.097s
? github.com/percona/mongodb_exporter/internal/util [no test files]
FAIL
make: *** [Makefile:104: test-race] Error 1
This error seems unrelated to the code I've submitted.
I have split two arbiter-related commits to #607 and this pr will only contains user pass expose commits |
main_test.go
Outdated
t.Logf("Origin: %s", originalBareURI) | ||
t.Logf("Expect: %s", originalBareURI) | ||
t.Logf("Result: %s", newUri) | ||
if newUri != originalBareURI { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if newUri != originalBareURI { | |
if newUri != originalPrefixBareURI { |
This is the expected behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have reorgnized the test code, 24987e4
could you review it again, thanks
main_test.go
Outdated
origin: "127.0.0.1", | ||
newUser: "", | ||
newPassword: "", | ||
expect: "127.0.0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the expectation here is mongodb://127.0.0.1
, that's how it used to work
expect: "127.0.0.1", | |
expect: "mongodb://127.0.0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my mistake, have correct it both in main.go
and main_test.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it does need a mongod://
prefix in all situation, according to https://www.mongodb.com/docs/manual/reference/connection-string/
main.go
Outdated
// add back mongodb:// | ||
uri = "mongodb://" + uri |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's remove it, anyway we do it a few lines later
please fix linters |
@BupycHuk seems weird, the below check
have no relation with my change, and some of the checks seem to randomly pass and failed and the check function |
Yeah, tests are unstable lately and we are working on it |
failed with: |
ci and lint check rules look like teetering |
main_test.go
Outdated
@@ -16,6 +16,7 @@ | |||
package main | |||
|
|||
import ( | |||
"github.com/stretchr/testify/assert" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this import should be moved below as a separate block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you mean code orders like this
import (
"context"
"fmt"
"strings"
"testing"
"time"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"go.mongodb.org/mongo-driver/bson"
"github.com/percona/mongodb_exporter/internal/tu"
)
changed, years ago I did the same order like this, but when the Goland and gofmt auto changed dependency order, I thought the auto reordered was more go-style.
Once all checks pass and the code is ready for review, please add
pmm-review-exporters
team as the reviewer. That would assign people from the review team automatically. Report any issues on our Forum or Discord.