
The patch adds support of oslo.caching in heat and enables caching when heat requests OS services and validates custom constraints. So it allows to increase performance of validation (cause we don't need to call requests for the same values) and handle the cases when stack have a lot of instances (and glance fails because heat is ddosing it). So the logic introduced in this patch is the following: - heat request value from validation cache - if value is found and it is not expired then we return it otherwise we need request client plugin about validation - if value is valid then store result in cache otherwise do not store it. The patch also introduces list of configurations that needs to be specified when using caching. The configuration for caching is modular. It consists from global toggle for caching (disabled by default because in-memory cache is leaking and memcached is not installed by default) and local toggles for specific piece of functionality (constraints cache). Local toggle is enabled by default but it won't be activated without global toggle(enabled=True in heat.conf). DocImpact Implements: blueprint constraint-validation-cache Change-Id: I0a71c52a5c003f0fc6be1762647ffe0146a3b387
72 lines
2.6 KiB
Python
72 lines
2.6 KiB
Python
#
|
|
# Copyright 2015 OpenStack Foundation
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
# implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
from oslo_cache import core
|
|
from oslo_config import cfg
|
|
|
|
from heat.common.i18n import _
|
|
|
|
"""The module contains the code related to integration between oslo.cache
|
|
module and heat."""
|
|
|
|
|
|
def register_cache_configurations(conf):
|
|
"""Register all configurations required for oslo.cache
|
|
|
|
The procedure registers all configurations required for oslo.cache.
|
|
It should be called before configuring of cache region
|
|
:param conf: instance of heat configuration
|
|
:return updated heat configuration
|
|
"""
|
|
# register global configurations for caching in heat
|
|
core.configure(conf)
|
|
|
|
# register heat specific configurations
|
|
constraint_cache_group = cfg.OptGroup('constraint_validation_cache')
|
|
constraint_cache_opts = [
|
|
cfg.IntOpt('expiration_time', default=60,
|
|
help=_(
|
|
'TTL, in seconds, for any cached item in the '
|
|
'dogpile.cache region used for caching of validation '
|
|
'constraints.')),
|
|
cfg.BoolOpt("caching", default=True,
|
|
help=_(
|
|
'Toggle to enable/disable caching when Orchestration '
|
|
'Engine validates property constraints of stack.'
|
|
'During property validation with constraints '
|
|
'Orchestration Engine caches requests to other '
|
|
'OpenStack services. Please note that the global '
|
|
'toggle for oslo.cache(enabled=True in [cache] group) '
|
|
'must be enabled to use this feature.'))
|
|
]
|
|
conf.register_group(constraint_cache_group)
|
|
conf.register_opts(constraint_cache_opts, group=constraint_cache_group)
|
|
|
|
return conf
|
|
|
|
|
|
# variable that stores an initialized cache region for heat
|
|
_REGION = None
|
|
|
|
|
|
def get_cache_region():
|
|
global _REGION
|
|
if not _REGION:
|
|
_REGION = core.configure_cache_region(
|
|
conf=register_cache_configurations(cfg.CONF),
|
|
region=core.create_region())
|
|
return _REGION
|