Skip to content

[Bug][Bitbucket] Bitbucket ignores the updated_on filter on /pipelines, so every run appends all pipelines to the raw table and Extract Pipelines grows without bound #9430

Open

Description

@eahmad-fhz

Search before asking

  • I had searched in the issues and found no similar issues.

What happened

On a Bitbucket Cloud repo with ~22k pipelines, the blueprint run time grew from ~25 min to ~9 h over three weeks. "Extract Pipelines" accounts for 485 of the 536 minutes of the latest run.

  • Every incremental run of "Collect Pipelines" fetches all ~445 pages (~22k pipelines), not only the ones updated since the last run.
  • Each run appends them to _raw_bitbucket_api_pipelines. Raw rows are deleted only on a full sync, so the table now holds ~35 copies of every pipeline.
  • "Extract Pipelines" uses NewApiExtractor and re-reads every raw row on every run. Rows extracted per run went from 221k (50 min) to 767k (485 min).

Root cause:

  1. pipeline_collector.go uses NewStatefulApiCollector with GetQueryCreatedAndUpdated, which adds q=updated_on>=<since>. Bitbucket Cloud's GET /2.0/repositories/{workspace}/{repo_slug}/pipelines/ ignores q: q=updated_on>=2099-01-01T00:00:00Z returns the full size, and an invalid q returns no error and the full size. The same q on /pullrequests returns 0. Atlassian's OpenAPI spec (https://api.bitbucket.org/swagger.json) lists no q parameter for list pipelines; created_on is listed but matches one exact timestamp only.
  2. pipeline_extractor.go uses NewApiExtractor, which reads all raw rows for the params on every run.

Same class as #9421 (GitHub GraphQL) and #9305 (CircleCI, fixed in #9313).

What do you expect to happen

An incremental run should extract only the raw rows added since the previous run, and collection should not append a full copy of every pipeline each run, so run time stays flat.

Proposed fix:

  1. Extractor: switch to NewStatefulApiExtractor, with the deployment/production patterns as SubtaskConfig so changing them triggers a full re-extract. PR to follow.
  2. Collector (follow-up): Bitbucket honours sort=-created_on. Use NewStatefulApiCollectorForFinalizableEntity (stop paging at the last run's created_on, re-collect unfinished pipelines) so the raw table stops growing.

How to reproduce

  1. Add a Bitbucket Cloud repo with a few thousand pipelines to a project with CI/CD enabled.
  2. Run the blueprint several times without full sync.
  3. select count(*), count(distinct convert_from(data,'UTF8')::jsonb->>'uuid') from _raw_bitbucket_api_pipelines grows by one full copy per run, and "Extract Pipelines" time grows with it.

Anything else

Every run. The three files involved are unchanged on main as of 652d7da.

Workaround: delete older raw copies, keeping the newest row per pipeline uuid, between runs:

DELETE FROM _raw_bitbucket_api_pipelines r
USING (SELECT id, row_number() OVER (PARTITION BY params, convert_from(data,'UTF8')::jsonb->>'uuid' ORDER BY id DESC) rn
       FROM _raw_bitbucket_api_pipelines) d
WHERE r.id = d.id AND d.rn > 1;

Version

v1.0.3-beta18

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

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

Metadata

Metadata

Assignees

Labels

type/bugThis issue is a bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions