Commit graph

39 commits

Author SHA1 Message Date
Mahima Singh
7b657edd0d Add Phase 2 optimizations: status API caching and improved Redis pipelining
- Add in-memory cache for /status endpoint with 30s TTL
- Cache keyed by view parameters to handle different query patterns
- Add cache clearing for tests to prevent interference
- Optimize get_queue_metrics to use single pipeline for all Redis calls
  - Previously made 7+ separate pipeline calls
  - Now combines all queue metrics into one pipeline (7n+2 operations)
  - Reduces Redis round trips and improves API response time
- Update unit tests to match new pipelining behavior
- All 866 tests passing
2025-12-24 13:55:24 +05:30
Jake Spain
93201756a0
Add v3 api and remove v2 2023-03-27 21:27:43 -04:00
Jake Spain
1df7ab6d34
Fix tests based on new dns config 2023-03-27 21:27:41 -04:00
Jake Spain
fb80d989c8
Removed api/v1 spec tests 2023-03-27 21:27:39 -04:00
Samuel Beaulieu
2e608b7196
spec test domain set at the config and provider levels 2022-03-31 13:15:58 -05:00
Samuel Beaulieu
a2d613782a
remove 'last minute' tcp vm_ready check from the api for pooled vms
the vm_ready methods should be implemented per provider and checking in the api
creates issues since provider code is not available. Removing this for the V2 api
2022-03-31 13:15:56 -05:00
Samuel Beaulieu
dd375b20c3
document the new provider configuration skip_dns_check_before_creating_vm 2022-03-31 13:15:55 -05:00
Samuel Beaulieu
66eb598e4e
tabling this PR for the next sprint 2022-03-31 13:15:54 -05:00
6b9eb2369f
Connect domain settings to pools, create v2 API 2022-03-31 13:15:52 -05:00
a0caa41a54
(DIO-2675) Undo pool size template overrides
This implements a delete method for pooltemplate and poolsize. The API
removes the override from Redis and then adds an entry in Redis that
causes the pool manager to wake up and process the removal of the
override.

To facilitate this, a new variable has been created in lib/vmpooler.rb
to hold a copy of the original / pre-override config. This supplemental
copy of the pools is then indexed for use as a reference.

When pool manager wakes up to process an override removal, it looks up
the pre-override value from the config via the new variables mentioned
above.

Just as with entering overrides, no restart is needed. Template and pool
size changes are logged so that anyone watching or reviewing the logs
can see what happened when. The new API endpoints also return values for
both the pre-revert and post-revert value.
2021-11-04 14:03:06 -04:00
Belen Bustamante
08132f75bd
Add healthcheck endpoint, spec testing 2020-09-22 12:25:26 -07:00
kirby@puppetlabs.com
c6fdc8d6fd (POOLER-186) Fix template alias evaluation with backend weight of 0
This change fixes template alias evaluation to ensure that the correct
data is set when generating on demand requests for pools that have a
backend weight configured for a value of 0. Without this change vmpooler
will return an empty selection in api for template alias evaluation.

To support this change tests are added that first reproduced the
failure, and then verified that it is resolved with the addition of the
patch. Additionally, test coverage is added to ensure that code paths
that include pickup gem usage are covered.
2020-08-05 16:33:10 -07:00
John O'Connor
85ff3f7022 (MAINT) Add optional API Request Logging
This was partially an exercise to use middleware, but also to enable
basic logging for the API by logging all the API calls to the logger.
2020-06-29 19:56:29 +01:00
John O'Connor
a21d8c5642 (POOLER-178) Target Stats for api & manager
Ensure that the correct stats are registered for the Manager and the api
respectively. E.g. all checkout counters are for the api only, whereas
clone times belong to the manager.

Also new ondemand functionality stats weren't registered, so add these
along with missing delete stats.
2020-06-29 19:54:28 +01:00
John O'Connor
8ed8c43970 (POOLER-160) Revise Metrics Classwork
Review changes suggested to revise the Metrics related files into a more
logical class structure.

