Skip to content

refactor: rework the download ingestion pipeline - #2132

Merged
netomi merged 3 commits into
mainfrom
split/ingestion-rework
Sep 13, 2026
Merged

netomi merged 3 commits into
mainfrom
split/ingestion-rework

Conversation

@netomi

@netomi netomi commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Stack: 3 of 6. Split out of #2027. Base: #2131 (split/ingestion-move).

This is the highest-risk part of #2027, isolated so it can be reviewed for what it actually is: a rewrite of live download counting.

Why this needed separating

#2027 presents itself as opt-in (ovsx.analytics.enabled, default false). The analytics are. This rework is not — it replaces the download-count pipeline for every deployment regardless of that flag. That is not visible from the PR description, and it is the regression risk in the whole change.

So this PR carries the restructuring with no analytics behaviour attached.

What changes

  • a log handler per storage backend becomes a DownloadRecordSource yielding RawDownloadRecords
  • DownloadCountProcessor becomes DownloadIngestionProcessor: resolves records to extensions (Caffeine-cached), aggregates, applies the counts
  • scheduling moves out of the handlers into DownloadIngestionRunner and the jobs package
  • AwsDownloadCountHandler splits into AwsDownloadRecordSource + the CloudFront and Fastly parsers; LogRecord becomes AccessLogRecord
  • StorageUtilService no longer asks a DownloadCountService whether a resource is covered, it asks the sources themselves; DownloadCountServiceAspect goes with the service it wrapped
  • DownloadCountProcessedItem -> DownloadIngestion, and V1_75 renames the table to match; its repository gains countFailedDownloadIngestions

The analytics seam is present but inert

DownloadAnalyticsRepository is here as an interface with no implementation, so the ObjectProvider the processor holds is never satisfied and only download counts are written. The single implementation anywhere in the tree is a test fake.

That is what makes "did download counting regress?" an answerable question in this PR.

Two deliberate deviations from #2027 for this purpose:

  • the interface is narrowed to save(List<DownloadEvent>). Its findSeries half drags in the whole query model (DownloadSeriesRequest, DownloadSeriesRow, and their enums), so it is added back with the Timescale implementation rather than carried here as five unused files.
  • captureDownload stays in the processor, guarded by analyticsRepository.ifAvailable, rather than being removed and re-added. It does nothing until the implementation lands. Its call site on the download-serving path is worth a look when it becomes live — it is a synchronous write on the registry's hottest endpoint.

The table rename

The second commit renames the table, so the schema stops carrying a name that only makes sense against a class that no longer exists. It is worth reviewing on its own terms, because it is the one part of this PR that is not backward compatible.

Everything in V1_75 is a catalog-only rename — the table, its primary key constraint, both indexes and the sequence. No data is copied and no column changes type, so there is no table rewrite and the ACCESS EXCLUSIVE lock is held only for as long as it takes to update the catalog rows. The indexes, constraint and sequence are renamed explicitly because renaming a table leaves them behind under their original names, which is exactly the half-renamed schema the migration exists to avoid. The sequence keeps its OWNED BY link, and its INCREMENT 50 still matches the entity's default allocationSize.

src/main/jooq-gen is regenerated, which is where most of that commit's diff comes from. Nothing referenced the generated table — it is reached only through JPA, via DownloadIngestionRepository and JPQL naming the entity.

What it is not safe against is an older server instance still running after the migration: its queries name the old table and will fail until it is replaced. The failure is loud rather than silent, and confined to the hourly ingestion job — this table is a ledger of which log files have been processed, so a failed run neither loses nor double-counts downloads, it retries on the next tick. Deployments running more than one server instance should expect errors in that window, and anyone with queries or dashboards against download_count_processed_item needs to know.

This corrects an earlier note on this PR, which said the entity rename carried no schema change. That was true of #2027, which has no migration at all; it is no longer true here.

Resolving the ingestion sources

The third commit. Two call sites each scanned the sources to answer "which source, if any, handles this storage type" — StorageUtilService.increaseDownloadCount via anyMatch(covers), and LogIngestionJob via filter(getStorageType().equals(t) && isEnabled()). They now share a DownloadRecordSourceIndex, built once per holder in a @PostConstruct and keyed by storage type. It is a plain object rather than a bean so that neither constructor signature changes, which keeps the six test configurations that wire StorageUtilService untouched.

The scan mattered most in StorageUtilService, which runs on every download: ObjectProvider.stream() resolves matching beans from the bean factory on each call, so the hottest endpoint in the registry paid a bean lookup plus a covers() call per source to answer a question with two possible answers.

Asking isEnabled() once at startup is safe — every input to it is a configuration property, fixed once the bean is initialized — and it fixes a logging bug worth calling out on its own: AzureDownloadRecordSource warns from inside isEnabled() when its logs endpoint is set but its storage endpoint is not, and covers() called isEnabled(). A half-configured Azure deployment was emitting that warning on every single download.

Enablement also leaves the covers() contract. Both implementations ended with && isEnabled() — correct, but it left every future source one forgotten conjunct away from suppressing downloads that nothing ingests, since the request path would skip them and the disabled job would never pick them up. A source that is not enabled is now absent from the index, so covers() answers coverage only and the guarantee holds for implementations not yet written. To be clear about what this is: a robustness and performance change, not a bug fix — the && isEnabled() conjuncts meant downloads were never actually lost.

Two enabled sources for one storage type would each claim the same downloads, with bean ordering deciding which answered; LogIngestionJob took the first via findFirst(). That now fails at startup instead.

The test pool cap

spring.datasource.hikari.maximum-pool-size: 4 in the test config, taken from #2027's own 35e5126e3.

The new processor test adds another cached Spring context, and each context holds an idle pool of 10 against the one shared container, exhausting its max_connections mid-suite. It surfaced as two failures with no apparent connection to this change — RepositoryServiceSmokeTest.testExecuteQueries and the recovery-lock test — both of which pass in isolation.

Worth noting for the Timescale PR that follows: this is a test-infra symptom of an unanswered production question. A second datasource means two pools per deployment, and the combined connection budget against the deployed max_connections has not been stated anywhere.

Verification

Full server suite: 1315 tests passing, with Flyway reporting Successfully applied 76 migrations, so V1_75 is exercised by every integration test rather than only applied in isolation. All pre-commit hooks pass.

The migration was also applied from scratch against a clean Postgres 16.2 to confirm it leaves no object — table, constraint, index or sequence — still carrying the old name.

Refs #2027, #2025

netomi and others added 3 commits September 13, 2026 11:09
Reworks the log-based download ingestion that PR #2027 needs, with no analytics
behaviour attached, so that the restructuring of live download counting can be
reviewed on its own.

A log handler per storage backend becomes a DownloadRecordSource that yields
RawDownloadRecords, and DownloadCountProcessor becomes DownloadIngestionProcessor,
which resolves records to extensions (with a Caffeine cache), aggregates them and
applies the download counts. Scheduling moves out of the handlers into
DownloadIngestionRunner and the jobs package. AwsDownloadCountHandler splits into
AwsDownloadRecordSource plus the CloudFront and Fastly parsers, and LogRecord
becomes AccessLogRecord.

StorageUtilService no longer asks a DownloadCountService whether a resource is
covered; it asks the sources themselves. DownloadCountServiceAspect goes with the
service it wrapped.

DownloadCountProcessedItem is renamed to DownloadIngestion, keeping its table
name, so there is no migration. Its repository gains countFailedDownloadIngestions.

The analytics seam is present but inert: DownloadAnalyticsRepository is an
interface with no implementation in this change, so the ObjectProvider the
processor holds is never satisfied and only the download counts are written. The
implementation, and the findSeries half of that interface, come with the analytics
work.

The test datasource pool is capped at 4. The new processor test adds another
cached Spring context, and each one holds an idle pool of 10 against the single
shared container, which exhausts its max_connections mid-suite - it surfaced as
unrelated failures in RepositoryServiceSmokeTest and the recovery-lock test.

Co-Authored-By: gnugomez <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The DownloadCountProcessedItem -> DownloadIngestion rename kept @table(name =
"download_count_processed_item"), so the schema still carried a name that only
makes sense against a class that no longer exists. V1_75 completes it.

Everything in the migration is a catalog-only rename - the table, its primary
key constraint, both indexes and the sequence. No data is copied and no column
changes type, so there is no table rewrite; the ACCESS EXCLUSIVE lock is held
only for as long as it takes to update the catalog rows. The indexes, the
constraint and the sequence are renamed explicitly because renaming a table
leaves them behind under their original names, which is precisely the
half-renamed schema the migration exists to avoid.

The sequence keeps its OWNED BY link across the rename, and its INCREMENT 50
still matches the entity's default allocationSize.

src/main/jooq-gen is regenerated, which is where the rest of the diff comes
from. Nothing referenced the generated table: it is reached only through JPA,
via DownloadIngestionRepository and JPQL naming the entity.

What this is not safe against is an older server instance still running after
the migration - its queries name the old table and will fail until it is
replaced. The failure is loud and confined to the hourly ingestion job, and
this table is a ledger of which log files have been processed, so a failed run
neither loses nor double-counts downloads, it retries on the next tick.
Deployments running more than one server instance should expect errors in that
window.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Two call sites each scanned the ingestion sources to answer "which source, if
any, handles this storage type":

  StorageUtilService  sources.stream().anyMatch(source -> source.covers(resource))
  LogIngestionJob     sources.stream().filter(s -> s.getStorageType().equals(t) && s.isEnabled())

Both now share a DownloadRecordSourceIndex, built once per holder in a
@PostConstruct and keyed by storage type. It is a plain object rather than a
bean so that neither constructor signature changes, which keeps the six test
configurations that wire StorageUtilService untouched.

The scan mattered most in StorageUtilService, which runs on every download:
ObjectProvider.stream() resolves matching beans from the bean factory on each
call, so the registry's hottest endpoint paid a bean lookup plus a covers() call
per source to answer a question with two possible answers. It is now a map
lookup.

Asking isEnabled() once at startup is safe - every input to it is a
configuration property, fixed once the bean is initialized - and it fixes a
logging bug. AzureDownloadRecordSource warns from inside isEnabled() when its
logs endpoint is set but its storage endpoint is not, and covers() called
isEnabled(), so a half-configured Azure deployment emitted that warning on every
single download.

Enablement is no longer part of the covers() contract. Both implementations
ended with "&& isEnabled()", which was correct but left every future source one
forgotten conjunct away from suppressing downloads that nothing ingests - the
request path would skip them and the disabled job would never pick them up. A
source that is not enabled is now absent from the index altogether, so covers()
answers coverage only, as its name says, and the guarantee holds for
implementations that have not been written yet.

Two enabled sources for one storage type would each claim the same downloads,
with bean ordering deciding which answered. LogIngestionJob previously took the
first via findFirst(); that now fails at startup instead.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@netomi
netomi force-pushed the split/ingestion-rework branch from 1d4903e to d712802 Compare September 13, 2026 09:18
@netomi
netomi merged commit 05873c8 into main Sep 13, 2026
5 checks passed
@netomi
netomi deleted the split/ingestion-rework branch September 13, 2026 09:23
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