Software /
code /
prosody
Annotate
util/envload.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 |
parent | 8416:bc9cb23b604a |
child | 12576:d1aacc6a81ac |
rev | line source |
---|---|
5020
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
1 -- Prosody IM |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
2 -- Copyright (C) 2008-2011 Florian Zeitz |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
3 -- |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
4 -- This project is MIT/X11 licensed. Please see the |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
5 -- COPYING file in the source package for more information. |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
6 -- |
8416
bc9cb23b604a
util.envload: Ignore "undefined variable" warning for loadstring [luacheck with strict 5.2 or 5.3 checks]
Kim Alvefur <zash@zash.se>
parents:
7930
diff
changeset
|
7 -- luacheck: ignore 113/setfenv 113/loadstring |
5020
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
8 |
7924
8487fe9fc335
util.envload: Open file here instead of letting loadfile do it so that all return values from io.open can be collected
Kim Alvefur <zash@zash.se>
parents:
7728
diff
changeset
|
9 local load, loadstring, setfenv = load, loadstring, setfenv; |
8487fe9fc335
util.envload: Open file here instead of letting loadfile do it so that all return values from io.open can be collected
Kim Alvefur <zash@zash.se>
parents:
7728
diff
changeset
|
10 local io_open = io.open; |
5020
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
11 local envload; |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
12 local envloadfile; |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
13 |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
14 if setfenv then |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
15 function envload(code, source, env) |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
16 local f, err = loadstring(code, source); |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
17 if f and env then setfenv(f, env); end |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
18 return f, err; |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
19 end |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
20 |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
21 function envloadfile(file, env) |
7924
8487fe9fc335
util.envload: Open file here instead of letting loadfile do it so that all return values from io.open can be collected
Kim Alvefur <zash@zash.se>
parents:
7728
diff
changeset
|
22 local fh, err, errno = io_open(file); |
8487fe9fc335
util.envload: Open file here instead of letting loadfile do it so that all return values from io.open can be collected
Kim Alvefur <zash@zash.se>
parents:
7728
diff
changeset
|
23 if not fh then return fh, err, errno; end |
8487fe9fc335
util.envload: Open file here instead of letting loadfile do it so that all return values from io.open can be collected
Kim Alvefur <zash@zash.se>
parents:
7728
diff
changeset
|
24 local f, err = load(function () return fh:read(2048); end, "@"..file); |
7930
5dec27760ecd
util.envload: Close file handle after reading data
Kim Alvefur <zash@zash.se>
parents:
7924
diff
changeset
|
25 fh:close(); |
5020
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
26 if f and env then setfenv(f, env); end |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
27 return f, err; |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
28 end |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
29 else |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
30 function envload(code, source, env) |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
31 return load(code, source, nil, env); |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
32 end |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
33 |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
34 function envloadfile(file, env) |
7924
8487fe9fc335
util.envload: Open file here instead of letting loadfile do it so that all return values from io.open can be collected
Kim Alvefur <zash@zash.se>
parents:
7728
diff
changeset
|
35 local fh, err, errno = io_open(file); |
8487fe9fc335
util.envload: Open file here instead of letting loadfile do it so that all return values from io.open can be collected
Kim Alvefur <zash@zash.se>
parents:
7728
diff
changeset
|
36 if not fh then return fh, err, errno; end |
7930
5dec27760ecd
util.envload: Close file handle after reading data
Kim Alvefur <zash@zash.se>
parents:
7924
diff
changeset
|
37 local f, err = load(fh:lines(2048), "@"..file, nil, env); |
5dec27760ecd
util.envload: Close file handle after reading data
Kim Alvefur <zash@zash.se>
parents:
7924
diff
changeset
|
38 fh:close(); |
5dec27760ecd
util.envload: Close file handle after reading data
Kim Alvefur <zash@zash.se>
parents:
7924
diff
changeset
|
39 return f, err; |
5020
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
40 end |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
41 end |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
42 |
ef1eb65acbba
util.envload: New module to abstract Lua 5.1's setfenv and Lua 5.2's load
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
43 return { envload = envload, envloadfile = envloadfile }; |