-
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
PMM-13426: Fix PBM collector memory leak #928
Conversation
exporter/exporter.go
Outdated
pbmc, err := newPbmCollector(ctx, client, e.opts.URI, e.opts.Logger) | ||
if err != nil { | ||
e.logger.Errorf("Cannot create PBM collector: %v, collector will now be disabled.", err) | ||
e.opts.EnablePBMMetrics = false | ||
requestOpts.EnablePBMMetrics = false | ||
} else { | ||
registry.MustRegister(pbmc) | ||
} |
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.
we create these objects on each request, so it won't help much
exporter/pbm_collector.go
Outdated
func newPbmCollector(ctx context.Context, client *mongo.Client, mongoURI string, logger *logrus.Logger) (*pbmCollector, error) { | ||
// we can't get details of other cluster from PBM if directConnection is set to true, | ||
// we re-write it if that option is set (e.g from PMM). | ||
if strings.Contains(mongoURI, "directConnection=true") { | ||
mongoURI = strings.ReplaceAll(mongoURI, "directConnection=true", "directConnection=false") | ||
} | ||
pbmClient, err := sdk.NewClient(ctx, mongoURI) | ||
if err != nil { | ||
logger.Errorf("failed to initialize PBM client from uri %s: %s", mongoURI, err.Error()) | ||
return nil, err | ||
} | ||
|
||
defer func() { | ||
err := pbmClient.Close(ctx) | ||
if err != nil { | ||
logger.Errorf("failed to close PBM client: %v", err) | ||
} | ||
}() | ||
_, err = pbmClient.GetConfig(ctx) | ||
if err != nil { | ||
logger.Errorf("failed to get PBM configuration during initialization: %s", err.Error()) | ||
return nil, err | ||
} | ||
return &pbmCollector{ | ||
ctx: ctx, | ||
mongoURI: mongoURI, | ||
base: newBaseCollector(client, logger.WithFields(logrus.Fields{"collector": "pbm"})), | ||
} | ||
}, nil |
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 revert it because of message above
exporter/pbm_collector.go
Outdated
@@ -112,7 +95,7 @@ func (p *pbmCollector) collect(ch chan<- prometheus.Metric) { | |||
|
|||
pbmConfig, err := pbmClient.GetConfig(p.ctx) | |||
if err != nil { | |||
logger.Errorf("failed to get PBM configuration: %s", err.Error()) | |||
logger.Warnf("failed to get PBM configuration: %s", err.Error()) |
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 think it should be Info level if we expect that pbm config might not exist there
PMM-13426 (optional, if ticket reported)
Closes #922 and #924
Below we provide a basic checklist of things that would make it a good PR:
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.