Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add errorhandling for missing cache in ranked statistics #2563

Merged
merged 6 commits into from Mar 22, 2023

Conversation

stveit
Copy link
Contributor

@stveit stveit commented Jan 26, 2023

Fixes #2561

Error from cache not being configured should not be handled. When trying to get data from cache, it will now behave as if the cache is empty. When trying to write, it will now just skip the writing step instead of crashing.
An error message will be displayed on the ranked statistics page as well.

@stveit stveit self-assigned this Jan 26, 2023
@github-actions
Copy link

github-actions bot commented Jan 26, 2023

Test results

     12 files       12 suites   11m 0s ⏱️
3 216 tests 3 120 ✔️   96 💤 0
9 123 runs  8 835 ✔️ 288 💤 0

Results for commit 199cb16.

♻️ This comment has been updated with latest results.

@codecov
Copy link

codecov bot commented Jan 26, 2023

Codecov Report

Merging #2563 (199cb16) into 5.6.x (af1d17e) will decrease coverage by 0.04%.
The diff coverage is 38.09%.

@@            Coverage Diff             @@
##            5.6.x    #2563      +/-   ##
==========================================
- Coverage   53.75%   53.72%   -0.04%     
==========================================
  Files         558      558              
  Lines       40587    40605      +18     
==========================================
- Hits        21819    21815       -4     
- Misses      18768    18790      +22     
Impacted Files Coverage Δ
python/nav/web/sortedstats/views.py 55.95% <38.09%> (-8.23%) ⬇️
python/nav/ipdevpoll/pool.py 84.88% <0.00%> (-5.04%) ⬇️
python/nav/ipdevpoll/plugins/statsystem.py 29.13% <0.00%> (-0.20%) ⬇️
python/nav/web/info/images/utils.py 52.50% <0.00%> (+12.50%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't run a manual test (yet), but this looks solid enough 😄 I only have two inline suggestions.

Also, one big request: This really solves a problem with a new function that was introduced in 5.6.0. IMO, this belongs in a 5.6.1 patch release, so this should be rebased to the 5.6.x branch and the base of this PR updated to that branch.

if result and not result.data:
result = None
except InvalidCacheBackendError as e:
_logger.error("Error accessing cache for ranked statistics: %s".format(e))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log statement appears to use some inconsistent string formatting techniques. As always, when using loggers, I suggest using the built-in string formatting of the logger object, which ensures that time is spent to format the arguments only if the current log level dictates that this log record should be emitted:

Suggested change
_logger.error("Error accessing cache for ranked statistics: %s".format(e))
_logger.error("Error accessing cache for ranked statistics: %s", e)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

cache = get_cache()
cache.set(cache_key, result, timeout=timeout)
except InvalidCacheBackendError as e:
_logger.error("Error accessing cache for ranked statistics: %s".format(e))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log statement appears to use some inconsistent string formatting techniques. As always, when using loggers, I suggest using the built-in string formatting of the logger object, which ensures that time is spent to format the arguments only if the current log level dictates that this log record should be emitted:

Suggested change
_logger.error("Error accessing cache for ranked statistics: %s".format(e))
_logger.error("Error accessing cache for ranked statistics: %s", e)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@stveit stveit changed the base branch from master to 5.6.x February 22, 2023 09:13
@sonarcloud
Copy link

sonarcloud bot commented Feb 22, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@stveit
Copy link
Contributor Author

stveit commented Feb 22, 2023

rebased on 5.6.x and base changed to such

Copy link
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spot on! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Missing cache config for ranked statistics can take down whole NAV site
2 participants