Skip to content

Commit c59b913

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 up to 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 85d2108 commit c59b913

File tree

9 files changed

+1232
-151
lines changed

9 files changed

+1232
-151
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: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,23 @@ 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. Quantiles in metrics summary collections
612+
are disabled by default. You can manually choose driver and enable quantiles.
610613
```lua
614+
-- Use metrics collectors. (Default if metrics found).
615+
crud.enable_stats({ driver = 'metrics' })
616+
617+
-- Use metrics collectors with 0.99 quantiles.
618+
crud.enable_stats({ driver = 'metrics', quantiles = true })
619+
620+
-- Use simple local collectors.
621+
crud.enable_stats({ driver = 'local' })
622+
```
623+
624+
Format is as follows.
625+
```
611626
crud.stats()
612627
---
613628
- spaces:
@@ -657,9 +672,44 @@ Possible statistics operation labels are
657672
Each operation section contains of different collectors
658673
for success calls and error (both error throw and `nil, err`)
659674
returns. `count` is total requests count since instance start
660-
or stats restart. `latency` is average time of requests execution,
675+
or stats restart. `latency` is 0.99 quantile of request execution
676+
time if `metrics` driver used and quantiles enabled,
677+
otherwise `latency` is total average.
661678
`time` is total time of requests execution.
662679

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

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

681739
## Cartridge roles
682740

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)