Commit graph

19 commits

Author SHA1 Message Date
Brandon High
2ca6d49aeb
(QENG-7530) Make VM names more human readable
Prior to this commit hostnames for VMs provisioned by vmpooler were 15
random characters. This is difficult for humans to tell apart.

This commit updates the naming to use the `spicy-proton` gem to generate
adjective noun pair names for the VMs, which I think would be easier for
humans to tell apart, as well as fun and memorable to say.

The random name should not exceed 15 characters in order to prevent
issues with NETBIOS, etc as discussed in the attached ticket.
2019-10-24 09:12:18 -07:00
kirby@puppetlabs.com
d94b14a4d8 (POOLER-137) Support integer environment variables
This commit updates vmpooler to set configuration values received via environment variables to integer values when an integer value is expected. Without this change vmpooler does not support setting integer values via environment variables. Additionally, testing is added for configuring vmpooler via environment variables.

To support this testing the gem climate_control is added, which allows
for testing environment variables without those set variables leaking to
other tests.
2019-01-22 15:02:07 -08:00
kirby@puppetlabs.com
cd73f53561 (POOLER-129) Allow setting weights for backends
This commit updates get_vm in the vmpooler API to allow for setting weights for backends. Additionally, when an alias for a pool exists, and the backend configured is not weighted, then the selection of the pool based on alias will be randomly sampled. Without this change any pool with the title of the alias is exhausted before an alternate pool with the configured alias is used, which results in an uneven distribution of VMs. When all backends involved are configured with weighted values the VM selection will be based on probability using those weights.

A bug is fixed when setting the default ttl for check_ready_vm.

Pickup is added to handle weighted VM selection.

