Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding more logging to the UCM guardrails logic #836

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions enterprise_catalog/apps/catalog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,13 +866,32 @@ def _check_content_association_threshold(catalog_query, metadata_list):
new_relations_size = len(metadata_list)
# To prevent false positives, this content association action stop gap will only apply to reasonably sized
# content sets
LOGGER.info(
'_check_content_association_threshold is checking the guardrail consideration floor of: %s for query: %s',
settings.CATALOG_CONTENT_INCLUSION_GUARDRAIL_CONSIDERATION_FLOOR,
catalog_query,
)
if existing_relations_size > settings.CATALOG_CONTENT_INCLUSION_GUARDRAIL_CONSIDERATION_FLOOR:
# If the catalog query hasn't been modified yet today, means there's no immediate reason for such a
# large change in content associations
LOGGER.info(
'_check_content_association_threshold is checking the modified value: %s of query: %s as compared to '
'todays date: %s',
catalog_query.modified.date(),
catalog_query,
localized_utcnow().date(),
)
if catalog_query.modified.date() < localized_utcnow().date():
# Check if the association of content results in a percentage change of
# `CATALOG_CONTENT_INCLUSION_GUARDRAIL_ALLOWABLE_DELTA` of content items from the query's content set.
percent_change = abs((new_relations_size - existing_relations_size) / existing_relations_size)
LOGGER.info(
'_check_content_association_threshold is checking the percent change: %s of query: %s as compared to '
'the threshold: %s',
percent_change,
catalog_query,
settings.CATALOG_CONTENT_INCLUSION_GUARDRAIL_ALLOWABLE_DELTA,
)
if percent_change > settings.CATALOG_CONTENT_INCLUSION_GUARDRAIL_ALLOWABLE_DELTA:
LOGGER.warning(
"[CONTENT_DELTA_WARNING] associate_content_metadata_with_query is requested to set query: "
Expand Down Expand Up @@ -914,9 +933,7 @@ def associate_content_metadata_with_query(metadata, catalog_query, dry_run=False
metadata_list = create_content_metadata(metadata, catalog_query, dry_run)
# Stop gap if the new metadata list is extremely different from the current one
if _check_content_association_threshold(catalog_query, metadata_list):
return list(content_key for content_key in catalog_query.contentmetadata_set.values_list(
'content_key', flat=True,
))
return catalog_query.contentmetadata_set.values_list('content_key', flat=True)
# Setting `clear=True` will remove all prior relationships between
# the CatalogQuery's associated ContentMetadata objects
# before setting all new relationships from `metadata_list`.
Expand Down
Loading