Skip to content

Commit d33cca7

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 a5d8f4d commit d33cca7

File tree

9 files changed

+1232
-150
lines changed

9 files changed

+1232
-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: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,22 @@ 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+
623+
Format is as follows.
624+
```
611625
crud.stats()
612626
---
613627
- spaces:
@@ -657,9 +671,44 @@ Possible statistics operation labels are
657671
Each operation section contains of different collectors
658672
for success calls and error (both error throw and `nil, err`)
659673
returns. `count` is total requests count since instance start
660-
or stats restart. `latency` is average time of requests execution,
674+
or stats restart. `latency` is 0.99 quantile of request execution
675+
time if `metrics` driver used and quantiles enabled,
676+
otherwise `latency` is total average.
661677
`time` is total time of requests execution.
662678

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

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

681738
## Cartridge roles
682739

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)