Skip to content

Commit

Permalink
Flush transitive aliases during deployment [RHELDST-28321]
Browse files Browse the repository at this point in the history
We saw some repo instability after a recent GA. This was due to only a
portion of affected URLs being flushed. The current deployment cache
flush only gets URLs based on directly updated aliases. This didn't take
into consideration URLs that require several aliases to be applied.
  • Loading branch information
amcmahon-rh committed Jan 6, 2025
1 parent 0146382 commit 6e6747a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 23 deletions.
2 changes: 1 addition & 1 deletion exodus_gw/models/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from .base import Base


# pylint: disable=unsubscriptable-object
class PublishedPath(Base):
"""Represents a path updated on the CDN at some point.
Expand Down
2 changes: 1 addition & 1 deletion exodus_gw/models/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from .base import Base


# pylint: disable=unsubscriptable-object
class Publish(Base):
__tablename__ = "publishes"

Expand Down
53 changes: 32 additions & 21 deletions exodus_gw/worker/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from exodus_gw import models, schemas
from exodus_gw.aws.dynamodb import DynamoDB
from exodus_gw.aws.util import uris_with_aliases
from exodus_gw.database import db_engine
from exodus_gw.settings import Settings

Expand Down Expand Up @@ -144,30 +145,40 @@ def deploy_config(
# URLs depending on what changed in the config.
flush_paths: set[str] = set()

updated_prefixes = set()
for src, updated_dest, _ in ddb.aliases_for_flush:
if original_aliases.get(src) != updated_dest:
for published_path in db.query(models.PublishedPath).filter(
models.PublishedPath.env == env,
models.PublishedPath.web_uri.like(f"{src}/%"),
updated_prefixes.add(src)

aliases_to_expand = [alias for alias in ddb.aliases_for_flush
if alias[0] in original_aliases.keys()]
updated_prefixes.update(uris_with_aliases(updated_prefixes, aliases_to_expand))

for src in updated_prefixes:
for published_path in db.query(models.PublishedPath).filter(
models.PublishedPath.env == env,
models.PublishedPath.web_uri.like(f"{src}/%"),
):
# If any original exclusion matches the uri, the uri wouldn't
# have been treated as an alias, thus cache flushing would be
# unnecessary.
if any(
[
re.search(exclusion, published_path.web_uri)
for exclusion in original_exclusions.get(src, [])
]
):
# If any original exclusion matches the uri, the uri wouldn't
# have been treated as an alias, thus cache flushing would be
# unnecessary.
if any(
[
re.search(exclusion, published_path.web_uri)
for exclusion in original_exclusions.get(src, [])
]
):
continue
LOG.info(
"Updated alias %s will flush cache for %s",
src,
published_path.web_uri,
extra={"event": "deploy"},
)
flush_paths.add(published_path.web_uri)

continue
LOG.info(
"Updated alias %s will flush cache for %s",
src,
published_path.web_uri,
extra={"event": "deploy"},
)
flush_paths.add(published_path.web_uri)

# Need to expand the matched aliases to other aliases that'd be populated
# during publish
# Include all the listing paths for flush when enabled in settings
flush_paths = (
flush_paths.union(_listing_paths_for_flush(config))
Expand Down
17 changes: 17 additions & 0 deletions tests/worker/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ def test_deploy_config_with_flush(
)
)

# These paths should be flushed after expanding the updated aliases.
db.add(
PublishedPath(
env="test",
web_uri="/content/testproduct/rhui/1/file1",
updated=datetime.now(tz=timezone.utc),
)
)
db.add(
PublishedPath(
env="test",
web_uri="/content/testproduct/rhui/1/file2",
updated=datetime.now(tz=timezone.utc),
)
)
db.commit()

# We're updating the alias in the config.
Expand Down Expand Up @@ -223,6 +238,8 @@ def test_deploy_config_with_flush(
"/content/testproduct/1/file1",
"/content/testproduct/1/file2",
"/content/testproduct/1/newExclusion/file5",
"/content/testproduct/rhui/1/file1",
"/content/testproduct/rhui/1/file2",
]

# And actor call should have been delayed by this long.
Expand Down

0 comments on commit 6e6747a

Please sign in to comment.