Skip to content

Commit 786493d

Browse files
Fix the Redis instance average command time showing 0 or 1 (#14258)
meter_redis_instance_average_time_spent_by_command divided the lifetime counters redis_commands_duration_seconds_total and redis_commands_total and then took rate('PT1M') of the ratio. That is how fast the lifetime average drifts, not the average time of a command. Divide the rate of the command time by the rate of the command count, with safeDiv for commands idle in the window, and report the average in microseconds. A meter value is stored as a whole number, and any value between 0 and 1 is stored as 1, so an average in seconds, far below 1 for Redis, would show 1 for every command that ran. The MAL script test input now spends 200 microseconds per command, so the test pins the scale. The Redis monitoring doc gives the unit as microseconds and names the instance metric.
1 parent e2c132f commit 786493d

4 files changed

Lines changed: 6 additions & 5 deletions

File tree

‎docs/en/changes/changes.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
* LAL: the v2 compiler runs a rule as Groovy LAL did, or fails its compilation naming what it does not support, where it dropped or rewrote parts (an `abort {}` in an extractor's `if`, a nested `if` in a sink, method chains after `tag()` and the other functions, casts, the order of samplers); lal.md lists the differences from Groovy LAL that v2 keeps. `as Boolean` converts a boolean, the text `true` or `false` in any case, and a number or a text holding one by zero (0 false, any other true), and fails the log on any other value (`"yes"`). A standard field statement (`service`, `instance`, `endpoint`, `traceId`, `segmentId`, `spanId`, `timestamp`) also sets what later reads of the log and the traffic it builds see: `lal/nginx.yaml`'s error-log metric takes the parsed time, `lal/miniprogram.yaml` builds instance and endpoint traffic and `lal/ios-metrickit.yaml` instance traffic, the slow-SQL rules' service traffic uses `parsed.service`, and the network-profiling rules of `lal/k8s-service.yaml`, `lal/mesh-dp.yaml` and `lal/envoy-als.yaml` write no sampled trace for a log without its `client_process` or `server_process`; `lal/ios-metrickit.yaml` aborts, as written, a log whose `name` tag does not start with `metrickit.diagnostic.`.
9898
* OAL: a script that compiled into something other than what it says now does what it says or fails the compilation with its source location: statements after a stray token or an unterminated comment were dropped, surplus or missing function arguments were ignored or reached another overload, string, escape, `100L`, `1_000` and `in [...]` literals were misread, a comparison across types, a `like` without `%`, an out-of-range number and a double passed to a long parameter matched or computed wrongly, and `percentile2(0)` and `histogram(0, ...)` failed every event. A generated class the JVM verifier rejects fails the compilation instead of the boot, and a from() attribute no function reads or a `disable(...)` naming no stream, or one already defined outside `disable.oal`, is logged as a warning; see oal.md.
9999
* TAL: a rule runs as written or fails its compilation naming what is wrong, where parts of it were dropped, replaced or read as something else (a repeated `metrics {}` clause or tag key, an unknown type after `as`, a misspelled layer, a method on a literal, a `log` argument beyond its placeholders), and two rules of one name, or two candidate files for one listed name, fail the boot. Values evaluate as LAL's: a cast that does not convert fails the span, conditions use Groovy truth, a whole-number quotient stays exact until its destination converts it (the shipped nanosecond-to-millisecond conversions are unchanged), and a leading-0 integer is octal; see tal.md. The shipped `otlp-general` `attr(...) as Double >= 400` fails a span whose status code is text that is no number, and a padded native `transmission.latency` tag reads where the Java analyzer failed the segment.
100+
* Fix the Redis instance `meter_redis_instance_average_time_spent_by_command` showing 0 or 1 instead of the average time of a command. The rule divided the two lifetime counters `redis_commands_duration_seconds_total` and `redis_commands_total` first and took the rate of that ratio, which is how fast the lifetime average drifts. It now divides the rate of the command time by the rate of the command count, and reports `0` for a command that did not run in the window. The metric is now in microseconds, not seconds: a meter value is stored as a whole number, so an average below 1 second was stored as 1. Values stored before the upgrade keep the old numbers.
100101

101102
#### UI
102103

‎docs/en/setup/backend/backend-redis-monitoring.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Each Redis server is cataloged as an `Instance` in OAP.
2424
| Blocked Clients | | meter_redis_blocked_clients | The number of blocked clients. | redis-exporter |
2525
| Memory Max Bytes | MB | meter_redis_memory_max_bytes | The max bytes of memory. | redis-exporter |
2626
| Hits Rate | % | meter_redis_hit_rate | Hit rate of redis when used as a cache. | redis-exporter |
27-
| Average Time Spend By Command | second | meter_redis_average_time_spent_by_command | Average time to execute various types of commands. | redis-exporter |
27+
| Average Time Spend By Command | microsecond | meter_redis_instance_average_time_spent_by_command | Average time to execute various types of commands. | redis-exporter |
2828
| Total Commands Trend | | meter_redis_total_commands_rate | The Trend of total commands. | redis-exporter |
2929
| DB keys | | meter_redis_evicted_keys_total </br> meter_redis_expired_keys_total </br> meter_redis_db_keys | The number of Expired / Evicted / total keys. | redis-exporter |
3030
| Net Input/Output Bytes | KB | meter_redis_net_input_bytes </br> meter_redis_net_output_bytes | Total bytes of input / output of redis net. | redis-exporter |

‎oap-server/analyzer/meter-analyzer-scripts-test/src/test/resources/scripts/mal/test-otel-rules/redis/redis-instance.data.yaml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ input:
7474
host_name: test-host
7575
cmd: get
7676
service_instance_id: test-instance
77-
value: 100.0
77+
value: 0.02
7878
expected:
7979
meter_redis_instance_uptime:
8080
entities:
@@ -198,7 +198,7 @@ expected:
198198
host_name: 'redis::test-host'
199199
cmd: get
200200
service_instance_id: test-instance
201-
value: 0.0
201+
value: 200.0
202202
meter_redis_instance_commands_duration_seconds_total_rate:
203203
entities:
204204
- scope: SERVICE_INSTANCE
@@ -210,4 +210,4 @@ expected:
210210
host_name: 'redis::test-host'
211211
cmd: get
212212
service_instance_id: test-instance
213-
value: 25.0
213+
value: 0.005

‎oap-server/server-starter/src/main/resources/otel-rules/redis/redis-instance.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ metricsRules:
6464
exp: redis_blocked_clients
6565

6666
- name: instance_average_time_spent_by_command
67-
exp: (redis_commands_duration_seconds_total.sum(['host_name','cmd','service_instance_id']) / redis_commands_total.sum(['host_name','cmd','service_instance_id'])).rate('PT1M')
67+
exp: redis_commands_duration_seconds_total.sum(['host_name','cmd','service_instance_id']).rate('PT1M').safeDiv(redis_commands_total.sum(['host_name','cmd','service_instance_id']).rate('PT1M')) * 1000000
6868
- name: instance_commands_duration_seconds_total_rate
6969
exp: redis_commands_duration_seconds_total.sum(['host_name','cmd','service_instance_id']).rate('PT1M')

0 commit comments

Comments
 (0)