Allow users to enable profiling via a setting

Prior to this commit, there is no way for an end user to enable
the new profiling features other than by patching their source
code or passing an extra query parameter to a web request,
which requires them to know the precise URL / query params / POST
body of the request that they want to profile, as well as passing
all of the necessary SSL-related flags to `curl` (et al) so that
their request can be authenticated.

This commit simply adds a boolean setting called 'enable_profiling'
which can be used to turn on this functionality for all requests.

We should provide more precise ways for users to control this, but
this at least gives them a simple option until we have something
better.
Add support for enabling profiling via HTTP header

This commit changes the new setting for enabling profiling from
"enable_profiling" to simply "profile", so that it's easy to
use it from the command line.

It also changes the mechanism for enabling profiling in an HTTP
request; previously, profiling would be enabled via a special
query parameter; now it is enabled via a header (X-Puppet-Profiling).

This allows it to work easily for any type of HTTP request
(GET/POST/HEAD/etc.) without having to worry about the means for
adding a query parameter.

The commit also adds a check for the `profile` setting during
outgoing indirector REST requests, and adds the header if the setting
is enabled.  This means that the profiling flag will work from
the client as well as on the server.
(maint) Enable logging for all `puppet doc` commands

Without this commit the --debug and --verbose flags can only be used
with the rdoc mode and doesn't interact with the other documentation
types. This commit extracts the logging configuration to apply to all
documentation modes.

In addition this defaults the log level to :warning. Since warning and
above messages will be emitted on stderr this will not affect the normal
operation of the `puppet doc` command. Using --debug or --verbose will
emit messages on stdout, so they should not be used while
programmatically generating docs.
Merge branch 'adrienthebo-maint-enable_logging_for_all_docs'

* adrienthebo-maint-enable_logging_for_all_docs:
  (maint) Enable logging for all `puppet doc` commands

closes #1580
(Maint) Ensure that 'hiera-puppet' is loaded correctly

The test for the hiera_* functions showed an interesting error. If the
hiera_hash or hiera_array tests were run in isolation they would
complain that Hiera was not defined and then fail. If the hiera_include
tests were run beforehand, then the tests for hash and array worked as
expected. The issues seems to have been that the require that brought in
hiera was being delayed until too late. By making sure that hiera-puppet
is loaded as soon as the function is defined, rather than called, we are
certain that hiera will be around when we need it.
(Maint) Ensure that activerecord tests are isolated

The activerecord based tests would setup activerecord and rails in a
manner that included stubbing. This made some things behave as you might
want, but caused some manner of getting them to behave the wrong way. By
removing the stubbing, the test cases all work from a clean database.

Another issue occured when one of the tests assumed that no other code
that used its indirection had been run prior to it. The test itself was
very questionable and ended up breaking when the tests were run in a
particular order. The test in question tried to assert that the code
would setup activerecord when it was initialized. Since all of the other
tests relied on this, and that particular behavior did not appear to be
important to the external contract of the class, the test has been
removed.
(Maint) Lazily load the activerecord code

Turns out that if you try to load activerecord when it isn't available,
things don't work. One of our test configurations tests without
activerecord and so the loading of this code needs to be delayed until
we know that we really want to run these tests.
(Maint) Provide JUnit output for jenkins

Without JUnit style output we don't have a good way of seeing test
failures within jenkins. This adds a new rake task ci:spec that will
run with junit output, descriptive output and spec order logging.

It turns out that some of the tests would call safe_posix_fork which
ended up closing all open file handles. This ended up also closing the
file handle that rspec would hold open for the junit output formatter.
Those tests have been modified to ensure that the file descripters are
not actually closed.
Provide a high level description of testing within puppet
Add documentation on examples
Add a section on example groups
Document before and after blocks, let blocks, mocks, and stubs
Merge branch 'adrienthebo-doc-introduction_to_rspec'

* adrienthebo-doc-introduction_to_rspec:
  Document before and after blocks, let blocks, mocks, and stubs
  Add a section on example groups
  Add documentation on examples
  Provide a high level description of testing within puppet

closes #1592
[ci skip]
(Maint) Do not overwrite file output

The windows spec code resets the output streams so that it can handle
color correctly. In doing so it assumed that everything was writing to
stdout, which is not the case when -o is used on the command line.
(#20194) Do not perform reverse DNS lookups in webrick

Previously, the webrick-based puppet master would perform a reverse DNS lookup on
every connected socket, even authenticated connections. This occurs when
puppet calls IPSocket#peeraddr to get its peer's IP address. But ruby
would by default perform a reverse lookup at the same time.

This commit sets the global setting via
BasicSocket.do_not_reverse_lookup to handle ruby 1.8.x and up.

The commit also sets the webrick :DoNotReverseLookup configuration
option, which is necessary on at least 1.9.2p0.

Paired-with: Andy Parker <andy@puppetlabs.com>
Merge pull request #1593 from joshcooper/ticket/master/20194_no_reverse_lookups

(#20194) Do not perform reverse DNS lookups in webrick
(#18211) Refactor daemon run loop

This adds a Scheduler module to puppet to handle the daemon run loop. The loop
involves two separate wakeup cycles, in which one can adjust the interval for
both. Refactoring into classes makes it easier to reason about and test the
correctness of scheduling. This should fix #18211.
(#14766) Add splay support to the scheduler

This adds a class that implements a job that runs with a constant offset. It
also adds a factory method to create jobs and uses it in the daemon loop to
implement splay.

Paired-with: Andy Parker <andy@puppetlabs.com>
(Maint) Properly mark ruby 2 test to not run without sqlite

It seems that rspec example groups do not compose their pending
conditions. For instance if and outer describe is

  describe "foo", :if => we_have_the_power? do
  ...

and a context is inside that with

  context "fighters", :if => band_members_available? do
  ...

then the context will still be executed if the band members are
available but we don't have the power.

This was causing the ruby 2 test for active record to execute even if we
didn't have active record available.
Merge pull request #1546 from cprice-puppet/feature/master/add-setting-to-enable-profiling

Allow users to enable profiling via a setting