Skip to content

Commit 6f9d79e

Browse files
Integrate CRUD statistics with metrics rock
If `metrics` [1] found, you can use metrics collectors to store statistics. It is required to use `>= 0.9.0` to support age buckets in summary and crucial bugfixes under high load [2]. 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'). If `metrics` used, `latency` statistics are changed to 0.99 quantile of request execution time (with aging). 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 Closes #224
1 parent 1440a84 commit 6f9d79e

File tree

7 files changed

+961
-107
lines changed

7 files changed

+961
-107
lines changed

.github/workflows/test_on_push.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ 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]
1819
include:
1920
- tarantool-version: "2.7"
2021
remove-merger: true
22+
- tarantool-version: "2.8"
23+
metrics-version: "0.1.8"
24+
- tarantool-version: "2.8"
25+
metrics-version: "0.9.0"
2126
- tarantool-version: "2.8"
2227
coveralls: true
28+
metrics-version: "0.12.0"
2329
fail-fast: false
2430
runs-on: [ubuntu-latest]
2531
steps:
@@ -47,6 +53,10 @@ jobs:
4753
tarantool --version
4854
./deps.sh
4955
56+
- name: Install metrics
57+
if: matrix.metrics-version != ''
58+
run: tarantoolctl rocks install metrics ${{ matrix.metrics-version }}
59+
5060
- name: Remove external merger if needed
5161
if: ${{ matrix.remove-merger }}
5262
run: rm .rocks/lib/tarantool/tuple/merger.so

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

README.md

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

609-
Format is as follows.
609+
If [`metrics`](https://github.com/tarantool/metrics) `0.9.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.
614+
crud.enable_stats({ driver = 'metrics' })
615+
616+
-- Use simple local collectors.
617+
crud.enable_stats({ driver = 'local' })
618+
```
619+
620+
Format is as follows.
621+
```
611622
crud.stats()
612623
---
613624
- spaces:
@@ -654,11 +665,44 @@ Possible statistics operation labels are
654665
Each operation section contains of different collectors
655666
for success calls and error (both error throw and `nil, err`)
656667
returns. `count` is total requests count since instance start
657-
or stats restart. `latency` is average time of requests execution,
668+
or stats restart. `latency` is 0.99 quantile of request execution
669+
time if `metrics` driver used, otherwise `latency` is total average.
658670
`time` is total time of requests execution.
659671

672+
In [`metrics`](https://www.tarantool.io/en/doc/latest/book/monitoring/)
673+
registry statistics are stored as `tnt_crud_stats` metrics
674+
with `operation`, `status` and `name` labels. Collector
675+
`tnt_crud_space_not_found` stores count of calls to unknown spaces.
676+
```
677+
metrics:collect()
678+
---
679+
- - label_pairs:
680+
status: ok
681+
operation: insert
682+
name: customers
683+
value: 221411
684+
metric_name: tnt_crud_stats_count
685+
- label_pairs:
686+
status: ok
687+
operation: insert
688+
name: customers
689+
value: 10.49834896344692
690+
metric_name: tnt_crud_stats_sum
691+
- label_pairs:
692+
status: ok
693+
operation: insert
694+
name: customers
695+
quantile: 0.99
696+
value: 0.00023606420935973
697+
metric_name: tnt_crud_stats
698+
- label_pairs: []
699+
value: 3
700+
metric_name: tnt_crud_space_not_found
701+
...
702+
```
703+
660704
`select` section additionally contains `details` collectors.
661-
```lua
705+
```
662706
crud.stats('my_space').select.details
663707
---
664708
- map_reduces: 4
@@ -671,6 +715,10 @@ crud.stats('my_space').select.details
671715
is a count of tuples fetched from storages during execution,
672716
`tuples_lookup` is a count of tuples looked up on storages
673717
while collecting response for call.
718+
In [`metrics`](https://www.tarantool.io/en/doc/latest/book/monitoring/)
719+
registry they are stored as `tnt_crud_map_reduces`,
720+
`tnt_crud_tuples_fetched` and `tnt_crud_tuples_lookup` metrics
721+
with `{ operation = 'select', name = space_name }` labels.
674722

675723
## Cartridge roles
676724

0 commit comments

Comments
 (0)