Mercurial > prosody-hg
annotate plugins/mod_user_account_management.lua @ 11523:5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
The metric subsystem of Prosody has had some shortcomings from
the perspective of the current state-of-the-art in metric
observability.
The OpenMetrics standard [0] is a formalization of the data
model (and serialization format) of the well-known and
widely-used Prometheus [1] software stack.
The previous stats subsystem of Prosody did not map well to that
format (see e.g. [2] and [3]); the key reason is that it was
trying to do too much math on its own ([2]) while lacking
first-class support for "families" of metrics ([3]) and
structured metric metadata (despite the `extra` argument to
metrics, there was no standard way of representing common things
like "tags" or "labels").
Even though OpenMetrics has grown from the Prometheus world of
monitoring, it maps well to other popular monitoring stacks
such as:
- InfluxDB (labels can be mapped to tags and fields as necessary)
- Carbon/Graphite (labels can be attached to the metric name with
dot-separation)
- StatsD (see graphite when assuming that graphite is used as
backend, which is the default)
The util.statsd module has been ported to use the OpenMetrics
model as a proof of concept. An implementation which exposes
the util.statistics backend data as Prometheus metrics is
ready for publishing in prosody-modules (most likely as
mod_openmetrics_prometheus to avoid breaking existing 0.11
deployments).
At the same time, the previous measure()-based API had one major
advantage: It is really simple and easy to use without requiring
lots of knowledge about OpenMetrics or similar concepts. For that
reason as well as compatibility with existing code, it is preserved
and may even be extended in the future.
However, code relying on the `stats-updated` event as well as
`get_stats` from `statsmanager` will break because the data
model has changed completely; in case of `stats-updated`, the
code will simply not run (as the event was renamed in order
to avoid conflicts); the `get_stats` function has been removed
completely (so it will cause a traceback when it is attempted
to be used).
Note that the measure_*_event methods have been removed from
the module API. I was unable to find any uses or documentation
and thus deemed they should not be ported. Re-implementation is
possible when necessary.
[0]: https://openmetrics.io/
[1]: https://prometheus.io/
[2]: #959
[3]: #960
| author | Jonas Schäfer <jonas@wielicki.name> |
|---|---|
| date | Sun, 18 Apr 2021 11:47:41 +0200 |
| parents | fcdc65bc6697 |
| children | 74b9e05af71e |
| rev | line source |
|---|---|
|
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
1189
diff
changeset
|
1 -- Prosody IM |
|
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2448
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
|
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2448
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5763
diff
changeset
|
4 -- |
| 758 | 5 -- This project is MIT/X11 licensed. Please see the |
| 6 -- COPYING file in the source package for more information. | |
|
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
7 -- |
|
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
8 |
|
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
9 |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 local st = require "util.stanza"; |
|
2935
4e4d0d899d9d
mod_register: Use set_password to set passwords instead of create_user.
Waqas Hussain <waqas20@gmail.com>
parents:
2923
diff
changeset
|
11 local usermanager_set_password = require "core.usermanager".set_password; |
|
3996
7f35b292531b
mod_register: Change to use new delete_user auth provider method
Matthew Wild <mwild1@gmail.com>
parents:
3995
diff
changeset
|
12 local usermanager_delete_user = require "core.usermanager".delete_user; |
|
927
cc180d25dbeb
Fixed: mod_register: Node prepping was not being applied to usernames (part of issue #57)
Waqas Hussain <waqas20@gmail.com>
parents:
926
diff
changeset
|
13 local nodeprep = require "util.encodings".stringprep.nodeprep; |
|
3995
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
14 local jid_bare = require "util.jid".bare; |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
15 |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
16 local compat = module:get_option_boolean("registration_compat", true); |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 |
|
541
3521e0851c9e
Change modules to use the new add_feature module API method.
Waqas Hussain <waqas20@gmail.com>
parents:
519
diff
changeset
|
18 module:add_feature("jabber:iq:register"); |
|
421
63be85693710
Modules now sending disco replies
Waqas Hussain <waqas20@gmail.com>
parents:
386
diff
changeset
|
19 |
|
8194
ba9cd8447578
mod_register: Add comments saying which section handles password change, account deletion and which is in-band registration
Kim Alvefur <zash@zash.se>
parents:
8192
diff
changeset
|
20 -- Password change and account deletion handler |
|
3995
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
21 local function handle_registration_stanza(event) |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
22 local session, stanza = event.origin, event.stanza; |
|
7017
ff734a602886
mod_register: Use session log instance to ease indentification
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
23 local log = session.log or module._log; |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
24 |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
25 local query = stanza.tags[1]; |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
26 if stanza.attr.type == "get" then |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
27 local reply = st.reply(stanza); |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
28 reply:tag("query", {xmlns = "jabber:iq:register"}) |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
29 :tag("registered"):up() |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
30 :tag("username"):text(session.username):up() |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
31 :tag("password"):up(); |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
32 session.send(reply); |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
33 else -- stanza.attr.type == "set" |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
34 if query.tags[1] and query.tags[1].name == "remove" then |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
35 local username, host = session.username, session.host; |
|
5098
fca8b5946f6f
mod_register: Hijack the session close call to send the final iq reply when deleting
Kim Alvefur <zash@zash.se>
parents:
5096
diff
changeset
|
36 |
|
7018
5c3d4254d415
mod_register: Add comment explaining the workaround for replying when the account is being deleted
Kim Alvefur <zash@zash.se>
parents:
7017
diff
changeset
|
37 -- This one weird trick sends a reply to this stanza before the user is deleted |
|
5098
fca8b5946f6f
mod_register: Hijack the session close call to send the final iq reply when deleting
Kim Alvefur <zash@zash.se>
parents:
5096
diff
changeset
|
38 local old_session_close = session.close; |
|
7711
c8130995d4d1
mod_register: Rename session reference in wrapped close method [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7710
diff
changeset
|
39 session.close = function(self, ...) |
|
c8130995d4d1
mod_register: Rename session reference in wrapped close method [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7710
diff
changeset
|
40 self.send(st.reply(stanza)); |
|
c8130995d4d1
mod_register: Rename session reference in wrapped close method [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7710
diff
changeset
|
41 return old_session_close(self, ...); |
|
5098
fca8b5946f6f
mod_register: Hijack the session close call to send the final iq reply when deleting
Kim Alvefur <zash@zash.se>
parents:
5096
diff
changeset
|
42 end |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5763
diff
changeset
|
43 |
|
3996
7f35b292531b
mod_register: Change to use new delete_user auth provider method
Matthew Wild <mwild1@gmail.com>
parents:
3995
diff
changeset
|
44 local ok, err = usermanager_delete_user(username, host); |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5763
diff
changeset
|
45 |
|
3996
7f35b292531b
mod_register: Change to use new delete_user auth provider method
Matthew Wild <mwild1@gmail.com>
parents:
3995
diff
changeset
|
46 if not ok then |
|
7017
ff734a602886
mod_register: Use session log instance to ease indentification
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
47 log("debug", "Removing user account %s@%s failed: %s", username, host, err); |
|
5098
fca8b5946f6f
mod_register: Hijack the session close call to send the final iq reply when deleting
Kim Alvefur <zash@zash.se>
parents:
5096
diff
changeset
|
48 session.close = old_session_close; |
|
3996
7f35b292531b
mod_register: Change to use new delete_user auth provider method
Matthew Wild <mwild1@gmail.com>
parents:
3995
diff
changeset
|
49 session.send(st.error_reply(stanza, "cancel", "service-unavailable", err)); |
|
7f35b292531b
mod_register: Change to use new delete_user auth provider method
Matthew Wild <mwild1@gmail.com>
parents:
3995
diff
changeset
|
50 return true; |
|
7f35b292531b
mod_register: Change to use new delete_user auth provider method
Matthew Wild <mwild1@gmail.com>
parents:
3995
diff
changeset
|
51 end |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5763
diff
changeset
|
52 |
|
7017
ff734a602886
mod_register: Use session log instance to ease indentification
Kim Alvefur <zash@zash.se>
parents:
5776
diff
changeset
|
53 log("info", "User removed their account: %s@%s", username, host); |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
54 module:fire_event("user-deregistered", { username = username, host = host, source = "mod_register", session = session }); |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
55 else |
|
10382
fcdc65bc6697
mod_user_account_management: Apply username normalization later
Kim Alvefur <zash@zash.se>
parents:
8484
diff
changeset
|
56 local username = query:get_child_text("username"); |
|
5637
991b47778bf3
mod_register: get_child_text()!
Kim Alvefur <zash@zash.se>
parents:
5500
diff
changeset
|
57 local password = query:get_child_text("password"); |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
58 if username and password then |
|
10382
fcdc65bc6697
mod_user_account_management: Apply username normalization later
Kim Alvefur <zash@zash.se>
parents:
8484
diff
changeset
|
59 username = nodeprep(username); |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
60 if username == session.username then |
|
8192
4354f556c5db
core.usermanager, various modules: Disconnect other resources on password change (thanks waqas) (fixes #512)
Kim Alvefur <zash@zash.se>
parents:
8183
diff
changeset
|
61 if usermanager_set_password(username, password, session.host, session.resource) then |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
62 session.send(st.reply(stanza)); |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
63 else |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
64 -- TODO unable to write file, file may be locked, etc, what's the correct error? |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
65 session.send(st.error_reply(stanza, "wait", "internal-server-error")); |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
66 end |
|
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
67 else |
|
311
513bd52e8e19
Fixed mod_register to use session.send for sending stanzas
Waqas Hussain <waqas20@gmail.com>
parents:
85
diff
changeset
|
68 session.send(st.error_reply(stanza, "modify", "bad-request")); |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
69 end |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
70 else |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
71 session.send(st.error_reply(stanza, "modify", "bad-request")); |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
72 end |
|
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
73 end |
|
3529
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
74 end |
|
3f9cc12308aa
mod_register: Updated to use the new events API.
Waqas Hussain <waqas20@gmail.com>
parents:
3394
diff
changeset
|
75 return true; |
|
3995
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
76 end |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
77 |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
78 module:hook("iq/self/jabber:iq:register:query", handle_registration_stanza); |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
79 if compat then |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
80 module:hook("iq/host/jabber:iq:register:query", function (event) |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
81 local session, stanza = event.origin, event.stanza; |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
82 if session.type == "c2s" and jid_bare(stanza.attr.to) == session.host then |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
83 return handle_registration_stanza(event); |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
84 end |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
85 end); |
|
e504b06492c6
mod_register: Add registration_compat config option to allow account remove requests addressed to='host' (defaults to true)
Matthew Wild <mwild1@gmail.com>
parents:
3540
diff
changeset
|
86 end |
|
60
44800be871f5
User registration, etc (jabber:iq:register)
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
87 |
