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

Feature: Add Puppet Classes view #799

Merged
merged 18 commits into from
Apr 4, 2023

Conversation

lcharreau
Copy link

Hello,
Recently, in order to better monitor our Puppet nodes, we needed to add a Class view in Puppetboard.

This view lists the Puppet classes that have had at least one of their resources changed (event). It consists of extracting the resource events from the last report of each node and grouping these events by class.
For each class, we display the number of nodes having executed a resource declared in this class, as well as the number of events by status ('failure', 'success' and 'noop').

The main drawback of this view (which is disabled by default) is that it is potentially resource-consuming since it requires parsing the last report of each node and classifying the events by class.
This heavy processing pushed us to add a cache system to store the results but also a scheduler to pre-compute these results so that they are available more quickly to the user.
If you have more than one worker, it is recommended to use a shared backend like Memcached (that's what we do).
To display the class view, we retrieve the pre-computed result (by a scheduled job triggered at regular intervals, every 5mn in our case) from the cache and we parse only the new reports (i.e. those generated after the caching and which are therefore not present in the cache). We take advantage of this to update the cache. For information, we automatically run Puppet agent every 4 hours.

When we click on a class, we display the view by class. This view allows listing all the nodes whose last report has executed (event) at least one resource declared in the class. The status of the node is also displayed as well as the status of the class (which corresponds to a global status of the resource events).

I submit this new feature without knowing if it can interest the Puppet community.

Screenshot (Classes view)
classes

Screenshot (Class view)
class

docker-compose configuration used to test this new view:

services:
  puppetboard:
    container_name: puppetboard
    hostname: puppetboard
    image: puppboard:4.2.3_xxx
    restart: always
    ports:
    - 127.0.0.1:8082:80
    volumes:
    - "/etc/puppetlabs/puppetdb/ssl:/etc/puppetlabs/puppetdb/ssl:ro"
    extra_hosts:
    - hostname-puppetdb:192.168.10.10
    environment:
    - PUPPETBOARD_WORKERS=5
    - PUPPETDB_HOST=hostname-puppetdb
    - PUPPETDB_PORT=8081
    - PUPPETDB_PROTO=https
    - PUPPETDB_SSL_VERIFY=/etc/puppetlabs/puppetdb/ssl/ca.pem
    - PUPPETDB_KEY=/etc/puppetlabs/puppetdb/ssl/private.pem
    - PUPPETDB_CERT=/etc/puppetlabs/puppetdb/ssl/public.pem
    - ENABLE_CLASS=True
    - SCHEDULER_ENABLED=True
    - CACHE_TYPE=MemcachedCache
    - UNRESPONSIVE_HOURS=16
    networks:
      app_net:
        ipv4_address: 10.10.30.10
  memcached:
    container_name: memcached
    hostname: memcached
    restart: always
    image: memcached:latest
    networks:
      app_net:
        ipv4_address: 10.10.30.11

networks:
  app_net:
    driver: bridge
    ipam:
      driver: default
      config:
      - subnet: 10.10.30.0/24

Louis Charreau added 18 commits March 7, 2023 16:51
The Class view is disabled by default.
- Install library for memcached backend to store cached objects.
- Use `--preload` flag to tell Gunicorn to load the app before forking the worker processes
  It creates the scheduler instance in order to trigger scheduled jobs at
  startup.
…rvalsi

It pre-compute the results to display in the classes view/
The result contains the events associated with the last reports and is
stored in the cache.
It displays a table with the list of nodes having at least one event
on a resource declared in a given class.
For each node, it also displays the status of the node as well as the
status of the class (aka the status of the resources that are declared
in this class).
Classes view displays a list of classes that had at least one event on a declared resource.
For each class, we have the number of nodes having executed this class (with at least one change on a resource declared in the class), the number of events by status ('failure', 'success', 'noop').
- Added screenshots
- Defined new App settings
- Flask-APScheduler is used to create scheduled jobs, triggered at
  regular intervals in order to pre-computed data for the Classes view
- Flask-Caching is used to store some results into a cache
This view displays the classes having had at least one event on one of their declared resources. We have to parse the last report of each node to group the events by class.
For each class, we display the number of nodes having executed this class as well as the number of events by status ('failure', 'success' and 'noop').

When we click on a class we display the class view which allows to list the nodes having executed this class (with at least one status change of a resource of this class).
@codecov
Copy link

codecov bot commented Mar 26, 2023

Codecov Report

Patch coverage: 36.65% and project coverage change: -8.29 ⚠️

Comparison is base (d519561) 85.55% compared to head (ff2f806) 77.27%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #799      +/-   ##
==========================================
- Coverage   85.55%   77.27%   -8.29%     
==========================================
  Files          19       20       +1     
  Lines        1087     1307     +220     
==========================================
+ Hits          930     1010      +80     
- Misses        157      297     +140     
Impacted Files Coverage Δ
puppetboard/views/classes.py 21.95% <21.95%> (ø)
puppetboard/core.py 79.31% <60.00%> (-6.74%) ⬇️
puppetboard/app.py 84.28% <100.00%> (+0.95%) ⬆️
puppetboard/default_settings.py 100.00% <100.00%> (ø)
puppetboard/docker_settings.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@gdubicki
Copy link
Contributor

Hi @lcharreau!

Thank you for your contribution. I think that it’s ok to merge it if the added feature is behind a feature flag and if it requires Memcache config to start the app only if this feature flag is enabled. Does it work this way?

@lcharreau
Copy link
Author

Hello @gdubicki,

thank you for your support.
Yes by default the "Classes" view is disabled, so no need to have a backend available for the cache (ENABLE_CLASS).

The default cache backend is "SimpleCache" (in memory), which is acceptable when you have only one worker.
However, if you configure more than one worker, it is recommended to use a shared backend like "MemcachedCache".
The type of backend is configured via the CACHE_TYPE variable.

As I explained in my previous post, you can also add a scheduled task to pre-compute the results at regular intervals (SCHEDULER_ENABLED). By default, this is also disabled.

To have the complete detail of the variables related to this functionality, you can refer to the variables defined in the puppetboard/docker_settings.py and puppetboard/default_settings.py files.

@gdubicki gdubicki merged commit 0e26b9a into voxpupuli:master Apr 4, 2023
@gdubicki
Copy link
Contributor

gdubicki commented Apr 4, 2023

Released in v4.3.0 a moment ago. 😊

@gdubicki gdubicki mentioned this pull request May 28, 2023
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.

2 participants