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

replSetGetConfigCollector #295

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

hiroshi
Copy link
Contributor

@hiroshi hiroshi commented Jun 12, 2021

Add replSetGetConfigCollector.
This is meant to resolve #292

It export metrics like this:

mongodb_cfg_members_priority{cl_id="000000000000000000000000",cl_role="shardsvr",member_idx="db-1:27017",rs_nm="MyRep",rs_state="2"} 3
mongodb_cfg_members_hidden{cl_id="000000000000000000000000",cl_role="shardsvr",member_idx="db-1:27017",rs_nm="MyRep",rs_state="2"} 0

Usage example

Count number of members eligible for primary
count(mongodb_cfg_members_priority > 0 and mongodb_cfg_members_hidden == 0 and ignoring(member_state) mongodb_members_health == 1)
(I use this for alerting when the number is below 2)

TODO

  • Fix lint errors
  • Add replset_config_collector_test.go

  • Tests passed.
  • Fix conflicts with target branch.
  • Update jira ticket description if needed.
  • Attach screenshots/console output to confirm new behavior to jira ticket, if applicable.

When all checks have passed and code is ready for the review, bot should add pmm-review-exporters team as the reviewer. That would assign people from the review team automatically. Report any issues on our Forums and Discord.

@denisok denisok requested review from a team, percona-csalguero and JiriCtvrtka and removed request for a team July 16, 2021 15:43
Copy link
Contributor

@percona-csalguero percona-csalguero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
Thanks for the fix.
Could you address the linter suggestions to set a base for further improvements?

Thanks !

@percona-csalguero
Copy link
Contributor

Hi. Just wanted to let you know I haven't forget about this.
I've just been busy and I would like to manually test it before merging it.
Is it ready for review? It appears as draft.

Regards

@hiroshi
Copy link
Contributor Author

hiroshi commented Aug 2, 2021

Hi, thanks for your attention.

I think at least a test is needed to be reviewable. So it remains as a draft.

I'll add a test when I have a time. Or, if you think this changes are usable I appreciate you take over this.

@percona-csalguero
Copy link
Contributor

Hello again.
I've checked out your branch and it looks good. I need to ask you for some small changes:

  • Address the linter suggestions
  • Add some tests, using this collector against the different server types we have in the docker-compose file.

Thanks for your help.

@JiriCtvrtka
Copy link
Contributor

@hiroshi Do you planning write some tests here? I think everything else is fine and can be merged then.

@hiroshi
Copy link
Contributor Author

hiroshi commented Sep 19, 2021

EDIT: I gave up running linter locally. Tried to fix the linter error and checked it by pushing commits.. So you can ignore this comment.


#295 (review)

Could you address the linter suggestions to set a base for further improvements?

I was trying to run linter on my local Apple Silicon mac, but not succeeded yet.
Image from Gyazo

I think this issue is related #286

How do I run those linter locally to check if my change is OK?

@hiroshi
Copy link
Contributor Author

hiroshi commented Sep 19, 2021

The line where the linter reported an error,
https://github.com/percona/mongodb_exporter/pull/295/files#diff-36945caa3d7bc040bc4a27f3cd597e18399e05ec94a87f344ac74eac5efeb5bcR53

if e, ok := err.(mongo.CommandError); ok {

is a almost identiacal to the line,
if e, ok := err.(mongo.CommandError); ok {

but it seems no linter error here.

I'm not sure what difference cause the linter error...

@hiroshi
Copy link
Contributor Author

hiroshi commented Sep 19, 2021

Also I was trying to run test on my local Apple silicon mac, but unable to run them.

Image from Gyazo

I created another pull request to address it -> #342

@hiroshi
Copy link
Contributor Author

hiroshi commented Sep 19, 2021

I fear that to run lint and test on my Apple silicon mac is unneccesary harder than fix lint and add test itself...
I hope someone taking over this pull request, fix lint and add test for it.
Or should I try on a linux environment, utilize docker for lint and test or fix all problem on Apple silicon mac?
Sorry, I'v just been frustrated...

@hiroshi
Copy link
Contributor Author

hiroshi commented Sep 20, 2021

#295 (review)

Could you address the linter suggestions to set a base for further improvements?

@percona-csalguero I fixed the linter error in 54ded8c.

EDIT: No, this causes segfault on d.logger.Errorf("cannot get replSetGetConfig: %s", err)
https://github.com/percona/mongodb_exporter/pull/295/checks

var e *mongo.CommandError
if errors.As(err, &e) {
if e.Code == replicationNotYetInitialized || e.Code == replicationNotEnabled {
return
}
}
d.logger.Errorf("cannot get replSetGetConfig: %s", err)

@hiroshi hiroshi force-pushed the replSetGetConfigCollector branch 8 times, most recently from 4e2d78b to 2497ae3 Compare September 20, 2021 10:15
@hiroshi
Copy link
Contributor Author

hiroshi commented Sep 20, 2021

Well, I tried to fix the lint error 54ded8c,
then add tests for replSetGetConfigCollector 22b9fe3, but it causes segfault https://github.com/percona/mongodb_exporter/pull/295/checks.

Reverting 54ded8c fixs the segfault.

I'm wondering how to fix the lint error. Can you help this?

@percona-csalguero
Copy link
Contributor

Just add the //nolint in that line. We won't get any benefit of making it more complex to satisfy the linter.

@hiroshi
Copy link
Contributor Author

hiroshi commented Sep 21, 2021

I'v just suppressed a set of lint errors at bb9ecc8.
However I found that more lint errors in replset_config_collector_test.go...

OK, I'll try to mitigate those error if possible....

I just copied implementation of replset_config_collector_test.go from replset_status_collector_test.go (also replset_config_collector.go).
Why no lint errors in replset_status_collector_test.go? Are there any exclusion setting? or lint process only changed file?

EDIT: Also I wonder why the check doesn't failed by those lint errors?

@percona-csalguero
Copy link
Contributor

Hello @hiroshi
Could you fix the merge conflicts and, if it is ready, mark it as ready for review.
Ignore linter errors if that stopping you.
Regards

@hiroshi
Copy link
Contributor Author

hiroshi commented Feb 24, 2023

I'v just tried to resolve those conflict, but there are too much differences since the last merge in origin/main.
https://github.com/percona/mongodb_exporter/compare/4f3568b..b526414

It seems that I need to read new code base to adjust my changes....

@hiroshi hiroshi force-pushed the replSetGetConfigCollector branch 2 times, most recently from 43bfd04 to 828d774 Compare February 24, 2023 09:33
…ctor

# Conflicts:
#	README.md
#	exporter/exporter.go
#	main.go
#	main_test.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to monitor number of members eligible for primary?
4 participants