Skip to content

Conversation

@umax
Copy link
Contributor

@umax umax commented Mar 21, 2018

Hi!

I will try to improve multiprocess metrics collections by a series of pull requests.
This one fixes unnecessary metric creation in loop.

The more correct way to use dict.setdefault is result = dict.setdefault(key, value). In our case:

metric = metrics.setdefault(metric_name, core.Metric(...))

instead of

metrics.setdefault(metric_name, core.Metric(...))
metric = metrics[metric_name]

But the problem is that core.Metric(...) will be executed each time when setdefault method calls whether needed or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Chaining = can be confusing, can you make this two statements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no problem

@umax umax force-pushed the reduce-unnecessary-metric-creation branch from 17c8202 to 350d24b Compare March 21, 2018 10:44
@brian-brazil brian-brazil merged commit e2a5061 into prometheus:master Mar 21, 2018
@brian-brazil
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants