Wrong memory percentage on /admin/reports/redis

Created on 12 January 2021, almost 4 years ago
Updated 31 August 2024, 4 months ago

Problem/Motivation

        '@used_percentage' => (int) ($info['used_memory'] ?? $info['Memory']['used_memory'] / $memory_config['maxmemory'] * 100),

The origin code is interpreted to

$used_percentage;
 
if (!isset($info['used_memory'])) {
   $used_percentage = (int) ($info['Memory']['used_memory'] / $memory_config['maxmemory'] * 100)
}
else {
  $used_percentage = (int) $info['used_memory'];
}

Steps to reproduce

Proposed resolution

Add () to $info['used_memory'] ?? $info['Memory']['used_memory']

        '@used_percentage' => (int) (($info['used_memory'] ?? $info['Memory']['used_memory']) / $memory_config['maxmemory'] * 100),

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇨🇳China jungle Chongqing, China

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇦🇺Australia thomwilhelm Sydney

    +1, just adding a patch here for people using composer patches.

    Hopefully this can get merged!

  • 🇬🇧United Kingdom Alina Basarabeanu

    Patch from #10 fixed the issue in Drupal Version 9.5.10 and redis 1.7.0.
    Can this be merged into the next stable release?
    Thank you

  • 🇳🇱Netherlands Dobefu

    I feel like this solution is not very future-proof, as it casts any data type to an integer. This would mean that the percentage would also break in the event that you set the max memory to 1GB and the amount used is in MBs. I feel like the solution would be to first parse the values to their count in bytes.

  • 🇦🇺Australia thomwilhelm Sydney

    Hi @Dobefu the module was already performing this cast so it wouldn't break anything, see the diff. It's just correcting a math error in the original design.

    Other cases not handled can be tackled in follow up issues.

  • 🇳🇱Netherlands Dobefu

    That's probably fair. I do feel like the cast shouldn't happen, but I agree that this isn't the issue to be discussing that

  • Status changed to Needs work 4 months ago
  • 🇨🇭Switzerland berdir Switzerland

    the cast is applied to the result of the divide, to avoid displaying a float, it's basically a round().

    However, the MR doesn't apply anymore.

  • Pipeline finished with Skipped
    4 months ago
    #256880
  • Status changed to Fixed 4 months ago
  • 🇨🇭Switzerland berdir Switzerland

    Rebased and added new test coverage for the status report page, including the percentage and also discovered a bug in another recently committed issue that I had to revert.

    Merged.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024