Also fixup grammar typos in docs strings and any trailing metrics that
have been recently added to vmpooler.
2020-06-29 19:54:28 +01:00
John O'Connor
bbd76bde4c (POOLER-160) Add Prometheus to pooler startup
This is a re-architect of the vmpooler initialisation code to:
1. Allow an API service for both manager and the api
2. Add the Prometheus endpoints to the web service.
   Needed to change the way the Rack Service is started as instantiating
   using ".New" leads to a failure to initialise the http Stats
   collection.
3. Selectively load the pooler api and/or Prometheus endpoints.
4. Rework API Spec tests for revised API loading. Needed to tidy up the
   initialisation and perform a reset! after each test to avoid "leaks"
   and dependencies between the tests.
2020-06-29 19:52:14 +01:00
kirby@puppetlabs.com
811fd8b60f (POOLER-158) Add capability to provision VMs on demand
This change adds a capability to vmpooler to provision instances on
demand. Without this change vmpooler only supports retrieving machines
from pre-provisioned pools.

Additionally, this change refactors redis interactions to reduce round
trips to redis. Specifically, multi and pipelined redis commands are
added where possible to reduce the number of times we are calling redis.

To support the redis refactor the redis interaction has changed to
leveraging a connection pool. In addition to offering multiple
connections for pool manager to use, the redis interactions in pool
manager are now thread safe.

Ready TTL is now a global parameter that can be set as a default for all
pools. A default of 0 has been removed, because this is an unreasonable
default behavior, which would leave a provisioned instance in the pool
indefinitely.

