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

Actually activate inventory caching #97

Merged

Conversation

tadeboro
Copy link
Contributor

SUMMARY

The inventory plugin advertises support for caching, but the implementation was missing the required pieces to make it work properly.

This commit split the inventory construction into two stages. The first stage is responsible for fetching remote data (interacting with the DigitalOcean's API). The second stage extracts the relevant data from the API responses and populated the inventory.

Caching support then came almost for free. All we had to do is only fetch data if:

  1. User does not want to use cache at all.
  2. User does use cache and wants data refreshed.
  3. User does use cache, but the cache is empty.

Some additional logic makes sure we write the data to cache if data refresh is requested, but nothing too complex.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

community.digitalocean.digitalocean inventory plugin

@codecov
Copy link

codecov bot commented May 23, 2021

Codecov Report

Merging #97 (aa2fc1b) into main (e928762) will increase coverage by 7.03%.
The diff coverage is 14.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #97      +/-   ##
==========================================
+ Coverage   63.75%   70.78%   +7.03%     
==========================================
  Files          30        1      -29     
  Lines        2163       89    -2074     
  Branches      417       16     -401     
==========================================
- Hits         1379       63    -1316     
+ Misses        551       24     -527     
+ Partials      233        2     -231     
Impacted Files Coverage Δ
plugins/inventory/digitalocean.py 70.78% <14.28%> (-0.81%) ⬇️
plugins/modules/digital_ocean_tag.py
plugins/modules/digital_ocean_certificate.py
plugins/modules/digital_ocean_database_info.py
plugins/modules/digital_ocean_region_info.py
...lugins/modules/digital_ocean_load_balancer_info.py
plugins/modules/digital_ocean_balance_info.py
plugins/modules/digital_ocean_sshkey.py
plugins/modules/digital_ocean_tag_info.py
plugins/modules/digital_ocean_kubernetes_info.py
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e928762...aa2fc1b. Read the comment docs.

@tadeboro
Copy link
Contributor Author

Not sure what codecov did here, but those numbers are definitely broken. It looks like we are comparing full coverage with partial coverage (only lines that I changed), but since I do not use codecov personally, I have no experience with these things.

@mamercad
Copy link
Collaborator

mamercad commented May 24, 2021

@gundalow Can you help us with the failing codecov/patch test?

@mamercad mamercad self-requested a review May 24, 2021 23:42
Copy link
Collaborator

@mamercad mamercad left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this, LGTM:

❯ grep cache digitalocean.yml
cache: yes
cache_plugin: jsonfile
cache_timeout: 300
cache_connection: /tmp/do_inventory
cache_prefix: do_

❯ head /tmp/do_inventory/do_community.digitalocean.digitalocean_bccfds_7fdd2
[
    {
        "backup_ids": [],
        "created_at": "2021-05-24T23:40:20Z",
        "disk": 25,
        "features": [
            "private_networking"
        ],
        "id": 247480313,
        "image": {

@mamercad
Copy link
Collaborator

@tadeboro Want to add a quick changelog fragment?

Copy link
Collaborator

@mamercad mamercad left a comment

Choose a reason for hiding this comment

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

Changelog fragment please.

@tadeboro tadeboro force-pushed the fix-inventory-cache branch from 6dc9d2f to 51115c3 Compare May 25, 2021 17:29
@tadeboro
Copy link
Contributor Author

@mamercad I wanted to add a changelog fragment once I knew the PR number, but then the code coverage distracted me ;)

@gundalow
Copy link
Contributor

@gundalow Can you help us with the failing codecov/patch test?

Could you try changing codecov.yml to the following:

coverage:
  status:
    project:
      default:
        informational: true # Don't fail CI if percentage drops
    patch:
      default:
        informational: true # Don't fail CI if percentage drops

# Don't count lines of code in these directories
ignore:
    - tests
fixes:
  - "ansible_collections/community/digitalocean/::"

@tadeboro tadeboro force-pushed the fix-inventory-cache branch from 51115c3 to fc7b4b8 Compare May 31, 2021 10:16
The inventory plugin advertises support for caching, but the
implementation was missing the required pieces to make it work
properly.

This commit split the inventory construction into two stages. The
first stage is responsible for fetching remote data (interacting with
the DigitalOcean's API). The second stage extracts the relevant data
from the API responses and populated the inventory.

Caching support then came almost for free. All we had to do is only
fetch data if:

 1. User does not want to use cache at all.
 2. User does use cache and wants data refreshed.
 3. User does use cache but the cache is empty.

There is some additional logic that makes sure we write the data to
cache if data refresh is requested, but nothing too complex.
@tadeboro tadeboro force-pushed the fix-inventory-cache branch from fc7b4b8 to aa2fc1b Compare May 31, 2021 10:33
@tadeboro
Copy link
Contributor Author

I rebased the changes onto the main branch. The codecov is still complaining because the updated lines are not covered by unit tests. And while I can add tests to cover them just to make codecov happy, I would rather not. Why? Because I will need to mock 90% of the inventory plugin functionality just to cover three if statements. And such tests (tests that do not actually test any surrounding code) are worthless in the long run since they do not adapt to the changes in the core.

Copy link
Collaborator

@mamercad mamercad left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this!

@mamercad mamercad merged commit 82b45a3 into ansible-collections:main Jun 1, 2021
@tadeboro tadeboro deleted the fix-inventory-cache branch June 1, 2021 11:43
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.

3 participants