Skip to content

Annotate the content membership experiment SQL with the repository (P… - #1651

Merged
dkliban merged 2 commits into
pulp:mainfrom
larrymou9:lrios/pulp-2346-repo-annotation
Oct 28, 2026
Merged

dkliban merged 2 commits into
pulp:mainfrom
larrymou9:lrios/pulp-2346-repo-annotation

Conversation

@larrymou9

@larrymou9 larrymou9 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Annotate the PULP-1996 experiment's SQL with the target repository, so RDS Performance Insights shows the variant and the repo. Follow-up from the #1643 review.

Each pexp=... v=A|B marker in patch 0081 is now followed by /* repo=<repository pk> */. The existing marker is unchanged, so the collector pattern (#1650) and the existing tests still match. It uses self.repository_id, so there is no extra database fetch.

Optional: repository on the dispatch log line

The ab_experiment_dispatch log line also gets a repository_id field (second commit), so CloudWatch can count dispatches per repository and variant. This is separate from the SQL annotation and can be dropped if not wanted. run_lazy_experiment() takes an optional repository_id (null when not passed), and the call in patch 0081 passes self.repository_id.

Testing

  • Patch 0081 applies to pulpcore 3.122.1 on top of the full patch stack, and compiles.
  • Compiled both variants' SQL in a perf pod with real Django and pulpcore (in memory, no DB access). Both markers are in the SQL for both variants:
Query pexp repo=<id>
Variant A subquery yes yes
Variant B subquery yes yes
Content filtered by A / B yes yes
  • The repo comment sits at character 89–391 of the query text, within prod's 4 kB limit (track_activity_query_size).
  • ruff check and ruff format --check pass.
  • Ran the real run_lazy_experiment() with stand-ins for the logger and Django: the dispatch line has repository_id when passed and null otherwise, and the other fields are unchanged.

Summary by Sourcery

Add repository context to content experiment SQL and dispatch telemetry while preserving existing experiment markers and behavior.

New Features:

  • Annotate content membership experiment SQL with the target repository identifier for repository-level performance analysis.
  • Include the target repository identifier in experiment dispatch logs when available.

Tests:

  • Extend interval content experiment tests to verify repository identifiers in dispatch logs and SQL markers.

…ULP-1996)

Add a second comment, `/* repo=<repository pk> */`, after each variant's
`pexp=... v=A|B` marker in patch 0081, so RDS Performance Insights shows both
the variant and the target repository. The existing marker is unchanged, so
the experiment collector's pattern and the existing test assertions still match.

Use self.repository_id, which is already on the RepositoryVersion, to avoid a
database fetch of the repository on every call. Add a test assertion for the
repo comment.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds repository identity to each content membership experiment SQL annotation using the existing repository ID, without changing the collector-facing variant marker, and verifies the new comment in the query test.

File-Level Changes

Change Details Files
Annotates experiment SQL with the target repository while preserving the existing variant marker.
  • Appends a /* repo=<repository pk> */ comment after each `pexp=... v=A
Bmarker in patch 0081.</li><li>Uses the existingRepositoryVersion.repository_id` value to avoid fetching the repository per call.
  • Keeps the existing variant marker unchanged for collector compatibility.
  • Extends the unit test to verify repository attribution in captured SQL.
    • Updates the test description to cover both markers.
    • Asserts captured queries contain the repository primary-key comment while retaining the existing variant-marker assertion.
    pulp_service/pulp_service/tests/unit/test_interval_content_experiment.py

    Tips and commands

    Interacting with Sourcery

    • Trigger a new review: Comment @sourcery-ai review on the pull request.
    • Continue discussions: Reply directly to Sourcery's review comments.
    • Generate a GitHub issue from a review comment: Ask Sourcery to create an
      issue from a review comment by replying to it. You can also reply to a
      review comment with @sourcery-ai issue to create an issue from it.
    • Generate a pull request title: Write @sourcery-ai anywhere in the pull
      request title to generate a title at any time. You can also comment
      @sourcery-ai title on the pull request to (re-)generate the title at any time.
    • Generate a pull request summary: Write @sourcery-ai summary anywhere in
      the pull request body to generate a PR summary at any time exactly where you
      want it. You can also comment @sourcery-ai summary on the pull request to
      (re-)generate the summary at any time.
    • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
      request to (re-)generate the reviewer's guide at any time.
    • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
      pull request to resolve all Sourcery comments. Useful if you've already
      addressed all the comments and don't want to see them anymore.
    • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
      request to dismiss all existing Sourcery reviews. Especially useful if you
      want to start fresh with a new review - don't forget to comment
      @sourcery-ai review to trigger a new review!

    Customizing Your Experience

    Access your dashboard to:

    • Enable or disable review features such as the Sourcery-generated pull request
      summary, the reviewer's guide, and others.
    • Change the review language.
    • Add, remove or edit custom review instructions.
    • Adjust other review settings.

    Getting Help

    @sourcery-ai sourcery-ai Bot left a comment

    Copy link
    Copy Markdown
    Contributor

    Choose a reason for hiding this comment

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

    Hey - I've found 1 issue

    Prompt for AI Agents
    Please address the comments from this code review:
    
    ## Individual Comments
    
    ### Comment 1
    <location path="pulp_service/pulp_service/tests/unit/test_interval_content_experiment.py" line_range="142" />
    <code_context>
             with CaptureQueriesContext(connection) as ctx:
                 assert list(version.get_content())
             assert any(marker in query["sql"] for query in ctx.captured_queries), marker
    +        repo_marker = f"/* repo={repository.pk} */"
    +        assert any(repo_marker in query["sql"] for query in ctx.captured_queries), repo_marker
    </code_context>
    <issue_to_address>
    **Release note fragment missing**
    
    When this non-trivial SQL annotation change is merged, the SQL annotation change and its test assertion are included without a Towncrier fragment, so the required release note is absent.
    
    Add a `CHANGES/{issue_number}.{category}` fragment for the change.
    </issue_to_address>

    Sourcery assessment

    Approval pending. 1 finding to address first.

    Blocking findings: pulp_service/pulp_service/tests/unit/test_interval_content_experiment.py:142


    Sourcery is free for open source - if you like our reviews please consider sharing them ✨

    with CaptureQueriesContext(connection) as ctx:
    assert list(version.get_content())
    assert any(marker in query["sql"] for query in ctx.captured_queries), marker
    repo_marker = f"/* repo={repository.pk} */"

    Copy link
    Copy Markdown
    Contributor

    Choose a reason for hiding this comment

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

    🟡 Medium · Release note fragment missing

    When this non-trivial SQL annotation change is merged, the SQL annotation change and its test assertion are included without a Towncrier fragment, so the required release note is absent.

    Add a CHANGES/{issue_number}.{category} fragment for the change.

    Prompt for AI agents
    In `pulp_service/pulp_service/tests/unit/test_interval_content_experiment.py` at line 142:
    
    **Release note fragment missing**
    
    When this non-trivial SQL annotation change is merged, the SQL annotation change and its test assertion are included without a Towncrier fragment, so the required release note is absent.
    
    Add a `CHANGES/{issue_number}.{category}` fragment for the change.

    From CLAUDE.md L76:

    Uses **towncrier**. For any non-trivial change, create a file in `CHANGES/` named `{issue_number}.{category}` where category is one of: `feature`, `bugfix`, `doc`, `removal`, `deprecation`, `misc`.

    Log the target repository on each ab_experiment_dispatch line, so CloudWatch
    counts can be split by repository, alongside the SQL annotation for RDS
    Performance Insights. run_lazy_experiment() takes an optional repository_id
    (null when not passed), and the get_content() call in patch 0081 passes
    self.repository_id. Add a test assertion for the field.
    
    Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
    @dkliban

    dkliban commented Oct 28, 2026

    Copy link
    Copy Markdown
    Member

    /ok-to-test

    @kdelee

    kdelee commented Oct 28, 2026

    Copy link
    Copy Markdown
    Contributor

    I tested the exact PR head in a built pulp-service image with pulpcore==3.122.1, applying patch 0081 during the image build.

    Validation:

    • The patch applied cleanly in the image build.
    • Django migrations ran against a real PostgreSQL 16 container.
    • test_get_content_marks_sql_per_variant passed (1 passed), exercising both variants and capturing the SQL actually sent through Django.
    • The generated SQL contained the expected form for both variants:
    ... /* pexp=PULP-1996-CONTENT-MEMBERSHIP v=A */ /* repo=<repository UUID> */ ...
    ... /* pexp=PULP-1996-CONTENT-MEMBERSHIP v=B */ /* repo=<repository UUID> */ ...

    The format string therefore works at runtime and the repository comment survives into the executed SQL. A production/PI check is still needed after rollout to verify that Performance Insights retains and displays the new comment.

    One follow-up: the current experiment-results collector groups PI data by experiment, variant, and SQL ID, but does not yet parse the new repo=... comment. It will need a repo-aware regex and rollup before it can report per-repository results. The CloudWatch query also needs to group the new repository_id dispatch field for per-repository dispatch counts.

    @kdelee kdelee left a comment

    Copy link
    Copy Markdown
    Contributor

    Choose a reason for hiding this comment

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

    LGTM, not sure if we need that changelog fragment to be able to merge

    @dkliban
    dkliban merged commit 7ee62c1 into pulp:main Oct 28, 2026
    5 of 6 checks passed
    dkliban added a commit that referenced this pull request Oct 29, 2026
    * Revert "Annotate the content membership experiment SQL with the repository (P… (#1651)"
    
    This reverts commit 7ee62c1.
    
    * Revert "Optimize read-only content queries and interval content experiment (PULP-2346, PULP-1996; merge after #1642) (#1643)"
    
    This reverts commit 0035e1e.
    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.

    3 participants