Pool empty messages have been removed when the pool size is set to 0.
Without this change, when a pool was set to a size of 0 the API and pool
manager would both show that a pool is empty.
2020-06-03 14:00:04 -07:00
Samuel Beaulieu
953aa68907 (POOLER-161) Fix extending vm lifetime when max lifetime is set
Before this PR, the current running time was being inspected to decide if the
vm lifetime could be extended. But since vm lifetime is absolute and not relative
this check is now removed.
2020-04-15 13:17:14 -05:00
Brandon High
82dae7d04c
Merge pull request #353 from mattkirby/vmpooler_flush
(POOLER-153) Add endpoint for resetting a pool
2020-02-14 09:53:47 -08:00
kirby@puppetlabs.com
52b60b074c (POOLER-153) Add endpoint for resetting a pool
This commit adds a capability to vmpooler to reset a pool, deleting its ready and pending instances and replacing them with fresh ones. Without this change vmpooler does not offer a mechanism to reset a pool without also changing its template.
2020-02-13 11:59:44 -08:00
Samuel
ae10bd4e22 (POOLER-123) Implement a max TTL (#349)
* (POOLER-123) Implement a max TTL

Before this change, we could checkout a vm and set the lifetime to a
very high number which would esssentially keep the vm running forever.
Now implementing a config setting max_lifetime_upper_limit which enforces
a maximum lifetime in hours both for initial checkout and extending a
running vm

* (POOLER-123) Improve PUT vm endpoint error messaging

Prior to this commit the PUT vm endpoint didn't give any useful
information about why a user's request failed.

This commit updates PUT to output a more helpful set of error messages
in the `failure` key that gets returned in the JSON response.

* (POOLER-123) Update max_lifetime_upper_limit key

This commit switches the max_lifetime_upper_limit key from being a
symbol to being a string, which is what the config hash seems to contain.

* (maint) Add option to disable Redis persistence in docker-compose

This commit is just a handy little command override to the redis
container to prevent persistence.
2019-12-05 09:35:30 -07:00
kirby@puppetlabs.com
30bf2074fe (POOLER-150) Synchronize checkout operations for API
This commit adds a shared mutex to vmpooler API so that checkout requests can be synchronized across threads. Without this change it is possible in some scenarios for vmpooler to allocate the same SUT to different API requests for a VM.
2019-10-21 14:24:34 -07:00
kirby@puppetlabs.com
9c5a0d114b (POOLER-142) Add running host to vm API data
This change adds the running host for a VM to the API data available via /vm/hostname. Without this change the running host would be logged to vmpooler log, but not available any other way. Additionally, the data will specify if a machine has been migrated. Without this change parent host data for a vmpooler machine is not available via the vmpooler API.
2019-08-21 12:43:06 -07:00
Spencer McElmurry
98a547b807 (POOLER-143) Add clone_target config change to API
This allows the user to change the cluster in which the targeted pool
will clone to. Upon configuration change, the thread will wake up and
execute the change within 1 second.
2019-07-29 08:53:27 -07:00
kirby@puppetlabs.com
d6e948d34d (POOLER-140) Ensure a VM is alive at checkout
This commit duplicates the vm_ready? check to the API layer to allow for API to validate that a VM is alive at checkout. Without this change API relies upon the checks in pool_manager validating pools. This change should allow for additional insight into whether a machine is in a ready state and resopnding at checkout time.
2019-07-17 12:03:55 -07:00
Spencer McElmurry
ce6ea1662d
Merge pull request #324 from puppetlabs/QENG-7201
(QENG-7201) Vmpooler pool statistic endpoint optimization
2019-04-17 11:56:48 -05:00
Samuel Beaulieu
714a9edf5e (QENG-7201) Adding docs and tests 2019-04-15 13:09:53 -05:00
kirby@puppetlabs.com
d738f35727 (POOLER-140) Ensure a running VM stays in a queue
This commit updates how a VM is checked out to ensure that there is no window where the VM could be considered discovered, and therefore destroyed. Without this change the VM is retrieved by calling 'spop' on the ready queue, and then adding it to the running queue. This change moves to selecting the VM by retrieving the last member of the set, and moving it with 'smove' from ready to running. As a result of this change vmpooler moves from retrieving the VMs from the ready state randomly, to instead retrieve the oldest VM in the queue. This change should reduce churn where it would otherwise not be required to satisfy demand.
2019-04-05 14:01:18 -07:00
kirby@puppetlabs.com
49ec06e151 (POOLER-138) Support multiple pools per alias
This change updates handling of pool aliases to allow for more than a
single pool to be configured as an alias pool. Without this change if
multiple pools are configured as an alias the last one to configure it
is set as the alias for that pool.

Additionally, redis testing requirements are removed in favor of
mock_redis. Without this change a redis server is required to run
vmpooler tests.
2019-02-01 09:05:23 -08:00
kirby@puppetlabs.com
4ba4a1dd6c (POOLER-131) Return requested name when getting VMs
This commit updates fetch_single_vm to return the name of the template that was requested, instead of the name of the pool providing the VM to meet the request. Without this change, when an alias is used for fetching a VM, a different pool title may be returned containing the requested VMs than the user initially requested.
2018-09-27 12:05:30 -07:00
Spencer McElmurry
12bba418d1 (POOLER-81) Add time remaining information (#280)
* (POOLER-81) Add time_remaining information

Before, the only time calculation displayed for a given VM was the
lifetime parameter. Added the remaining parameter which will
display time until the VM is destroyed as a float.

Additionally, start_time and end_time were added to api to return
as UTC based times (e.g. 2018-07-10 11:01:03 -0700).

* Remove abs eval from GET, rework spec tests to check each field.
This allows us to account for "flakiness" of the remaining return.

* Change datetime to RFC3339 for start_time and end_time
2018-07-12 09:40:22 -07:00
Spencer McElmurry
84065dd059 Revert "(POOLER-81) Add time_remaining information" (#279)
* Revert "(POOLER-34) Ship clone request to ready time to metrics (#277)"

This reverts commit a865e6bd2f.

* Revert "(POOLER-81) Add time_remaining information (#276)"

This reverts commit 1910cffaf7.
2018-07-10 09:00:12 -07:00
Spencer McElmurry
1910cffaf7 (POOLER-81) Add time_remaining information (#276)
* (POOLER-81) Add time_remaining information

Before, the only time calculation displayed for a given VM was the
lifetime parameter. Added the time_remaining parameter which will
display time until the VM is destroyed in hours, minutes, seconds.

Additionally, updated the running parameter to display in a similar
fashion as time_remaining.

* Add spec testing for testing time_remaining stat
2018-07-09 16:22:05 -07:00
kirby@puppetlabs.com
cbd4567454 Provide valid configuration for auth
This commit removes a additional authenticate method that is defined in the token_spec tests. Instead, authenticate is used from api/helpers. To support this change the config provided is updated to specify a dummy provider. Without this change authenticate cannot be tested along with token_spec because token_spec redefines authenticate.
2018-06-27 14:41:27 -07:00
kirby@puppetlabs.com
9fa27af8e5 (POOLER-113) Add support for multiple LDAP search bases
This commit updates vmpooler to support setting an array of search bases
in addition to a single base provided as a string. Without this change
it is not possible to specify multiple search bases to use with the LDAP
authentication provider. Additionally, test coverage is added to
the authentication helper method.
2018-06-25 21:37:22 -07:00
kirby@puppetlabs.com
9bb4df7d8e (POOLER-107) Add configuration API endpoint
This commit adds a configuration endpoint to the vmpooler API. Pool
size, and pool template, can be adjusted for pools that are configured
at vmpooler application start time. Pool template changes trigger a pool
refresh, and the new template has delta disks created automatically by
vmpooler.

Additionally, the capability to create template delta disks is added to
the vsphere provider, and this is implemented to ensure that templates
have delta disks created at application start time.

The mechanism used to find template VM objects is simplified to make the flow of logic easier to understand. As an additional benefit, performance of this lookup is improved by using FindByInventoryPath.

A table of contents is added to API.md to ease navigation. Without this change API.md has no table of contents and is difficult to navigate.

Add mutex object for managing pool configuration updates

This commit adds a mutex object for ensuring that pool configuration changes are synchronized across multiple running threads, removing the possibility of two threads attempting to update something at once, without relying on redis data. Without this change this is managed crudely by specifying in redis that a configuration update is taking place. This redis data is left so the REPOPULATE section of _check_pool can still identify when a configuration change is in progress, and prevent a pool from repopulating at that time.

Add wake up event for pool template changes

This commit adds a wake up event to detect pool template changes.
Additionally, GET /config has a template_ready section added to the
output for each pool, which makes clear when a pool is ready to populate
itself.
2018-06-15 10:15:47 -07:00
Samuel Beaulieu
96541729fb (POOLER-93) Extend API endpoint to provide just what is needed
The status endpoint provides a lot of statistics. This commit extends it
by supporting a query parameter called 'view' which may contain one or
multiple comma separated names for the top-level statistics returned
in the JSON response. status is always returned.
Optional elements are capacity,queue,clone,boot,pools
Everything is returned when 'view' is not specified, which is
backwards compatible with the current behavior.
2017-10-20 15:53:40 -05:00
Samuel Beaulieu
f10bcadf7e (POOLER-92) Add the alias information in the API status page for each pool
Before this change if a pool had an alias configured, the information would not be
made public in the API. This commit adds the alias key in the pool object for each
pool if configured. The alias key can be abscent, a string or an one or multiple
array of strings. The value of the alias is copied from the configuration and can
represent another name for the pool, or another configured pool.
2017-10-18 12:28:51 -05:00
Glenn Sarti
8bcf74872a (POOLER-73) Restructure tests to unit and integration directories
Previously all of the spec tests for VM Pooler were all together in the specs
directory.  However some tests require a working local Redis server to operate
and other instead mock all external dependencies.  This commit splits the test
files between unit and integration, where integration tests require a working
Redis instance, and unit tests do not.  This commit also removes the root
`vmpooler` directory as it is not required.  The tests rake test still operates
correctly.

This commit also adds the mock_redis library for testing for the pool_manager.
2017-02-17 13:04:38 -08:00