Skip to content

Commit

Permalink
Integrate CRUD statistics with metrics
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DifferentialOrange committed Dec 15, 2021
1 parent e10cc0c commit 94a461e
Show file tree
Hide file tree
Showing 7 changed files with 941 additions and 105 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/test_on_push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ jobs:
matrix:
# We need 1.10.6 here to check that module works with
# old Tarantool versions that don't have "tuple-keydef"/"tuple-merger" support.
tarantool-version: ["1.10.6", "1.10", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7"]
tarantool-version: ["1.10.6", "1.10", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7", "2.8"]
metrics-version: [""]
remove-merger: [false]
include:
- tarantool-version: "2.7"
remove-merger: true
- tarantool-version: "2.8"
metrics-version: "0.1.8"
- tarantool-version: "2.8"
metrics-version: "0.9.0"
- tarantool-version: "2.8"
coveralls: true
metrics-version: "0.12.0"
fail-fast: false
runs-on: [ubuntu-latest]
steps:
Expand Down Expand Up @@ -47,6 +53,10 @@ jobs:
tarantool --version
./deps.sh
- name: Install metrics
if: matrix.metrics-version != ''
run: tarantoolctl rocks install metrics ${{ matrix.metrics-version }}

- name: Remove external merger if needed
if: ${{ matrix.remove-merger }}
run: rm .rocks/lib/tarantool/tuple/merger.so
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added
* Statistics for CRUD operations on router (#224).
* Integrate CRUD statistics with `metrics` (#224).

### Changed

Expand Down
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,15 @@ crud.enable_stats()
crud.reset_stats()
```

If [`metrics`](https://github.com/tarantool/metrics) `0.9.0` or greater
found, metrics collectors will be used by default to store statistics
instead of local collectors. You can manually choose driver if needed.
```
-- Use metrics collectors.
crud.enable_stats({ driver = 'metrics' })
```

To get statistics in code, call `crud.stats()`.
```lua
crud.stats()
---
Expand Down Expand Up @@ -645,9 +654,41 @@ Possible statistics operation labels are
Each operation section contains of different collectors
for success calls and error (both error throw and `nil, err`)
returns. `count` is total requests count since instance start
or stats restart. `latency` is average time of requests execution,
or stats restart. `latency` is 0.99 quantile of request execution
time if `metrics` driver used, otherwise `latency` is total average.
`time` is total time of requests execution.

In `metrics` registry statistics are stored as `tnt_crud_stats` metrics
with `operation`, `status` and `name` labels. Collector
`tnt_crud_space_not_found` stores count of calls to unknown spaces.
```
metrics:collect()
---
- - label_pairs:
status: ok
operation: insert
name: customers
value: 221411
metric_name: tnt_crud_stats_count
- label_pairs:
status: ok
operation: insert
name: customers
value: 10.49834896344692
metric_name: tnt_crud_stats_sum
- label_pairs:
status: ok
operation: insert
name: customers
quantile: 0.99
value: 0.00023606420935973
metric_name: tnt_crud_stats
- label_pairs: []
value: 3
metric_name: tnt_crud_space_not_found
...
```

`select` section additionally contains `details` collectors.
```lua
crud.stats('my_space').select.details
Expand All @@ -661,7 +702,10 @@ crud.stats('my_space').select.details
(including those not executed successfully). `tuples_fetched`
is a count of tuples fetched from storages during execution,
`tuples_lookup` is a count of tuples looked up on storages
while collecting response for call.
while collecting response for call. In `metrics` registry they
are stored as `tnt_crud_map_reduces`, `tnt_crud_tuples_fetched`
and `tnt_crud_tuples_lookup` metrics with
`{ operation = 'select', name = space_name }` labels.

## Cartridge roles

Expand Down
Loading

0 comments on commit 94a461e

Please sign in to comment.