Software /
code /
prosody
Annotate
spec/util_hashes_spec.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 | 10748:93293891709b |
child | 12355:a0ff5c438e9d |
rev | line source |
---|---|
9964
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 -- Test vectors from RFC 6070 |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local hashes = require "util.hashes"; |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local hex = require "util.hex"; |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 -- Also see spec for util.hmac where HMAC test cases reside |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 |
10747
63a89b876407
util.hashes: Use generic name of PBKDF2-HMAC-SHA1 function in tests
Kim Alvefur <zash@zash.se>
parents:
9970
diff
changeset
|
7 describe("PBKDF2-HMAC-SHA1", function () |
9964
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 it("test vector 1", function () |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 local P = "password" |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 local S = "salt" |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 local c = 1 |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 local DK = "0c60c80f961f0e71f3a9b524af6012062fe037a6"; |
10747
63a89b876407
util.hashes: Use generic name of PBKDF2-HMAC-SHA1 function in tests
Kim Alvefur <zash@zash.se>
parents:
9970
diff
changeset
|
13 assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha1(P, S, c))); |
9964
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 end); |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 it("test vector 2", function () |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 local P = "password" |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 local S = "salt" |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 local c = 2 |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 local DK = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957"; |
10747
63a89b876407
util.hashes: Use generic name of PBKDF2-HMAC-SHA1 function in tests
Kim Alvefur <zash@zash.se>
parents:
9970
diff
changeset
|
20 assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha1(P, S, c))); |
9964
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 end); |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 it("test vector 3", function () |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 local P = "password" |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 local S = "salt" |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 local c = 4096 |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 local DK = "4b007901b765489abead49d926f721d065a429c1"; |
10747
63a89b876407
util.hashes: Use generic name of PBKDF2-HMAC-SHA1 function in tests
Kim Alvefur <zash@zash.se>
parents:
9970
diff
changeset
|
27 assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha1(P, S, c))); |
9964
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 end); |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 it("test vector 4 #SLOW", function () |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 local P = "password" |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 local S = "salt" |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 local c = 16777216 |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 local DK = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984"; |
10747
63a89b876407
util.hashes: Use generic name of PBKDF2-HMAC-SHA1 function in tests
Kim Alvefur <zash@zash.se>
parents:
9970
diff
changeset
|
34 assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha1(P, S, c))); |
9964
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 end); |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 end); |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 |
10748
93293891709b
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents:
10747
diff
changeset
|
38 describe("PBKDF2-HMAC-SHA256", function () |
93293891709b
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents:
10747
diff
changeset
|
39 it("test vector 1", function () |
93293891709b
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents:
10747
diff
changeset
|
40 local P = "password"; |
93293891709b
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents:
10747
diff
changeset
|
41 local S = "salt"; |
93293891709b
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents:
10747
diff
changeset
|
42 local c = 1 |
93293891709b
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents:
10747
diff
changeset
|
43 local DK = "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b"; |
93293891709b
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents:
10747
diff
changeset
|
44 assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha256(P, S, c))); |
93293891709b
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents:
10747
diff
changeset
|
45 end); |
93293891709b
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents:
10747
diff
changeset
|
46 it("test vector 2", function () |
93293891709b
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents:
10747
diff
changeset
|
47 local P = "password"; |
93293891709b
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents:
10747
diff
changeset
|
48 local S = "salt"; |
93293891709b
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents:
10747
diff
changeset
|
49 local c = 2 |
93293891709b
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents:
10747
diff
changeset
|
50 local DK = "ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43"; |
93293891709b
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents:
10747
diff
changeset
|
51 assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha256(P, S, c))); |
93293891709b
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents:
10747
diff
changeset
|
52 end); |
93293891709b
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents:
10747
diff
changeset
|
53 end); |
93293891709b
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents:
10747
diff
changeset
|
54 |
93293891709b
util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents:
10747
diff
changeset
|
55 |