Add ability for proportional rollout of the OCI data model
This commit is contained in:
parent
66ddf66fb0
commit
77d7600b64
4 changed files with 22 additions and 9 deletions
|
@ -1,5 +1,6 @@
|
|||
import inspect
|
||||
import logging
|
||||
import hashlib
|
||||
|
||||
from data.database import DerivedStorageForImage, TagManifest, Manifest, Image
|
||||
from data.registry_model.registry_oci_model import oci_model
|
||||
|
@ -11,12 +12,14 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
class SplitModel(object):
|
||||
def __init__(self, oci_namespace_whitelist, v22_namespace_whitelist):
|
||||
def __init__(self, oci_model_proportion, oci_namespace_whitelist, v22_namespace_whitelist):
|
||||
self.v22_namespace_whitelist = set(v22_namespace_whitelist)
|
||||
|
||||
self.oci_namespace_whitelist = set(oci_namespace_whitelist)
|
||||
self.oci_namespace_whitelist.update(v22_namespace_whitelist)
|
||||
|
||||
self.oci_model_proportion = oci_model_proportion
|
||||
|
||||
def supports_schema2(self, namespace_name):
|
||||
""" Returns whether the implementation of the data interface supports schema 2 format
|
||||
manifests. """
|
||||
|
@ -75,7 +78,16 @@ class SplitModel(object):
|
|||
args_dict = {argnames[index + 1]: value for index, value in enumerate(args)}
|
||||
|
||||
namespace_name = self._namespace_from_kwargs(args_dict)
|
||||
if namespace_name in self.oci_namespace_whitelist:
|
||||
use_oci = namespace_name in self.oci_namespace_whitelist
|
||||
if not use_oci and self.oci_model_proportion:
|
||||
# Hash the namespace name and see if it falls into the proportion bucket.
|
||||
bucket = (int(hashlib.md5(namespace_name).hexdigest(), 16) % 100)
|
||||
if bucket <= int(self.oci_model_proportion * 100):
|
||||
logger.debug('Enabling OCI for namespace `%s` in proportional bucket',
|
||||
namespace_name)
|
||||
use_oci = True
|
||||
|
||||
if use_oci:
|
||||
logger.debug('Calling method `%s` under OCI data model for namespace `%s`',
|
||||
attr, namespace_name)
|
||||
return getattr(oci_model, attr)(*args, **kwargs)
|
||||
|
|
Reference in a new issue