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

(SDK-144) Add option to run validate in parallel #144

Merged
merged 1 commit into from
Aug 10, 2017

Conversation

austb
Copy link
Contributor

@austb austb commented Jul 11, 2017

This addes the --parallel flag to the pdk validate command. This
flag will cause the validations to run in their own threads.

UPDATE: waiting for release of tty-spinner gem (also probably need to wait for a release of tty-prompt with compatible tty-cursor range.

Remaining

  • Remove short_spinner_text
  • Use PDK::Util.spinner_opts_for_platform
  • Use released versions of tty-spinner and tty-prompt gems
  • Add Docs

@austb austb force-pushed the parallel_validation branch 4 times, most recently from b5501f0 to 502fd09 Compare July 12, 2017 21:05
@@ -15,6 +15,7 @@ module PDK::CLI

flag nil, :list, _('list all available validators')
flag :a, 'auto-correct', _('automatically correct problems (where possible)')
flag nil, :parallel, _('run validations in parallel')
Copy link
Contributor

Choose a reason for hiding this comment

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

For the upcoming community release, we'll need to comment this line and hardcode line 74 with false.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not necessary to comment it out, can just make it a hidden flag (like --answer-file), so that it's still available for dev & testing but not shown in the help output.

@austb austb force-pushed the parallel_validation branch 3 times, most recently from e77123e to dcef710 Compare July 12, 2017 23:53
Copy link
Contributor

@rodjek rodjek left a comment

Choose a reason for hiding this comment

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

A couple of refactors, and a behaviour change I'm not sure if we want.

Also, it looks like the de po file has been changed with some bad unicode substitutions (ü => Ÿ etc)?

mod_root = PDK::Util.module_root
unless mod_root
raise PDK::CLI::FatalError, _('Current working directory is not part of a module. (No metadata.json was found.)')
end
Copy link
Contributor

Choose a reason for hiding this comment

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

This block can be replaced with PDK::CLI::Util.ensure_in_module! however i'm not sure that we can to restrict validators to run in a module (for example, a module consumer would probably want to run pdk validate from the root of their control repo to run validation on everything at once).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not view this as a behavior change. previously we had this code around the console command call in cli/exec.rb. This had to be brought out to this level because Dir.chdir changes the working dir of the process, not the thread.

@@ -14,13 +14,29 @@ def self.pattern
'metadata.json'
end

def self.spinner_text(targets = [])
_('Checking metadata syntax (%{targets})') % {
targets: targets.map { |t| Pathname.new(t).absolute? ? Pathname.new(t).relative_path_from(Pathname.pwd) : t }.join(' '),
Copy link
Contributor

Choose a reason for hiding this comment

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

As this is now being used in multiple places, we should probably split it out into a helper method (PDK::Util.targets_relative_to_pwd or something) to avoid duplicating the logic.

@austb
Copy link
Contributor Author

austb commented Jul 13, 2017

@rodjek The de po file has been removed entirely from this build. It contained outdated strings which were causing problems when creating new threads. I did not see any way to update a po file while keeping the old strings.

@bmjen bmjen added this to the 0.5.0 milestone Jul 13, 2017
@bmjen bmjen added the feature label Jul 13, 2017
rodjek
rodjek previously approved these changes Jul 14, 2017
@austb austb force-pushed the parallel_validation branch 9 times, most recently from 14aea40 to c385e98 Compare July 20, 2017 18:27
@austb austb dismissed rodjek’s stale review July 20, 2017 18:28

Lots has changed in the PDK and in the parallel validation, so it could use another look over before we merge.

@austb austb force-pushed the parallel_validation branch from c385e98 to 5e4ef24 Compare July 20, 2017 18:51

# This is a placeholder until we integrate ansicon into Windows packaging
# or come up with some other progress indicator for Windows.
class WindowsSpinner
Copy link
Contributor

Choose a reason for hiding this comment

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

ansicon is already integrated. we can drop this.

Copy link
Contributor Author

@austb austb Jul 24, 2017

Choose a reason for hiding this comment

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

We also need unicode before our ✔️ or ✖️ will show up in windows. We could default to the text passed or failed on windows, ie

[passed] Checking metadata (metadata.json)

Would we rather have that so we can have the spinner on Windows? And do we want to do that in this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

having the words instead of the unicode chars is a good idea. I wouldn't block the PR for the change, but we need to do it at one point....

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll leave it as is for now, but get a fix for that up once we get this through.

module CLI
module Spinner
PREFIX = 'spinner_key'.freeze
LOCK = Monitor.new
Copy link
Contributor

Choose a reason for hiding this comment

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

locks should be private to avoid other callers violating expectations.

threads.each(&:join)
exit_codes.sort!

if exit_codes.last != 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@austb austb Jul 24, 2017

Choose a reason for hiding this comment

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

I sorted them to return the highest error code with last in order to mirror the functionality in base_validator.rb

Copy link
Contributor

Choose a reason for hiding this comment

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

lib/pdk/util.rb Outdated

# Returns the targets' paths relative to the working directory
#
# @ return Array<String> The absolute or path to the target
Copy link
Contributor

Choose a reason for hiding this comment

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

should that be @return instead of @ return ?

Where/how can we check the YARD output?

Copy link
Contributor Author

@austb austb Jul 24, 2017

Choose a reason for hiding this comment

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

We need to add a rake task to generate YARD output https://github.com/lsegal/yard#generating-documentation

I'll fix the typo and we can have another PR for that if we want to add it.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is fixed, just not shown as outdated for some reason

@@ -1,604 +0,0 @@
# German translations for puppet development kit package.
Copy link
Contributor

Choose a reason for hiding this comment

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

this file should not be deleted

Copy link
Contributor Author

@austb austb Jul 24, 2017

Choose a reason for hiding this comment

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

This file caused a lot of problems for threads because it was no longer up to date with the current pdk.pot file, and when talking to the i18n folks they were confused why we even had a PO file in our repo as they will be managed by transifex. We should discuss this in more detail if you have concerns, but if we would like both the German PO file and threading the German PO file must be kept up to date and in sync with the pdk.pot file.

An important note, keeping a PO file in sync with the POT file without deleting all the existing translations is not a feature provided by the gettext-setup-gem we use because the Transifex workflow creates brand new PO files and populates them with the previous translations that match current strings. So we would be responsible for figuring out how to do that (most likely using msgmerge).

Another potential solution would be for you to keep the German file locally and not checked in to the repo.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would be interested how the non-up-to-date de.po file causes issues with threading, especially outside the de locale.

rake gettext:update_pot and rake gettext:po[de] worked fine until now to update the po file as needed, and to the right thing for gettext. I'm sure transifex can one-time import the existing translations once we get around to integrating.

Another potential solution would be for you to keep the German file locally and not checked in to the repo.

I'm not even using the thing, what value would it have on my local machine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe we ran into two error messages, one involves fuzzy messages and the other is for old messages it leaves in comments at the bottom.

Commented

Warning: obsolete msgid exists.
         #~ msgstr "Verwende ein eigenes Vorlagerepository für dieses Modul."

Fuzzy

Warning: fuzzy message was used.
  : msgid 'Unable to write '%{file}': %{msg}'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sure transifex can one-time import the existing translations once we get around to integrating.

In my interactions with i18n for this problem, I don't think they are willing to ship a translation that wasn't done by Transifex or whichever company does the translations through Transifex.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added a Rake task that cleans the file for us, one extra step to make sure it works, but we can keep the German file now

Copy link
Contributor

Choose a reason for hiding this comment

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

Excellent work, @austb . Thank you very much for your attention here!

Copy link
Contributor

Choose a reason for hiding this comment

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

(specifically to discovering the root cause of the uninitialized threads)

@DavidS
Copy link
Contributor

DavidS commented Jul 24, 2017

I've had a few comments/change requests on first reading.

Copy link
Contributor

@scotje scotje left a comment

Choose a reason for hiding this comment

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

Some relatively minor things before we merge today. Austin and I talked about a larger refactor that we try to do before 1.0 release.

@@ -105,7 +104,13 @@ def add_spinner(message, opts = {})
@success_message = opts.delete(:success)
@failure_message = opts.delete(:failure)

@spinner = Gem.win_platform? ? WindowsSpinner.new(message, opts) : TTY::Spinner.new("[:spinner] #{message}", opts)
PDK::Util.spinner_opts_for_platform(opts)
Copy link
Contributor

Choose a reason for hiding this comment

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

This method should return a new hash and you should merge with existing opts rather than mutating arg.

@@ -1,7 +1,6 @@
require 'bundler'
require 'childprocess'
require 'tempfile'
require 'tty-spinner'
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason to not explicitly require this here anymore?

Dir.chdir(mod_root) do
::Bundler.with_clean_env do
run_process!
end
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a reason to remove all this, the parallel validate can still call the util method to abort early but I feel like removing this is pushing responsibility in the wrong direction.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can test Dir.pwd so that we only try to chdir if we aren't already in the right place. That should keep the child threads from complaining.

targets = parse_targets(options)

return 0 if targets.empty?

return_val = 0
@return_val = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Was there a reason this had to become an instance var? Something to do with threads?

@scotje scotje changed the title {WIP} (SDK-144) Add option to run validate in parallel (SDK-144) Add option to run validate in parallel Aug 7, 2017
DavidS
DavidS previously requested changes Aug 8, 2017
Copy link
Contributor

@DavidS DavidS left a comment

Choose a reason for hiding this comment

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

Please do not merge this currently, as it is not passing the internal pipeline for the packaging.

@austb austb added the blocked label Aug 8, 2017
@austb austb force-pushed the parallel_validation branch from af21753 to 8570f99 Compare August 8, 2017 19:13
@coveralls
Copy link

Coverage Status

Coverage increased (+0.008%) to 92.238% when pulling 15083b6 on austb:parallel_validation into 47fb4ee on puppetlabs:master.

@puppetlabs puppetlabs deleted a comment from coveralls Aug 8, 2017
@puppetlabs puppetlabs deleted a comment from coveralls Aug 8, 2017
@puppetlabs puppetlabs deleted a comment from coveralls Aug 8, 2017
@puppetlabs puppetlabs deleted a comment from coveralls Aug 8, 2017
@puppetlabs puppetlabs deleted a comment from coveralls Aug 8, 2017
@puppetlabs puppetlabs deleted a comment from coveralls Aug 8, 2017
@puppetlabs puppetlabs deleted a comment from coveralls Aug 8, 2017
@puppetlabs puppetlabs deleted a comment from coveralls Aug 8, 2017
@puppetlabs puppetlabs deleted a comment from coveralls Aug 8, 2017
@DavidS DavidS dismissed their stale review August 9, 2017 12:38

temp hold pre-release

@coveralls
Copy link

Coverage Status

Coverage increased (+0.008%) to 92.238% when pulling 49ccaa5 on austb:parallel_validation into 47fb4ee on puppetlabs:master.

@austb austb removed the blocked label Aug 9, 2017
@austb austb force-pushed the parallel_validation branch from 49ccaa5 to 5727304 Compare August 9, 2017 17:40
@coveralls
Copy link

Coverage Status

Coverage increased (+0.008%) to 92.238% when pulling 5727304 on austb:parallel_validation into f8cb71d on puppetlabs:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.008%) to 92.238% when pulling cbe341b on austb:parallel_validation into f8cb71d on puppetlabs:master.

@scotje
Copy link
Contributor

scotje commented Aug 10, 2017

@jbondpdx Austin is going to add a blurb to the README about this feature and then we plan to merge. Despite the size of the PR, the actual user impact/README stuff should be pretty simple.

This adds the `--parallel` flag to the `pdk validate` command. This
flag will cause the validations to run in their own threads.
@austb austb force-pushed the parallel_validation branch from cbe341b to 6e45cd2 Compare August 10, 2017 19:00
@coveralls
Copy link

Coverage Status

Coverage increased (+0.008%) to 92.248% when pulling 6e45cd2 on austb:parallel_validation into 3a7e3d5 on puppetlabs:master.

@austb austb merged commit 4a68817 into puppetlabs:master Aug 10, 2017
@austb austb deleted the parallel_validation branch August 10, 2017 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants