Bug #10957

Warning error on "Monitor/Statistics" webpage

Added by Claudiu Nagy over 1 year ago. Updated about 1 month ago.

Status:Closed
Priority:Normal
Assigned To:Tomer Brisker
Category:Statistics
Target version:-
Difficulty: Bugzilla link:
Found in release: Pull request:https://github.com/theforeman/foreman/pull/4143
Story points-
Velocity based estimate-
Release1.14.1Release relationshipAuto

Description

Due to some limitations/bugs in linux containers sometimes the value returned by facter for memoryfree is not correct. It does not contain the unit of measure (MB, GB, etc). I have such a case and in the database where there is a value for memoryfree of "8.00 " . Because of that value the "Monitor/Statistics" can't be accessed with the below warning:

RuntimeError
Unknown string: "8.00 "!
lib/core_extensions.rb:139:in `rescue in to_gb'
lib/core_extensions.rb:128:in `to_gb'
app/models/fact_value.rb:101:in `block in to_gb'
app/models/fact_value.rb:100:in `to_gb'
app/models/fact_value.rb:58:in `mem_average'
app/controllers/statistics_controller.rb:9:in `index'
app/controllers/concerns/application_shared.rb:13:in `set_timezone'
app/models/concerns/foreman/thread_session.rb:32:in `clear_thread'
lib/middleware/catch_json_parse_errors.rb:9:in `call'
lib/core_extensions.rb:129:in `to_gb'

Looking at the "to_gb" ruby code in "lib/core_extensions.rb" i was under the impression that such a case should work:

      case unit.to_sym
      when nil, :B, :byte          then (value.to_f / Foreman::SIZE[:giga])

But of course it doesn't.

Should a situation where memoryfree equals "8.00 " (no unit in there) give an error or should it work?

P.S. I do have a patch for "to_gb" that will work if the value is similar to "8.00 ".

Associated revisions

Revision fc2fc7ac
Added by Tomer Brisker 2 months ago

Fixes #10957 - Correctly handle to_gb when no unit given

History

#1 Updated by Dominic Cleal over 1 year ago

  • Category set to Statistics

I'm not sure which is the best course of action. Ideally the fact would be fixed in facter/ohai etc, or we could put a workaround into a fact parser to add the expected unit if it's a common, unfixed bug.

Otherwise I'd probably suggest changing to_gb in app/models/fact_value.rb instead to ignore the fact rather than changing the to_gb method to assume a unit.

The nil in the case statement doesn't help as it's failing to match the regexp earlier on, since the unit there is expected and not optional.

#2 Updated by Claudiu Nagy over 1 year ago

I agree that the value should be ignored. At least in my case the value is not correct and is just invalidating my statistics for that fact. Another option is to discard the value when it is inserted in the database.

#3 Updated by Inixi Noisse over 1 year ago

in the file lib/core_extensions.rb you should change line 129 to:
value, _, unit=self.match(/(\d+(\.\d+)?) ?(([KMGT]|GiB|GB|B?|B))$/i)[0..3]

and also add appropriate case switch

#4 Updated by The Foreman Bot 2 months ago

  • Status changed from New to Ready For Testing
  • Assigned To set to Tomer Brisker
  • Pull request https://github.com/theforeman/foreman/pull/4143 added

#5 Updated by Anonymous 2 months ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#6 Updated by Dominic Cleal about 1 month ago

  • Release set to 1.14.1

Also available in: Atom PDF