Skip to content

Commit 6cc736f

Browse files
Tanishq-Choudharywu-sheng
authored andcommitted
Fix the Redis instance average command time showing 0 or 1
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 0a862ab commit 6cc736f

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
@@ -89,6 +89,7 @@
8989
* The OTLP log receiver keeps a record whose attributes repeat a key, and the logs of a resource whose attributes repeat one, with the key's last value, instead of losing the record, or every log of the export request, to a duplicate-key error.
9090
* Fix a LAL rule applied through the runtime-rule API being attributed to `lal/lal/<name>.yaml`, the catalog prefix applied twice, in its error messages and its generated class; it is now `lal/<name>.yaml`, as the same file loaded at boot.
9191
* Log tag autocomplete keeps the tags of the logs received through OTLP apart from those of every other source, under the new tag type `OTLP_LOG`. `queryLogTagAutocompleteKeys` and `queryLogTagAutocompleteValues` take an optional `type` (`LOG` or `OTLP_LOG`) to read one source; without it, as the UI and LogQL query, they return both merged, within the same limit. The OTLP logs' tags written before the upgrade stay under `LOG`, so a query with `type: OTLP_LOG` misses them until they expire. Both are read in one storage query: `ITagAutoCompleteQueryDAO` takes a list of tag types, so a storage plugin outside this repository that implements it has to follow.
92+
* 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.
9293

9394
#### UI
9495

‎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 | μs | 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)