Skip to content

Fix the Redis instance average command time staying near zero - #14258

Merged
wu-sheng merged 1 commit into
apache:masterfrom
Tanishq-Choudhary:fix-redis-avg-command-time
Nov 23, 2026
Merged

wu-sheng merged 1 commit into
apache:masterfrom
Tanishq-Choudhary:fix-redis-avg-command-time

Conversation

@Tanishq-Choudhary

Copy link
Copy Markdown
Contributor

Fix the Redis instance meter_redis_instance_average_time_spent_by_command staying near zero

  • Add a unit test to verify that the fix works.
  • Explain briefly why the bug exists and how to fix it.

The instance rule divided the two lifetime counters from redis_exporter first and then took rate('PT1M') of the ratio:

(redis_commands_duration_seconds_total.sum([...]) / redis_commands_total.sum([...])).rate('PT1M')

That ratio is the lifetime average time per command. Its per-second rate is how fast that lifetime average drifts, which is close to 0 on any Redis that has been up for a while, and can go negative. The "Avg Command Time" panel of the Redis instance dashboard reads this metric, so it shows about 0 for every command.

The rule now takes the rate of each counter and divides them, the same shape the BanyanDB rules use for latency per call:

redis_commands_duration_seconds_total.sum([...]).rate('PT1M').safeDiv(redis_commands_total.sum([...]).rate('PT1M'))

safeDiv gives 0 for a command that did not run in the window, instead of NaN.

The MAL script test expected 0.0 for this metric. Its input moves the duration and count counters by the same amount in 2 seconds (25/s each), so the average time per command is 1.0. The expectation is now 1.0; on master the test fails with expected=1.0, actual=0.0.

Values stored before the upgrade keep the old near-zero numbers, so the chart steps at the upgrade.

  • Update the CHANGES log.

  • GraalVM distro impact:

    • None.
    • Impacted, by: bundled rule files. Edits the instance_average_time_spent_by_command expression in otel-rules/redis/redis-instance.yaml; the distro compiles it as it is.

@wu-sheng
wu-sheng force-pushed the fix-redis-avg-command-time branch from 1ab795f to 6cc736f Compare November 23, 2026 13:38
@wu-sheng

wu-sheng commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Thanks @Tanishq-Choudhary, the diagnosis is right: the old rule took the rate of the lifetime average, not the average of the window. I pushed a fix-up to your branch, squashed into your commit (you stay the author), because the new rule alone still wouldn't give a useful panel.

Why the rule needs a scale. OAP stores a MAL meter value as a whole number. Analyzer.getValue (oap-server/analyzer/meter-analyzer/.../v2/Analyzer.java) turns any value between 0 and 1 into 1. A Redis command takes microseconds, so the average in seconds is tiny: a GET at 2 µs is 0.000002, stored as 1. The "Avg Command Time" panel would show 1 for every command that ran and 0 for idle ones. The old rule gave the same 0-or-1 picture. The MAL script test doesn't catch it, because it checks the double before that rounding, and its input gave exactly 1 second per command.

The BanyanDB latency rules you modelled this on handle it the same way: they end in * 1000 to report milliseconds. Milliseconds aren't enough for Redis (2 µs is still 0.002), so this rule ends in * 1000000 and reports microseconds.

What changed in the push:

  • redis-instance.yaml: ... .safeDiv(...) * 1000000.
  • redis-instance.data.yaml: the duration counter input is 0.02 instead of 100.0, so the test spends 200 µs per command and the expected average is 200.0. With the input changed, meter_redis_instance_commands_duration_seconds_total_rate expects 0.005 instead of 25.0. I checked that the test fails with expected=1.0, actual=200.0 if the scale is missing.
  • backend-redis-monitoring.md: the unit is microsecond, not second, and the row names the real metric, meter_redis_instance_average_time_spent_by_command.
  • changes.md: the entry says the old values were 0 or 1 and that the metric is now in microseconds.

The Horizon UI panel title gets the unit in apache/skywalking-horizon-ui#226.

If you have local work on this branch, save it before git fetch && git reset --hard origin/fix-redis-avg-command-time.

@wu-sheng
wu-sheng force-pushed the fix-redis-avg-command-time branch from 6cc736f to e91f8cd Compare November 23, 2026 13:39
@wu-sheng wu-sheng added this to the 11.2.0 milestone Nov 23, 2026
@wu-sheng wu-sheng added the bug Something isn't working and you are sure it's a bug! label Nov 23, 2026
wu-sheng added a commit to apache/skywalking-horizon-ui that referenced this pull request Nov 23, 2026
apache/skywalking#14258 fixes meter_redis_instance_average_time_spent_by_command,
which showed 0 or 1 for every command, and reports it in microseconds.
Title the Redis node dashboard's widget Avg Command Time (microseconds),
in English and the seven translations, and give the unit in the Redis
dashboard doc.
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.
@wu-sheng
wu-sheng force-pushed the fix-redis-avg-command-time branch from e91f8cd to f0eb580 Compare November 23, 2026 13:56
@Tanishq-Choudhary

Copy link
Copy Markdown
Contributor Author

Makes sense, thanks for the fix-up.

wu-sheng added a commit to apache/skywalking-horizon-ui that referenced this pull request Nov 23, 2026
…226)

apache/skywalking#14258 fixes meter_redis_instance_average_time_spent_by_command,
which showed 0 or 1 for every command, and reports it in microseconds.
Title the Redis node dashboard's widget Avg Command Time (microseconds),
in English and the seven translations, and give the unit in the Redis
dashboard doc.
@wu-sheng
wu-sheng merged commit 786493d into apache:master Nov 23, 2026
537 of 542 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working and you are sure it's a bug!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants