Skip to content

feat(cache): add read-only cache inspection command (sebs resources inspect) - #310

Open
sanskar-singh-2403 wants to merge 1 commit into
spcl:masterfrom
sanskar-singh-2403:feat/cache-inspect
Open

feat(cache): add read-only cache inspection command (sebs resources inspect)#310
sanskar-singh-2403 wants to merge 1 commit into
spcl:masterfrom
sanskar-singh-2403:feat/cache-inspect

Conversation

@sanskar-singh-2403

@sanskar-singh-2403 sanskar-singh-2403 commented Jul 28, 2026

Copy link
Copy Markdown

Summary

Adds sebs resources inspect, a read-only command that visualizes the
on-disk cache without contacting any cloud provider or requiring a Docker
daemon. Addresses #306.

Per the discussion on the issue, this extends the existing
sebs.cache.Cache API rather than introducing a separate inspection layer,
and lives as a subcommand under the existing resources command group.

What it shows

  • Deployed benchmarks: benchmark, platform, language, packaging
    (container vs code_package), number of functions, and trigger types.
  • Allocated resources per platform: resources_id, region, storage
    bucket count, and locally allocated ports.

Changes

  • Extend sebs.cache.Cache with two read-only helpers:
    • get_deployed_benchmarks(): flattens the per-benchmark config.json
      files into rows of (benchmark, platform, language, packaging,
      functions, triggers, storage, nosql).
    • get_allocated_resources(): reads the per-cloud files (aws.json,
      local.json, ...) for resources_id, region, storage buckets, and
      locally allocated ports.
  • Make Cache docker_client optional so read-only consumers can open a
    cache without a running Docker daemon; guard the container-caching paths
    with an assertion.
  • Add the resources inspect CLI command with a rich table view and a
    --json output mode, plus an optional --deployment platform filter.
  • Add offline unit tests that build a synthetic cache directory.

Usage

sebs resources inspect --cache ./cache
sebs resources inspect --cache ./cache --deployment aws
sebs resources inspect --cache ./cache --output json

Test plan

  • Offline unit tests pass (synthetic cache directory)
  • black, flake8, mypy, and interrogate (100%) pass locally
  • Verified table, JSON, and --deployment filter against a real cache

Addresses #306.



<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Added a read-only `resources inspect` command to view cached benchmark deployments and allocated cloud resources.
  - Supports optional deployment filtering and output as a table or JSON.
  - Cache inspection now works without requiring an active Docker daemon; Docker-dependent operations fail fast when Docker isn’t available.
  - Reports benchmark packaging details, trigger info, storage/nosql keys, regions, storage buckets, and allocated ports.
- **Tests**
  - Added offline unit tests validating deployed benchmarks and allocated resources, including platform filtering and ports-only scenarios.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e0f8153a-e37c-4a6e-8275-c08563a6ce8a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Changes

Cache inspection

Layer / File(s) Summary
Cache inspection APIs
sebs/cache.py
Cache permits an absent Docker client, reads cached benchmark and resource metadata across supported clouds, and guards Docker-dependent package operations.
Resources inspection command
sebs/cli.py
Adds resources inspect with deployment filtering and table or JSON output.
Offline inspection coverage
tests/test_cache_inspect.py
Tests benchmark/resource inspection, platform filtering, and ports-only resource entries using synthetic cache data.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Operator
  participant resources_inspect
  participant Cache
  participant CachedJSON

  Operator->>resources_inspect: invoke resources inspect
  resources_inspect->>Cache: load cached benchmarks and resources
  Cache->>CachedJSON: read config.json and cloud cache files
  CachedJSON-->>Cache: return cached metadata
  Cache-->>resources_inspect: return inspection results
  resources_inspect-->>Operator: render JSON or Rich tables
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding a read-only cache inspection command and related cache support.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sebs/cache.py`:
- Around line 1004-1006: Update add_code_package and update_code_package to
validate Docker availability for container packages at method entry, before
creating cache directories or copying/deleting code. Replace the Docker-client
assert with a RuntimeError, and move cache_dir creation until after this
validation so failures cannot leave partial cache entries.

In `@sebs/cli.py`:
- Around line 927-929: Update the emptiness check in the allocated-resource loop
to also consider the `allocated_ports` field, so entries containing only ports
are retained; continue skipping entries only when resources, storage buckets,
and allocated ports are all absent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d5e5aa5c-5045-432a-95fa-71c5e9e61254

📥 Commits

Reviewing files that changed from the base of the PR and between c650942 and e242c16.

📒 Files selected for processing (3)
  • sebs/cache.py
  • sebs/cli.py
  • tests/test_cache_inspect.py

Comment thread sebs/cache.py Outdated
Comment thread sebs/cli.py
@sanskar-singh-2403

Copy link
Copy Markdown
Author

@coderabbitai help

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

CodeRabbit commands

These commands are invoked using PR/Issue comments.

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai rate limit to show your current review rate limit status.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai evaluate custom pre-merge check --instructions <custom-checks-instructions> --name <custom-checks-title> [--mode <error|warning>] to validate the custom pre-merge checks instructions. Defaults to error when --mode is omitted.
  • @coderabbitai ignore pre-merge checks to override pre-merge checks and get an approval on PR.
  • @coderabbitai run pre-merge checks to run pre-merge checks on the pull request.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai emit path instructions to emit generated path-specific review instructions for this repository.
  • @coderabbitai resolve merge conflict to automatically resolve merge conflicts.
  • @coderabbitai autofix to automatically fix issues identified in unresolved review comments.
  • @coderabbitai fix-ci to automatically fix failing CI checks by creating a stacked PR with fixes.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai generate configuration to create a PR that adds the current resolved configuration as .coderabbit.yaml (or show it if already present).
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit configuration file (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, support, documentation and community

  • Visit our status page to check the current availability of CodeRabbit.
  • Create a ticket on our support page for assistance with any issues or questions.
  • Visit our documentation site for detailed information on how to use CodeRabbit.
  • Join our Discord community to connect with other users and get help from the community.
  • Follow us on X/Twitter for updates and announcements.

@sanskar-singh-2403

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
sebs/cache.py (1)

525-635: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consolidate the hardcoded cloud list into SUPPORTED_CLOUDS.

SUPPORTED_CLOUDS duplicates the ["azure", "aws", "gcp", "openwhisk", "local"] literal already used in load_config (line 267) and shutdown (line 315). Now there are three copies of the same list; a future change (adding/removing a supported cloud) risks silently missing one of them.

♻️ Proposed consolidation
     def load_config(self) -> None:
         with self._lock:
-            for cloud in ["azure", "aws", "gcp", "openwhisk", "local"]:
+            for cloud in self.SUPPORTED_CLOUDS:
                 cloud_config_file = os.path.join(self.cache_dir, "{}.json".format(cloud))
     def shutdown(self) -> None:
         if self.config_updated:
             with self._lock:
-                for cloud in ["azure", "aws", "gcp", "openwhisk", "local"]:
+                for cloud in self.SUPPORTED_CLOUDS:
                     if cloud in self.cached_config:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sebs/cache.py` around lines 525 - 635, Reuse the class-level SUPPORTED_CLOUDS
constant in load_config and shutdown instead of their duplicated hardcoded cloud
lists. Update those cloud-iteration or validation paths to reference
SUPPORTED_CLOUDS so future supported-cloud changes apply consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@sebs/cache.py`:
- Around line 525-635: Reuse the class-level SUPPORTED_CLOUDS constant in
load_config and shutdown instead of their duplicated hardcoded cloud lists.
Update those cloud-iteration or validation paths to reference SUPPORTED_CLOUDS
so future supported-cloud changes apply consistently.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a55b6c63-32e0-4295-9b2d-a578aa8109b3

📥 Commits

Reviewing files that changed from the base of the PR and between e242c16 and 74db93e.

📒 Files selected for processing (3)
  • sebs/cache.py
  • sebs/cli.py
  • tests/test_cache_inspect.py

Add `sebs resources inspect` to visualize the on-disk cache without
contacting any cloud provider or requiring a Docker daemon.

- Extend sebs.cache.Cache with two read-only helpers:
  - get_deployed_benchmarks(): flattens per-benchmark config.json files
    into rows of (benchmark, platform, language, packaging, functions,
    triggers, storage, nosql).
  - get_allocated_resources(): reads the per-cloud files (aws.json,
    local.json, ...) for resources_id, region, storage buckets, and
    locally allocated ports.
- Make Cache docker_client optional so read-only consumers can open a
  cache without a running Docker daemon; guard the container-caching
  paths with an assertion.
- Add the `resources inspect` CLI command with a rich table view and a
  --json output mode, plus an optional --deployment platform filter.
- Add offline unit tests that build a synthetic cache directory.

Addresses spcl#306.
@sanskar-singh-2403

Copy link
Copy Markdown
Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
sebs/cache.py (2)

528-636: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Simplify redundant key-check before dict access.

Ruff (RUF019) flags the "containers" in lang_cfg and lang_cfg["containers"] / "code_package" in lang_cfg and lang_cfg["code_package"] patterns at lines 608 and 610 — dict.get(...) already returns a falsy default, so the membership check is redundant.

♻️ Suggested tweak
-                        if "containers" in lang_cfg and lang_cfg["containers"]:
+                        if lang_cfg.get("containers"):
                             packaging = "container"
-                        elif "code_package" in lang_cfg and lang_cfg["code_package"]:
+                        elif lang_cfg.get("code_package"):
                             packaging = "code_package"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sebs/cache.py` around lines 528 - 636, Update packaging detection in
get_deployed_benchmarks to use lang_cfg.get("containers") and
lang_cfg.get("code_package") directly as truthiness checks, removing the
redundant membership tests while preserving the existing container,
code_package, and unknown precedence.

Source: Linters/SAST tools


161-163: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Class-level mutable list attribute.

Ruff flags SUPPORTED_CLOUDS as a mutable default at class scope (RUF012). It's only iterated today, but annotating as ClassVar (or using a Tuple) makes the immutability intent explicit and future-proofs against accidental in-place mutation.

♻️ Suggested tweak
-    # Cloud platforms that own a per-cloud cache file (`<cloud>.json`).
-    SUPPORTED_CLOUDS: List[str] = ["azure", "aws", "gcp", "openwhisk", "local"]
+    # Cloud platforms that own a per-cloud cache file (`<cloud>.json`).
+    SUPPORTED_CLOUDS: ClassVar[Tuple[str, ...]] = ("azure", "aws", "gcp", "openwhisk", "local")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sebs/cache.py` around lines 161 - 163, Update the SUPPORTED_CLOUDS class
attribute to declare class-level ownership and prevent mutable-default linting,
using ClassVar with an immutable tuple or another immutable representation.
Preserve the existing cloud values and iteration behavior.

Source: Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@sebs/cache.py`:
- Around line 528-636: Update packaging detection in get_deployed_benchmarks to
use lang_cfg.get("containers") and lang_cfg.get("code_package") directly as
truthiness checks, removing the redundant membership tests while preserving the
existing container, code_package, and unknown precedence.
- Around line 161-163: Update the SUPPORTED_CLOUDS class attribute to declare
class-level ownership and prevent mutable-default linting, using ClassVar with
an immutable tuple or another immutable representation. Preserve the existing
cloud values and iteration behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 83639dca-bfae-41e3-906d-26624b4eb8ad

📥 Commits

Reviewing files that changed from the base of the PR and between 74db93e and fb17cbc.

📒 Files selected for processing (3)
  • sebs/cache.py
  • sebs/cli.py
  • tests/test_cache_inspect.py

@sanskar-singh-2403

sanskar-singh-2403 commented Jul 29, 2026

Copy link
Copy Markdown
Author

@mcopik this pr is ready to be reviewed, let me know your thoughts, Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant