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 evm:db:dump:local and evm:db:dump:remote tasks #17483

Merged
merged 6 commits into from
May 31, 2018

Conversation

NickLaMuro
Copy link
Member

@NickLaMuro NickLaMuro commented May 25, 2018

Builds off of ManageIQ/manageiq-gems-pending#351 , which added pg_dump functionality back to the PostgresAdmin lib, and creates rake tasks for running a database dump to either a local file, of NFS/SMB share.

Notable changes

  • Refactors EvmDatabaseOps#backup so that EvmDatabaseOps#dump can leverage almost all of the same code.
  • Carbon copies the evm:db:backup tasks into evm:db:dump tasks.
  • Adds option to --exclude-table-data from the dump for specific tables

Links

Steps for Testing/QA

Not sure the best way to test that these work, but we probably should run some tests to confirm everything is behaving as expected. I will probably do some testing of this locally now that I have this up for review, and will report back with how I tested things for others to try as well.

Update: Here is what I did to test:

  • Found a db to dump on my local machine

  • Ran in the terminal:

    $ rake evm:db:dump:local -- --local-file tmp/vmdb_db_dump --dbname my_vmdb
  • Checked the log/evm.log to see that the commands run made sense:

    $ tail log/evm.log
    ...
    [----] I, [2018-05-25T17:17:16.749795 #46992:3ff54d03fa0c]  INFO -- : MIQ(PostgresAdmin.runcmd_with_logging) Running command... psql --no-password --dbname my_vmdb --command SELECT\ pg_database_size\(\'my_vmdb\'\)\;
    [----] I, [2018-05-25T17:17:16.769418 #46992:3ff54d03fa0c]  INFO -- : MIQ(EvmDatabaseOps.run_db_opt_for_new_uri) [my_vmdb] with database size: [100 bytes], free space at [tmp/vmdb_db_dump]: [200 bytes]
    [----] I, [2018-05-25T17:17:16.769763 #46992:3ff54d03fa0c]  INFO -- : MIQ(PostgresAdmin.runcmd_with_logging) Running command... pg_dump --no-password --format c --file tmp/vmdb_db_dump my_vmdb
    [----] I, [2018-05-25T17:18:25.311775 #46992:3ff54d03fa0c]  INFO -- : MIQ(EvmDatabaseOps.dump) [my_vmdb] database has been dumped up to file: [tmp/vmdb_db_dump]
  • Ran in the terminal:

    $ rake evm:db:dump:local --           \
        --local-file tmp/vmdb_db_dump_2   \
        --dbname my_vmdb                  \
        --exclude-table-data "metrics_*" "vim_performance_states" "event_streams"
  • Confirmed that the dump size was smaller and commands executed made sense:

    $ ls -lhtmp/vmdb_db_dump*
    -rw-r--r--  1 nicklamuro  staff   452M May 25 17:18 tmp/vmdb_db_dump
    -rw-r--r--  1 nicklamuro  staff   331M May 25 18:35 tmp/vmdb_db_dump_2
    $ tail log/evm.log
    ...
    [----] I, [2018-05-25T18:34:16.749795 #46993:3ff54d03fa0c]  INFO -- : MIQ(PostgresAdmin.runcmd_with_logging) Running command... psql --no-password --dbname my_vmdb --command SELECT\ pg_database_size\(\'my_vmdb\'\)\;
    [----] I, [2018-05-25T18:34:16.769418 #46993:3ff54d03fa0c]  INFO -- : MIQ(EvmDatabaseOps.run_db_opt_for_new_uri) [my_vmdb] with database size: [100 bytes], free space at [tmp/vmdb_db_dump]: [200 bytes]
    [----] I, [2018-05-25T18:34:16.769763 #46993:3ff54d03fa0c]  INFO -- : MIQ(PostgresAdmin.runcmd_with_logging) Running command... pg_dump --no-password --format c --file tmp/vmdb_db_dump my_vmdb --exclude-table-data metrics_\* --exclude-table-data vim_performance_states --exclude-table-data event_streams
    [----] I, [2018-05-25T18:35:25.311775 #46993:3ff54d03fa0c]  INFO -- : MIQ(EvmDatabaseOps.dump) [my_vmdb] database has been dumped up to file: [tmp/vmdb_db_dump]

@NickLaMuro NickLaMuro force-pushed the add_evm_db_dump_tasks branch 3 times, most recently from f1ed8cb to 6116691 Compare May 25, 2018 23:36
@NickLaMuro
Copy link
Member Author

@miq-bot assign @carbonin
@miq-bot add_labels enhancement, gaprindashvili/no

# :username => 'samba_one',
# :password => 'Zug-drep5s',
# :remote_file_name => "backup_1", - Provide a base file name for the uploaded file
private_class_method def self.run_db_opt_for_new_uri(db_opts, connect_opts = {})
Copy link
Member

Choose a reason for hiding this comment

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

This method name is not great. I would prefer we refactor this into more pieces to make the individual operations more obvious. For example, with_mount_session and check_free_space

Copy link
Member

Choose a reason for hiding this comment

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

Not sure why this was squashed .. will copy the comment into a separate one.

end

desc 'Dump the local ManageIQ EVM Database (VMDB) to a remote file'
task :remote do
Copy link
Member

Choose a reason for hiding this comment

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

Do we need the restore for the dump side of things?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Lol sorry, I read this as task :restore do
🤦‍♂️

Copy link
Member

Choose a reason for hiding this comment

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

To be more clear, I was suggesting removing this task because I thought it was restoring a pg_dump which I don't really want to do unless it was an old backup (from before we removed it as a backup option).

Copy link
Member Author

Choose a reason for hiding this comment

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

That is fair. Yeah, I really don't plan to support pg_dump restores myself. I have a fun set of directions for importing DBs when working on performance issues and such, so me personally, I only really care about getting the pg_dump stuff working from a "backup" perspective.

The fact that it "can work" in the :restore tasks is just a nice plus.

# :username => 'samba_one',
# :password => 'Zug-drep5s',
# :remote_file_name => "backup_1", - Provide a base file name for the uploaded file
private_class_method def self.run_db_opt_for_new_uri(action, db_opts, connect_opts = {})
Copy link
Member

Choose a reason for hiding this comment

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

This method name is not great. I would prefer we refactor this into more pieces to make the individual operations more obvious. For example, with_mount_session and check_free_space

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool, yeah, I can look into doing that. I agree, the name sucks.

cc @jrafanie #namingIsHard #botherLJWheneverPossible

Copy link
Member

Choose a reason for hiding this comment

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

I like naming things "run_things_and_stuff" to force myself to name it before merge. Sometimes, I leave it like that so someone else can provide a better name.

Copy link
Member

Choose a reason for hiding this comment

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

For me this is the only thing holding this PR up. @NickLaMuro are you going to try to refactor this or are you just looking for naming suggestions?

Copy link
Member Author

Choose a reason for hiding this comment

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

@carbonin actively looking at this right now actually.

I think your naming suggestions are pretty solid, so probably just going to go with them, but I am noticing that half of what I would do for with_mount_session is also needed for the EvmDatabaseOps.restore method as well, so pondering how I can that in as well.

Since I am splitting things up a bit now (where before, it was just a copy-pasta for the most part), I am taking my time to do it right. This is the disadvantage of going the full refactoring route, where I original just kinda did it half way. Splitting this up via your suggestion is the overall better approach in my opinion, just has the cost of time to implement.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good @NickLaMuro, just making sure 👍

@ManageIQ ManageIQ deleted a comment from NickLaMuro May 30, 2018
A helper method that will be used in future commits.  Also adds a few
specs to validate log output.
@NickLaMuro NickLaMuro force-pushed the add_evm_db_dump_tasks branch 3 times, most recently from a8630f2 to 56ad9f2 Compare May 31, 2018 01:29
This methods is used to handle the session mount logic for the
restore/backup methods in this class in a single spot.

Note:  merged_db_opts is used here in the log messages because db_opts
is not mutated as part of with_mount_session, but we want to make sure
we are logging the correct info.  Putting the log statement inside the
with_mount_session seemed like a bad idea, so rebuilding the calculated
db_opts hash seemed like the least ugly workaround.
Moves out free_space calculation code from EvmDatabaseOps.backup into a
helper method for later shared use.
Runs using the same setup as EvmDatabaseOps#backup, but runs a `pg_dump`
under the hood.  It uses the same method for determining if there is
enough diskspace for the dump as the backup method.  This isn't 100%
accurate, but it should be "Good Enough™".
Effectively a carbon copy of the `:backup` namespace tasks.
Allows excluding of specific tables from the database dump that may not
be necessary for the intended use.
@miq-bot
Copy link
Member

miq-bot commented May 31, 2018

Some comments on commits NickLaMuro/manageiq@bf7e19f~...051a1f7

spec/lib/evm_database_ops_spec.rb

  • ⚠️ - 68 - Detected allow_any_instance_of. This RSpec method is highly discouraged, please only use when absolutely necessary.

@miq-bot
Copy link
Member

miq-bot commented May 31, 2018

Checked commits NickLaMuro/manageiq@bf7e19f~...051a1f7 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 6 offenses detected

lib/evm_database_ops.rb

lib/tasks/evm_dba.rake

@carbonin
Copy link
Member

Those EmptyLinesAroundArguments cops are strange, is that because of how we're using private_class_method here? Feels like a bug ...

Copy link
Member

@carbonin carbonin left a comment

Choose a reason for hiding this comment

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

Looks great @NickLaMuro

Looking over all of this again I'm seeing a bunch of things that would be nice to fix up (I can't keep track of these options hashes at all), but this PR is definitely not the place for it.

@carbonin carbonin merged commit a09f2d1 into ManageIQ:master May 31, 2018
@carbonin carbonin added this to the Sprint 87 Ending Jun 4, 2018 milestone May 31, 2018
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.

4 participants