Skip to content

Commit c6b15b9

Browse files
Integrate CRUD statistics with metrics
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 07f59c8 commit c6b15b9

File tree

7 files changed

+941
-105
lines changed

7 files changed

+941
-105
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` (#224).
1213

1314
### Changed
1415

README.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,15 @@ crud.enable_stats()
610610
crud.reset_stats()
611611
```
612612

613+
If [`metrics`](https://github.com/tarantool/metrics) `0.9.0` or greater
614+
found, metrics collectors will be used by default to store statistics
615+
instead of local collectors. You can manually choose driver if needed.
616+
```
617+
-- Use metrics collectors.
618+
crud.enable_stats({ driver = 'metrics' })
619+
```
620+
621+
To get statistics in code, call `crud.stats()`.
613622
```lua
614623
crud.stats()
615624
---
@@ -645,9 +654,41 @@ Possible statistics operation labels are
645654
Each operation section contains of different collectors
646655
for success calls and error (both error throw and `nil, err`)
647656
returns. `count` is total requests count since instance start
648-
or stats restart. `latency` is average time of requests execution,
657+
or stats restart. `latency` is 0.99 quantile of request execution
658+
time if `metrics` driver used, otherwise `latency` is total average.
649659
`time` is total time of requests execution.
650660

661+
In `metrics` registry statistics are stored as `tnt_crud_stats` metrics
662+
with `operation`, `status` and `name` labels. Collector
663+
`tnt_crud_space_not_found` stores count of calls to unknown spaces.
664+
```
665+
metrics:collect()
666+
---
667+
- - label_pairs:
668+
status: ok
669+
operation: insert
670+
name: customers
671+
value: 221411
672+
metric_name: tnt_crud_stats_count
673+
- label_pairs:
674+
status: ok
675+
operation: insert
676+
name: customers
677+
value: 10.49834896344692
678+
metric_name: tnt_crud_stats_sum
679+
- label_pairs:
680+
status: ok
681+
operation: insert
682+
name: customers
683+
quantile: 0.99
684+
value: 0.00023606420935973
685+
metric_name: tnt_crud_stats
686+
- label_pairs: []
687+
value: 3
688+
metric_name: tnt_crud_space_not_found
689+
...
690+
```
691+
651692
`select` section additionally contains `details` collectors.
652693
```lua
653694
crud.stats('my_space').select.details
@@ -661,7 +702,10 @@ crud.stats('my_space').select.details
661702
(including those not executed successfully). `tuples_fetched`
662703
is a count of tuples fetched from storages during execution,
663704
`tuples_lookup` is a count of tuples looked up on storages
664-
while collecting response for call.
705+
while collecting response for call. In `metrics` registry they
706+
are stored as `tnt_crud_map_reduces`, `tnt_crud_tuples_fetched`
707+
and `tnt_crud_tuples_lookup` metrics with
708+
`{ operation = 'select', name = space_name }` labels.
665709

666710
## Cartridge roles
667711

0 commit comments

Comments
 (0)