Skip to content

Commit

Permalink
Report served artifacts' size metrics even when caching is turned off
Browse files Browse the repository at this point in the history
  • Loading branch information
lubosmj committed Nov 4, 2024
1 parent 79da4c6 commit 001d32b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pulpcore/cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,7 @@ async def cached_function(*args, **kwargs):
response = await self.make_entry(
key, bk, func, args, kwargs, self.default_expires_ttl
)

if size := response.headers.get("X-PULP-ARTIFACT-SIZE"):
elif size := response.headers.get("X-PULP-ARTIFACT-SIZE"):
artifacts_size_counter.add(size)

return response
Expand Down
4 changes: 4 additions & 0 deletions pulpcore/content/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
)

from pulpcore.exceptions import UnsupportedDigestValidationError # noqa: E402
from pulpcore.metrics import artifacts_size_counter # noqa: E402

from jinja2 import Template # noqa: E402: module level not at top of file
from pulpcore.cache import AsyncContentCache # noqa: E402
Expand Down Expand Up @@ -993,6 +994,7 @@ def _build_url(**kwargs):
raise HTTPRequestRangeNotSatisfiable(headers={"Content-Range": f"bytes */{size}"})

headers["X-PULP-ARTIFACT-SIZE"] = str(content_length)
artifacts_size_counter.add(content_length)

if domain.storage_class == "pulpcore.app.models.storage.FileSystem":
path = storage.path(artifact_name)
Expand Down Expand Up @@ -1127,8 +1129,10 @@ async def finalize():

if content_length := response.headers.get("Content-Length"):
response.headers["X-PULP-ARTIFACT-SIZE"] = content_length
artifacts_size_counter.add(content_length)
else:
response.headers["X-PULP-ARTIFACT-SIZE"] = str(size)
artifacts_size_counter.add(size)

if save_artifact and remote.policy != Remote.STREAMED:
await asyncio.shield(
Expand Down

0 comments on commit 001d32b

Please sign in to comment.