Skip to content

Commit bc7ef2b

Browse files
Integrate CRUD statistics with metrics rock
If `metrics` [1] found, you can use metrics collectors to store statistics. `metrics >= 0.10.0` is required to use metrics driver. (`metrics >= 0.9.0` is required to use summary quantiles with age buckets. `metrics >= 0.5.0, < 0.9.0` is unsupported due to quantile overflow bug [2]. `metrics == 0.9.0` has bug that do not permits to create summary collector without quantiles [3]. In fact, user may use `metrics >= 0.5.0`, `metrics != 0.9.0` if he wants to use metrics without quantiles, and `metrics >= 0.9.0` if he wants to use metrics with quantiles. But this is confusing, so let's use a single restriction for both cases.) The metrics are part of global registry and can be exported together (e.g. to Prometheus) with default tools without any additional configuration. Disabling stats destroys the collectors. Metrics collectors are used by default if supported. To explicitly set driver, call `crud.enable_stats{ driver = driver }` ('local' or 'metrics'). To enable quantiles, call `crud.enable_stats{ driver = 'metrics', quantiles = true }`. With quantiles, `latency` statistics are changed to 0.99 quantile of request execution time (with aging). Quantiles computations increases performance overhead by near 10% when used in statistics. Add CI matrix to run tests with `metrics` installed. To get full coverage on coveralls, #248 must be resolved. 1. https://github.com/tarantool/metrics 2. tarantool/metrics#235 3. tarantool/metrics#262 Closes #224
1 parent 620994a commit bc7ef2b

File tree

9 files changed

+1234
-150
lines changed

9 files changed

+1234
-150
lines changed

.github/workflows/test_on_push.yaml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,24 @@ jobs:
1313
matrix:
1414
# We need 1.10.6 here to check that module works with
1515
# old Tarantool versions that don't have "tuple-keydef"/"tuple-merger" support.
16-
tarantool-version: ["1.10.6", "1.10", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7"]
16+
tarantool-version: ["1.10.6", "1.10", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7", "2.8"]
17+
metrics-version: [""]
1718
remove-merger: [false]
19+
perf-test: [false]
1820
include:
21+
- tarantool-version: "1.10"
22+
metrics-version: "0.12.0"
23+
perf-test: true
1924
- tarantool-version: "2.7"
2025
remove-merger: true
26+
- tarantool-version: "2.8"
27+
metrics-version: "0.1.8"
28+
- tarantool-version: "2.8"
29+
metrics-version: "0.10.0"
2130
- tarantool-version: "2.8"
2231
coveralls: true
32+
metrics-version: "0.12.0"
33+
perf-test: true
2334
fail-fast: false
2435
runs-on: [ubuntu-latest]
2536
steps:
@@ -47,6 +58,10 @@ jobs:
4758
tarantool --version
4859
./deps.sh
4960
61+
- name: Install metrics
62+
if: matrix.metrics-version != ''
63+
run: tarantoolctl rocks install metrics ${{ matrix.metrics-version }}
64+
5065
- name: Remove external merger if needed
5166
if: ${{ matrix.remove-merger }}
5267
run: rm .rocks/lib/tarantool/tuple/merger.so
@@ -62,6 +77,10 @@ jobs:
6277
- name: Run tests and code coverage analysis
6378
run: make -C build coverage
6479

80+
- name: Run performance tests
81+
run: make -C build performance
82+
if: ${{ matrix.perf-test }}
83+
6584
- name: Send code coverage to coveralls.io
6685
run: make -C build coveralls
6786
if: ${{ matrix.coveralls }}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
### Added
1111
* Statistics for CRUD operations on router (#224).
12+
* Integrate CRUD statistics with [`metrics`](https://github.com/tarantool/metrics) (#224).
1213

1314
### Changed
1415

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ add_custom_target(luatest
3636
COMMENT "Run regression tests"
3737
)
3838

39+
set(PERFORMANCE_TESTS_SUBDIR "test/performance")
40+
41+
add_custom_target(performance
42+
COMMAND PERF_MODE_ON=true ${LUATEST} -v -c ${PERFORMANCE_TESTS_SUBDIR}
43+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
44+
COMMENT "Run performance tests"
45+
)
46+
3947
add_custom_target(coverage
4048
COMMAND ${LUACOV} ${PROJECT_SOURCE_DIR} && grep -A999 '^Summary' ${CODE_COVERAGE_REPORT}
4149
DEPENDS ${CODE_COVERAGE_STATS}

README.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,24 @@ crud.disable_stats()
606606
crud.reset_stats()
607607
```
608608

609-
Format is as follows.
609+
If [`metrics`](https://github.com/tarantool/metrics) `0.10.0` or greater
610+
found, metrics collectors will be used by default to store statistics
611+
instead of local collectors. You can manually choose driver if needed.
610612
```lua
613+
-- Use metrics collectors. (Default if metrics found).
614+
crud.enable_stats({ driver = 'metrics' })
615+
616+
-- Use metrics collectors with 0.99 quantile.
617+
crud.enable_stats({ driver = 'metrics', quantiles = true })
618+
619+
-- Use simple local collectors.
620+
crud.enable_stats({ driver = 'local' })
621+
```
622+
Performance overhead is 3-7% in case of `local` driver and
623+
5-10% in case of `metrics` driver, up to 20% for `metrics` with quantiles.
624+
625+
Format is as follows.
626+
```
611627
crud.stats()
612628
---
613629
- spaces:
@@ -657,9 +673,44 @@ Possible statistics operation labels are
657673
Each operation section contains of different collectors
658674
for success calls and error (both error throw and `nil, err`)
659675
returns. `count` is total requests count since instance start
660-
or stats restart. `latency` is average time of requests execution,
676+
or stats restart. `latency` is 0.99 quantile of request execution
677+
time if `metrics` driver used and quantiles enabled,
678+
otherwise `latency` is total average.
661679
`time` is total time of requests execution.
662680

681+
In [`metrics`](https://www.tarantool.io/en/doc/latest/book/monitoring/)
682+
registry statistics are stored as `tnt_crud_stats` metrics
683+
with `operation`, `status` and `name` labels. Collector
684+
`tnt_crud_space_not_found` stores count of calls to unknown spaces,
685+
`tnt_crud_schema_reloads` stores count of schema reloads in calls.
686+
```
687+
metrics:collect()
688+
---
689+
- - label_pairs:
690+
status: ok
691+
operation: insert
692+
name: customers
693+
value: 221411
694+
metric_name: tnt_crud_stats_count
695+
- label_pairs:
696+
status: ok
697+
operation: insert
698+
name: customers
699+
value: 10.49834896344692
700+
metric_name: tnt_crud_stats_sum
701+
- label_pairs:
702+
status: ok
703+
operation: insert
704+
name: customers
705+
quantile: 0.99
706+
value: 0.00023606420935973
707+
metric_name: tnt_crud_stats
708+
- label_pairs: []
709+
value: 3
710+
metric_name: tnt_crud_space_not_found
711+
...
712+
```
713+
663714
`select` section additionally contains `details` collectors.
664715
```lua
665716
crud.stats('my_space').select.details
@@ -674,9 +725,17 @@ crud.stats('my_space').select.details
674725
is a count of tuples fetched from storages during execution,
675726
`tuples_lookup` is a count of tuples looked up on storages
676727
while collecting response for call.
728+
In [`metrics`](https://www.tarantool.io/en/doc/latest/book/monitoring/)
729+
registry they are stored as `tnt_crud_map_reduces`,
730+
`tnt_crud_tuples_fetched` and `tnt_crud_tuples_lookup` metrics
731+
with `{ operation = 'select', name = space_name }` labels.
677732

678733
Statistics are preserved between package reloads or [Tarantool Cartridge
679734
role reloads](https://www.tarantool.io/en/doc/latest/book/cartridge/cartridge_api/modules/cartridge.roles/#reload).
735+
Beware that metrics 0.12.0 and below do not support
736+
preserving stats between role reload
737+
(see [tarantool/metrics#334](https://github.com/tarantool/metrics/issues/334)),
738+
thus this feature will be unsupported for `metrics` driver.
680739

681740
## Cartridge roles
682741

crud/stats/local_registry.lua

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
-- @module crud.stats.local_registry
33
--
44

5+
local errors = require('errors')
6+
57
local dev_checks = require('crud.common.dev_checks')
68
local op_module = require('crud.stats.operation')
79
local registry_common = require('crud.stats.registry_common')
810
local stash = require('crud.stats.stash')
911

1012
local registry = {}
1113
local internal = stash.get('local_registry')
14+
local StatsLocalError = errors.new_class('StatsLocalError', {capture_stack = false})
1215

1316
--- Initialize local metrics registry.
1417
--
@@ -17,9 +20,19 @@ local internal = stash.get('local_registry')
1720
--
1821
-- @function init
1922
--
20-
-- @treturn boolean Returns true.
23+
-- @tab opts
2124
--
22-
function registry.init()
25+
-- @bool opts.quantiles
26+
-- Quantiles is not supported for local, only `false` is valid.
27+
--
28+
-- @treturn boolean Returns `true`.
29+
--
30+
function registry.init(opts)
31+
dev_checks({ quantiles = 'boolean' })
32+
33+
StatsLocalError:assert(opts.quantiles == false,
34+
"Quantiles are not supported for 'local' statistics registry")
35+
2336
internal.registry = {}
2437
internal.registry.spaces = {}
2538
internal.registry.space_not_found = 0

0 commit comments

Comments
 (0)