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

Change how reporters subscribe to metrics #3148

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gustawlippa
Copy link
Contributor

Now every call to ensure_metric/3 also subscribes all reporters to it, which I think is a less surprising API. This makes init_subscriptions/0 redundant. The benefit is that some metrics started after the call to mongoose_metrics:init were not reported (global.unregister_command), thus not visible in Graphite for example, and now such situation is impossible.

This PR is just a proposition to solve the problem. The upside is that if you ensure a metric exists, it is also reported (if any reporters are set). The downside is that there is less flexibility in adding reporters, or for example using some reporters for some metrics, and not subscribing them to others.

Now every call to ensure_metric/3 also subscribes all reporters to it. This
makes init_subscriptions/0 redundant. The benefit is that some metrics started
after the call to mongoose_metrics:init were not reported and now such
situation is impossible.
@codecov
Copy link

codecov bot commented Jun 1, 2021

Codecov Report

Merging #3148 (3fe2541) into master (94935ae) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3148      +/-   ##
==========================================
- Coverage   79.52%   79.48%   -0.04%     
==========================================
  Files         397      397              
  Lines       32320    32310      -10     
==========================================
- Hits        25701    25681      -20     
- Misses       6619     6629      +10     
Impacted Files Coverage Δ
src/global_distrib/mod_global_distrib_utils.erl 64.42% <100.00%> (-1.00%) ⬇️
src/metrics/mongoose_metrics.erl 95.91% <100.00%> (-0.19%) ⬇️
src/elasticsearch/mongoose_elasticsearch.erl 76.92% <0.00%> (-7.70%) ⬇️
src/pubsub/node_hometree.erl 77.77% <0.00%> (-5.56%) ⬇️
src/ejabberd_s2s_out.erl 60.13% <0.00%> (-1.83%) ⬇️
src/mam/mod_mam_elasticsearch_arch.erl 86.60% <0.00%> (-1.79%) ⬇️
src/wpool/mongoose_wpool.erl 84.00% <0.00%> (-1.00%) ⬇️
src/ejabberd_sm.erl 83.27% <0.00%> (-0.33%) ⬇️
src/ejabberd_c2s.erl 88.98% <0.00%> (-0.23%) ⬇️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 94935ae...3fe2541. Read the comment docs.

subscribe_metric(Name, Type) ->
Reporters = exometer_report:list_reporters(),
lists:foreach(
fun({ReporterName, _ReporterPid}) ->
Copy link
Contributor

Choose a reason for hiding this comment

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

good catch to match Reporter here properly.
Reporting a bad result from exometer_report:subscribe would help to avoid this small bug...

exometer_report:subscribe(Reporter, Name, default, Interval).

subscribe_to_all(Reporter, Interval) ->
Copy link
Contributor

Choose a reason for hiding this comment

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

there are two reasons it's done as is:

  • it could be a bit faster to subscribe to all at once (need to test that)
  • metrics are reported with different initial offset interval if not subscribed at once.

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.

None yet

2 participants