A dockerfile is added that allows for building and installing vmpooler
from the current HEAD in docker to make for easy testing.
2018-09-11 11:15:02 -07:00
Corey Osman
2daa5244b8 Adds a new mechanism to load providers from any gem or file path. (#263)
* Adds ability to load only providers used in config file
2018-07-24 16:35:18 -07:00
kirby@puppetlabs.com
4788693749 Update gemspec in preparation for vmpooler release
This commit updates gemspec and Gemfile in preparation of a vmpooler release. To support this change the vmpooler executable is placed into a bin directory for inclusion in the gem. The license in gemspec is updated to Apache 2.0 to reflect the vmpooler project license.
2018-07-14 15:49:58 -07:00
Corey Osman
148f92591e Adds a gemspec file 2018-06-12 12:01:26 -07:00
kirby@puppetlabs.com
356c541fdc (POOLER-101) Update nokogiri and net-ldap
This commit updates nokogiri and net-ldap to versions that have fixed known vulnerabilities. Without this change vmpooler requires versions of each gem that contain known vulnerabilities.
2018-05-11 17:48:53 -07:00
kirby@puppetlabs.com
28922df28e Remove references to jruby 1.7
This commit removes references to jruby 1.7 and ruby 2.0 in Gemfile. Without this change there are references to unused ruby versions.
2018-01-11 11:04:42 -08:00
Glenn Sarti
0840e11e71 (maint) Pin nokogiri and redis due to old ruby versions
Nokogiri and Redis gems have had recent releases which are not compatible with
older ruby versions.  This commit modifies the Gemfile to get the latest of
each of these gems on modern ruby versions and pin to the older gem versions for
older ruby engines.
2017-09-19 16:42:51 -07:00
Glenn Sarti
cecf8c5c79 (maint) Pin nokogiri on legacy ruby
Due to native extensions not working for JRuby on Windows easily, sometimes very
old versions of MRI Ruby are needed for debugging (1.9.3). This commit pins
nokogiri to a version which is compatible with ruby 1.9.x.  It is expected this
is only required for debugging in edge cases. vmpooler should still be run on
modern ruby versions in production.
2017-07-19 12:52:33 -07:00
Glenn Sarti
888ffc4afc (POOLER-52) Add a generic connection pool
Previously VMPooler had no concept of a connection pooler.  While there is an
up to date connection pooler Gem (connection_pool), that supports MRI and jRuby,
it lacked metrics which are useful to diagnose errors and judge pool size.
This commit:

- Brings in the connection_pool gem
- Creates a new class called generic_connection_pool which inherits from the
  ConnectionPool class in the connection_pool gem.
- Extends the connection pool object with a new function called `with_metrics`
  This copies the code from the original `with` method but emits metrics for
  how long it took to get an object from the pool, and then how many objects
  are left in the pool.  This is sent using VMPooler's metrics object.
  Extending the object was used instead of overriding as it was not possible to
  inject into the existing function and monkey patching did not seem the correct
  way.

  In order use the metics, the GenericConnectionPool object modifies the
  initialize method to use :metrics and :metrics_prefix options
- Also added tests for the GenericConnectionPool class to ensure the new
  functions are tested.  Note that the functionality that was not extended is
  not tested in VMPooler.
2017-05-17 13:52:28 -07:00
Glenn Sarti
e399087dc1 (maint) Pin rack to 1.x
Rack was updated recently and 2.x requires ruby 2.2 or above. As VMPooler should
work in older jruby, we need to be Ruby 1.9.3 compatible.  This commit pins
the rack gem to 1.x.
2017-05-12 15:09:27 -07:00
Glenn Sarti
85a2fa4f20 (maint) Add rubocop for testing
This commit adds the rubocop gem, a rubocop rake task and an initial rubocop
configuration file in prepartion for using rubocop in CI.

This commit also adds a rubocop todo file that exempts existing files from
violations.
2017-02-10 13:33:36 -08:00
Glenn Sarti
80c0742e80 (maint) Update Gemfile and gitignore
Previously, a bundle install would not pull in gems from Gemfile.local or
~/.gemfile which are common development workflows in Puppet.  This commit
modifies the Gemfile to pull in these additional gemfiles if they exist.  This
commit also adds common files and folders to gitignore which should not be
committed to this repository.
2017-02-08 17:35:58 -08:00
Rob Braden
e7a71c1088 Merge pull request #171 from sschneid/puma_gem
Add `puma` as required gem
2016-11-29 15:16:43 -08:00
kirby@puppetlabs.com
e6613d56a0 Update migration spec to call pool manager and validate results
Use mock_redis instead of redis.

Make passing of mock redis to helper calls more clear

Update pool_manager_spec to specify vsphere argument where applicable. Update pool_helper calls to vsphere where needed for tests to pass. Without this change rspec tests for pool_manager_spec exhibit 12 failures.

Update pool_manager_spec test with open_socket

Pool_manager_spec stubs a tcpsocket connection to simulate this happening directly within _check_pending_vm. This commit updates this to look more like its usage with open_socket, which allows the test to pass.
2016-11-22 10:23:13 -08:00
Scott Schneider
eceb5bcab0 Add puma as required gem
It is much more performant than the Sinatra's built-in WEBrick.
2016-11-19 10:00:17 -08:00
Rick Sherman
34b93ca6c3 Merge CI.next into Master (#161)
* [QENG-3919] Make vmpooler checkouts be all or nothing (#153)

* (QENG-3919) spike for implementation of all-or-nothing checkout

* Fix two botched variable references

* Aggregate API helper methods

* Add specs for failed multi-vm allocation API endpoints

* (QENG-3919) Add tests for multiple vm requests

* (QENG-3919) Add (failing) specs for POST /vm/pool1+pool2 usages

This exposes the old (bad) behavior on this other code path. Will fix this up next.

* (QENG-3919) Bring query params version in line with JSON post version

Not clear to me why these had to be implemented so differently.

* (QENG-3919) extract common method from both methods of VM allocation

* (QENG-3919) Naming fix, cosmetic cleanups

I mean, I presume all these commits are going to get squashed away on merge anyway.

* (QENG-3919) Update API docs

We consider it a bug that the actual behavior was not this behavior, but the
documentation was also silent on this point.

* (QENG-3919) minor readability tweak in refactored method

* (QENG-3919) Clean up interim comments re: status codes

* (QENG-3919) Drop now-orphaned `checkout_vm` method

We kept this up-to-date while we were upgrading and refactoring, but, turns out,
this method is no longer called anywhere.  💀 🔥

* (QENG-3919) Return 503 status on failed allocation

Making sure we go back to the original functionality, which was:

 - status 200 when vms successfully allocated
 - status 404 when a pool name is unknown
 - status 404 when no pool name is specified
 - status 503 when vm allocation failed

* (QENG-3919) add net-ldap to Gemfile

Maybe we shouldn't foil-ball gems onto servers.

* (QENG-3919) Turns out, spush isn't a redis command

And hence we see once again the weakness of mockist tests.

* (QENG-3919) Pin the net-ldap gem to 0.11 for the jrubies, etc.

* (QENG-3919) Correct an old spelling error in spec descriptions

* (QENG-3919) Further tweak net-ldap version

* (QENG-3919) return_single_vm -> return_vm_to_ready_state

cc @shermdog

* (RE-7014) Add support for statsd
They way we were using graphite was incorrect for the type of data we were sending it.  statsd is the appropriate mechanism for our needs.
statsd and graphite are mutually exclusive and configuring statsd will take precendence over Graphite.  Example of configuration in vmpooler.yaml.example

* (RE-7014) Add tracking of vm gets via statsd
Add the tracking of successful, failed, invalid, and empty pool vm gets.  It is possible we may want to tweak this, but have validated with spec tests and pcaps.

```
vmpooler-tmp-dev.ready.debian-7-x86_64:1|c
vmpooler-tmp-dev.running.debian-7-x86_64:1|c

vmpooler-tmp-dev.checkout.invalid:1|c
vmpooler-tmp-dev.checkout.success.debian-7-x86_64:1|c
vmpooler-tmp-dev.checkout.empty:1|c

vmpooler-tmp-dev.running.debian-7-x86_64:1|c

vmpooler-tmp-dev.clone.debian-7-x86_64:12.10|ms

vmpooler-tmp-dev.ready.debian-7-x86_64:1|c
```

* (RE-7014) statsd nitpicks and additional rspec
Cleaned up some code review nitpicks and added pool_manager_spec for empty pool.

* (RE-7014) update statsd to use gauge for running/ready
Previously was using increment which was incorrect for that particular application.

* Revert "Merge pull request #155 from shermdog/RE-7014-cinext"

This reverts commit cc03a86f6a, reversing
changes made to 5aaab7c5c2.

* (QENG-4070) Consistently return 503 if valid pool is empty

There were several problems with how the pooler checked out vms with
respect to empty pools, invalid pools, and aliases:

- If the vmpooler config did not contain any aliases and the caller
requested a vm from an empty pool or a non-existent one, the vmpooler
would error with:

    NoMethodError - undefined method `[]' for nil:NilClass

If the config contained a non-nil alias section, then:

- If the caller requested a vm from an empty pool and either the vm
didn't have an alias or the aliased pool was empty or non-existent, then
the request for that vm would be silently ignored. The vmpooler would
return 200 if the caller asked for multiple vms and the vmpooler was
able to checkout at least one vm.  Otherwise it would return 404.

- Similarly, if the caller requested a vm from a non-existent pool, then
the request was silently ignored.

This commit adds a `pool_names` Set to the config containing all valid
pool names including aliases. This is used to determine whether a
requested template name is valid or not. This is necessary because redis
does not distinguish between empty and non-existent sets, e.g. the
following returns false in both cases:

    backend.exists('vmpooler__ready__' + key)

If the caller requests a vm (single or multiple), and any vm references
an invalid pool name, we immediately return 404. Otherwise, we know the
request is for valid pool names, since the vmpooler requires a restart
to change pool names and counts.

We then attempt to acquire each vm, trying to match on pool name or
failing back to aliased pool name, as was the previous behavior.

The resulting behavior is:

- If the caller asks for at least one vm from an unknown pool, then
don't try to checkout any vms and respond with 404.
- If the caller asks for a vm, and at least one pool is empty, then
respond with 503, returning checked out vms back to the pool.
- Otherwise return 200 with the list of checked out vms.

This commit also makes `alias` optional again.

This commit also re-enables tests that were merged in from master, but
originally commented out due to the bugs described above..

* (maint) Add json pessimistic pin

json 2.0.x was released on July 1 and is not compatible with ruby < 2.0.
Since we still support that version, add a pessimistic pin, which is
what we were using prior to July 1.

* [QENG-4070] Make json version conditional on RUBY_VERSION

* Drop extraneous mocks from updated test

* Revert "Revert "Merge pull request #155 from shermdog/RE-7014-cinext""

This reverts commit 0fd6fff934.

* Fix some spec errors

These were caused in part by dropping changes from the original PR when we
dropped the v1_spec.rb master test file (in favor of the updated and separated
versions).

* [QENG-4075] Fix bug with template name on allocation failure

We're returning [nil,nil] in this case, meaning that name will not be set. This
means we'll get an error trying to concatenate the stats string. Use the
requested template name here instead.

* [QENG-4075] Refactor statsd methods / classes

Prior to this we could easily run into situations where `statds_prefix` would
be `nil` (and possibly the `statsd` handle itself). There was some significant
complexity and brittleness in how statsd was set up.

Refactored so that:

 - `statsd_prefix` is no longer exposed to any callers of statsd methods
 - there is now a `Vmpooler::DummyStatsd` class which can be returned when we are not actually going to publish stats, but would like to keep the calling interface consistent
 - setup of the statsd handle is via just passing in `config[:statsd]`, if `nil`, this will result in a dummy handle being return
 - defaulting of `server` values was fixed -- this did not actually work in the previous implementation. `config[:statsd][:server]` is now required.
 - tests use a `DummyStatsd` instance instead of an rspec double.
 - calls to `statsd.increment` were taking incorrect arguments (some our fault, some part of the prior implementation), and were not collecting data on which pools were "invalid" or "empty". Fixed this and are now explicitly tracking the invalid/empty pool names.

* [QENG-4075] Drop now-superfluous :statsd config defaulting

* [QENG-4075] Unify graphite and statsd for the pool manager

Prior to this, the `pool_manager.rb` library could take handles for both
graphite and statsd endpoints (which were considered mutually exclusive),
and then would use one. There was a bevy of conditional logic around sending
metrics to the graphite/statsd handles (and actually at least one bug of
omission).

Here we refactor more, building on earlier work:

 - Our graphite class comes into line with the API of our Statsd and DummyStatsd classes
 - In `pool_manager.rb` we now accept a single "metrics" handle, and we drop all the conditional logic around statsd vs. graphite
 - We move the inconsistent error handling out of the calling classes and into our metrics classes, actually logging to `$stderr` when we can't publish metrics
 - We unify the setup code to use `config` to determine whether statsd, graphite, or a dummy metrics handle should be used, and make that happen.
 - Cleaned up some tests. We could probably stand to do a bit more work in this area.

* [QENG-4075] Clean up pool manager, specs

Prior to this, `pool_manager.rb` allowed the `metrics` argument to be optional,
but at this point it will be an instance of `Vmpooler::Statsd`,
'Vmpooler::Graphite', or `Vmpooler::DummyStatsd`, so making this non-optional.

Cleaned up that file's tests, cosmetically, as well as recognizing that the
behavioral difference between graphite and statsd does not depend on the pool
manager.

* [QENG-4075] update example vmpooler.yaml file

This documents the changes to :server being mandatory for all metrics
endpoints, as well as the graphite endpoint supporting an optional :port
configuration value.

* [QENG-4075] Rename usages of statsd -> metrics

Really, let's just support a generic metrics interface.

* (maint) move statsd-ruby require into Vmpooler::Statsd class

We've managed to move mentions of this out of the calling code, so let's
move the require.

* (maint) metrics.log -> metrics.timing

We missed this during the refactoring. Bringing this up to date.

* [QENG-4075] Allow specifying 'graphs:' for dashboard

Prior to this the dashboard front-end would use the configuration settings
for `graphite[:server]`/`graphite[:prefix]` to locate a graphite server
to use for rendering graphs.

Now that we have multiple possible metrics backends, the front-end graph
host for the dashboard could be entirely different from the back-end metrics
server that we publish to (if any).

This decouples those settings:

 - use `graphs[:server]` / `graphs[:prefix]` for the graphite-compatible web front-end to use for dashboard display graphs
 - fall back to `graphite[:server]`/`graphite[:prefix]` if `graphs` is not specified, in order to support legacy `vmpooler.yaml` configurations.

Note that since `statsd` takes precedence over `graphite`, it's possible to specify both `statsd` (for publishing) and `graphite` (for reading). We still prefer `graphs` over `graphite`.

Updated the example `vmpooler.yaml` config file.

* (maint) fix variable reference in new_metrics

This was referencing config directly, when what we want is for a
hash to be passed in (derived from config).

* (maint) Fix typo in updated graph link call

* (maint) default :graphs prefix to 'vmpooler'

* (maint) Fix parse error in vmpooler script

The things you find through manual QA 🧌

* (maint) use strings instead of symbols in config

Nested hash data comes back with string keys, not symbols. Be consistent.

* [QENG-4075] Factor out Vmpooler::DummyStatsd

This makes it visible to lib/vmpooler.rb, as well as putting this dummy
metrics endpoint in its own file for easier discovery.

* (maint) clean up statsd inclusion and require lines

The library is actually required as 'statsd' and not 'ruby-statsd', best I can tell.

* (maint) construct ::Statsd instead of Statsd

Because it's ambiguous in this scope, and, well, it doesn't
actually work in production.

* [QENG-4075] Also track completely invalid requests

When we don't even get a pool name we still want metrics to be recorded.
2016-07-25 10:43:32 -05:00
Colin
e57ee075f2 (QENG-2246) Add Travis CI
This commit adds a Rakefile, Gemfile, and Travis CI config file.

The Rakefile contains two tasks: test and junit. Both targets execute
the spec tests, with the difference being how the results are presented.

The Gemfile defines dependencies and a test group. To install just the
gems needed for running the application, execute:
  * `bundle install --without test`

The new .travis.yml file is for Travis CI and targets the major ruby
versions.
2015-07-06 11:24:31 -07:00