Skip to content

Add support for DLO automatic cleanup#278

Merged
austb merged 2 commits into
puppetlabs:masterfrom
bastelfreak:systemd
Jul 24, 2018
Merged

Add support for DLO automatic cleanup#278
austb merged 2 commits into
puppetlabs:masterfrom
bastelfreak:systemd

Conversation

@bastelfreak

Copy link
Copy Markdown
Collaborator

No description provided.

@bastelfreak

Copy link
Copy Markdown
Collaborator Author

This is WIP. Let me know if you're interested in this and I will add tests + README.md updates.

Comment thread Gemfile Outdated
gem 'rake'
gem 'puppetlabs_spec_helper', :require => false
# Pinning due to bug in newer rspec with Ruby 1.8.7
gem 'rspec-core', '3.1.7'

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I run into some issues while running the tests locally. For debugging I removed the pinning.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We shouldn't need to support such an old Ruby version anymore, so this should be ok.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I rebased against the release branch to get all this fixed. I hope that was okay.

@austb austb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We are still discussing the details around the customization options for cleanup frequency. I'll get back to this PR as soon as I have more information. Thanks for your contributions!

Comment thread manifests/server.pp Outdated
-> systemd::unit_file{'puppetdb-cleanup.timer':
content => epp("${module_name}/puppetdb-DLO-cleanup.timer.epp"),
}
-> service{'puppetdb-cleanup.timer':

@austb austb Jul 16, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This needs to be a ~> so that the service will be restarted if the puppetdb-cleanup.timer file changes.

As an alternative, it looks like the ~> service block can be omitted entirely with something like this (which I pulled from the README)

systemd::unit_file { 'foo.service':
 source => "puppet:///modules/${module_name}/foo.service",
 enable => true,
 active => true,
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

After months of work, this feature is finally released. It wasn't available when when I created this PR. updated the code.

Comment thread manifests/server.pp Outdated
if $facts['systemd'] {
# deploy a systemd timer + service to cleanup old reports
# https://puppet.com/docs/puppetdb/5.2/maintain_and_tune.html#clean-up-the-dead-letter-office
systemd::unit_file{'puppetdb-cleanup.service':

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should rename this to puppetdb-dlo-cleanup.service (and the matching timer one below) in case we want to add another cleanup service in the future.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

sounds good, done

Comment thread manifests/server.pp Outdated
}
-> service{'puppetdb-cleanup.timer':
ensure => 'running',
enable => true,

@austb austb Jul 16, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think the enable option is necessary here, but I could be mistaken.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It needs to be enabled. Otherwise the timer is off after the next reboot and the upcoming puppet run would start it.


[Timer]
# Daily at 8am
OnCalendar=*-*-* 08:0:00

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should choose the time of day via fqdn_rand. If there are multiple PuppetDB VMs running on the same physical machine this will prevent them from hammering the disk at the same time.

Also the comment will no longer be accurate, so you can remove it or replace it with a general comment about running once a day with a link to documentation on the systemd timer syntax

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could select the hour with fqdn_rand(24) and the minutes with fqdn_rand(60).

Comment thread manifests/server.pp
}

if $automatic_dlo_cleanup {
if $facts['systemd'] {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If systemd does not exist, lets try setting up a cron job to clean this up instead. For example Redhat 6 has cron but not systemd.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

@austb

austb commented Jul 17, 2018

Copy link
Copy Markdown
Contributor

@bastelfreak These comments are done and ready for you to take a look at.


[Service]
Type=oneshot
ExecStart=/usr/bin/find /opt/puppetlabs/server/data/puppetdb/stockpile/discard/ -type f -mtime +90 -delete

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, one final note. For security reasons, this service should run as the PuppetDB user

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

added user and group

@bastelfreak bastelfreak force-pushed the systemd branch 2 times, most recently from cd9f333 to 1923209 Compare July 19, 2018 19:55
@bastelfreak

Copy link
Copy Markdown
Collaborator Author

Personal reminder:

  • should add tests
  • Update readme
  • expose maximum DLO age as variable

@austb

austb commented Jul 19, 2018

Copy link
Copy Markdown
Contributor

Awesome! This looks good. If you need any help writing tests just let us know and we can help out. I would say these would be nice.

  1. Can be disabled (ie. creates neither the service/timer nor the cronjob)
  2. Creates systemd service/timer, and starts timer
  3. Creates cron job if systemd not available
  4. Actually runs as puppetdb user. ie cannot perform some action the PuppetDB user should not be able to do (we can chat about this if it's unclear what to do, I'll have to think about it as well)

And if you add DLO age as variable, a test that that can be customized.

@bastelfreak bastelfreak force-pushed the systemd branch 2 times, most recently from 8b60736 to 7a2bc12 Compare July 20, 2018 20:21

@rbrw rbrw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a few comments with respect to the travis and sh bits. Thanks.

Comment thread .travis.yml Outdated
- rm -f Gemfile.lock
- gem update --system
- gem --version
- bundle -v

@rbrw rbrw Jul 23, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd suggest either moving these to a helper script,

before_install: some/where/prep-tests

or using a different approach, i.e. say with one of the yaml multi-line sytaxes.

For example, using ">":

before_install: >
    set -ex
    && bundle -v 
    && rm -f Gemfile.lock
    && ...

or using "|"

before_install: |
    set -ex
    bundle -v 
    rm -f Gemfile.lock
    ...

(Note that syntax is just approximate -- haven't checked it.)

Otherwise, travis will just keep going iirc. That is, it runs all the bullet points, even if one of them fails, only stopping if there was a failure after it has tried them all.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rbrw these changes are from the rebase, I'll address them in pr #279

Comment thread .travis.yml
- gem --version
- bundle -v
script:
- 'bundle exec rake $CHECK'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, do we need the single quotes, and regardless, wonder if we should quote the CHECK expansion as "$CHECK", just to avoid having to worry about the content.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rbrw see above, will address in #279

@Zak-Kent

Copy link
Copy Markdown
Contributor

@bastelfreak, sorry but would you be able to rebase this on master again? We ended up making some changes/rebasing the existing pr we had up before it merged. Thanks for all the help!

@bastelfreak bastelfreak changed the title [WIP] add support for DLO automatic cleanup Add support for DLO automatic cleanup Jul 24, 2018
@bastelfreak

Copy link
Copy Markdown
Collaborator Author

@austb can you review this again please?

There is also a small change to a string that needed to be
double quoted.
@austb austb merged commit 4e4e81a into puppetlabs:master Jul 24, 2018
@austb

austb commented Jul 24, 2018

Copy link
Copy Markdown
Contributor

Thanks @bastelfreak for the PR!

@bastelfreak bastelfreak deleted the systemd branch July 24, 2018 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants