Skip to content

Add protobuf ingestion adapter and indexing parity - #1450

Open
jwils wants to merge 7 commits into
mainfrom
joshuaw/proto-ingestion-adapter
Open

jwils wants to merge 7 commits into
mainfrom
joshuaw/proto-ingestion-adapter

Conversation

@jwils

@jwils jwils commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Why

The indexer has a format-neutral IngestionAdapter seam and shared for_each_ingestion_format test suite (#1412), but the :proto format is still pending because elasticgraph-proto_ingestion does not yet validate native protobuf records or register a "proto" ingestion adapter.

What

Add ProtoIngestion::RecordValidator and ProtoIngestion::IngestionAdapter, wire ProtoIngestion::IndexerExtension to register "proto", and enable :proto across the shared indexer test suite.

How

ProtoIngestion::RecordValidator validates ElasticGraph constraints that protobuf wire decoding cannot express: unknown enum integer values, JsonSafeLong range, finite Float values, calendar Date strings, DateTime Timestamp bounds, LocalTime, TimeZone, and Untyped JSON payloads. Retained wire-contract checks (JsonSafeLong and enum membership) stay unsampled when skip_record_validation: true.

ProtoIngestion::IngestionAdapter validates incoming Event[Google::Protobuf::Message] records, unwraps top-level union/interface messages to their concrete subtype, verifies required rollover timestamps, and pairs events with ProtoIngestion::RecordPreparer without JSON schema version checks.

Risk

Activates "proto" ingestion when protobuf runtime metadata is present in the schema artifacts. Existing JSON ingestion paths are unchanged.

Testing

No manual testing. The schema evolution acceptance specs now run their old-event ingestion examples for both formats; the dump checks that guard JSON schema versions stay JSON-only. Ignoring old events for a deleted indexed type remains pending for :proto, since the current envelope reserves that type's alternative and the event decodes without a record.

Bigger picture

Completes the 3-PR protobuf indexing parity stack (#1441, #1442, #1450), running the shared elasticgraph-indexer unit, integration, and acceptance specs against both :json and :proto.

@jwils
jwils marked this pull request as draft November 2, 2026 00:56
@jwils
jwils added this pull request to stack #1443 November 2, 2026 00:56
@jwils
jwils force-pushed the joshuaw/proto-ingestion-adapter branch from 1cc170f to 9ec7bb3 Compare November 4, 2026 23:50
@jwils
jwils force-pushed the joshuaw/proto-ingestion-adapter branch from 9ec7bb3 to 0cdff9d Compare November 5, 2026 20:08
@jwils
jwils force-pushed the joshuaw/proto-ingestion-adapter branch from 0cdff9d to bc946a1 Compare November 9, 2026 15:58
@jwils
jwils force-pushed the joshuaw/proto-ingestion-adapter branch from bc946a1 to 8099960 Compare November 9, 2026 16:10
jwils added a commit that referenced this pull request Nov 9, 2026
## Why

The shared indexer specs need real protobuf publishers before they can
exercise protobuf ingestion. Their protobuf round trip is still a
placeholder.

## What

Add a test publisher that compiles `schema.proto`, encodes event
batches, and decodes native protobuf records. Extract the shared
`protoc` locator from the existing schema test helper.

## How

The publisher walks protobuf descriptors and uses the generated runtime
metadata for scalar and enum overrides. Each instance owns its
descriptor pool, so tests can encode with an older publisher and decode
with the current schema.

Focused specs cover proto2 and proto3, field presence, nested lists and
abstract types, exact 64-bit integers, timestamps, and disk-backed
artifacts. The publisher stays independent of the production record
preparer.

## Risk

Adds test support and declares runtime dependencies on
`elasticgraph-indexer` and `google-protobuf`. Protobuf ingestion remains
inactive; existing indexing examples stay pending.

## Testing

No manual testing.

## Bigger picture

This prepares the shared indexer parity suite for real protobuf
publishing. Record preparation (#1442) and adapter integration plus
parity-test activation (#1450) follow in this stack.
@jwils
jwils force-pushed the joshuaw/proto-ingestion-adapter branch from 8099960 to 05b08cc Compare November 9, 2026 16:29
@jwils
jwils force-pushed the joshuaw/proto-ingestion-adapter branch 3 times, most recently from 81cf6c4 to 79f2aca Compare November 22, 2026 00:16
@jwils
jwils marked this pull request as ready for review November 22, 2026 18:04
@jwils
jwils force-pushed the joshuaw/proto-ingestion-adapter branch from 79f2aca to e6373db Compare November 25, 2026 18:56
Base automatically changed from joshuaw/proto-record-conversion to main November 29, 2026 15:23
jwils added a commit that referenced this pull request Nov 29, 2026
## Why

The indexer needs datastore hashes, but protobuf publishers produce
native messages. Converting them into public record hashes first adds a
full traversal and extra allocations.

## What

Prepare native protobuf messages directly into datastore records in one
pass using the generated protobuf runtime metadata and `google-protobuf`
descriptors.

## How

`ProtoIngestion::RecordPreparer` caches field plans built from protobuf
descriptors. Sparse runtime metadata supplies field-name overrides, enum
names, and scalar types. Renamed built-in scalars retain their indexing
preparers, and enum symbols and numbers map consistently across Ruby
runtimes.

The preparer applies shared scalar rules, unwraps abstract `oneof`
records, prepares message scalars such as `google.protobuf.Timestamp`
from their canonical protobuf JSON form through the scalar's indexing
preparer, and parses and canonicalizes `Untyped` leaves. The shared
indexing pipeline adds `__counts` afterward.

Preserves field presence, explicit defaults, exact 64-bit integers,
nested lists, and concrete types in a single pass.

## Risk

Adds `ProtoIngestion::RecordPreparer` and
`RuntimeMetadata::Schema.from_schema_artifacts`, which become active
when #1450 registers the protobuf ingestion adapter. Runtime
dependencies are `elasticgraph-indexer` and `google-protobuf`.

## Testing

No manual testing. Covered by integration specs in
`record_preparer_spec.rb` and unit specs in
`runtime_metadata/schema_spec.rb`.

## Bigger picture

Builds on #1441's protobuf publishing test support. Native record
validation, adapter registration, and activation of the shared indexing
parity suite follow in #1450.

---------

Signed-off-by: Josh Wilson <joshuaw@squareup.com>
Co-authored-by: Neon <f833053fa3445a7878359a1bd17c4f6b4ed1ceb3e7414f306f4929b1f9032d02@buzz>
@jwils
jwils force-pushed the joshuaw/proto-ingestion-adapter branch from e6373db to 6536995 Compare November 29, 2026 15:31
jwils and others added 7 commits November 30, 2026 12:52
- Extract ElasticGraph::ProtoIngestion::Descriptors to deduplicate descriptor walking across RecordPreparer, RecordValidator, and IngestionAdapter
- Fix IngestionAdapter to check Google::Protobuf::MessageExts, handle repeated id_source paths on rollover targets, and guard against raise
- Validate DateTime fields overridden to protobuf string in RecordValidator
- Cover Duration, string DateTime, and repeated derived id_source rollover checks in indexing_parity_spec
- Fix RBS signatures and YARD return types

Co-authored-by: Josh Wilson <joshuaw@squareup.com>
Signed-off-by: Josh Wilson <joshuaw@squareup.com>
`record_preparer_spec` covers record preparation directly, so these examples now assert only on adapter and validator behavior.

Co-authored-by: Josh Wilson <joshuaw@squareup.com>
Signed-off-by: Josh Wilson <joshuaw@squareup.com>
…or both formats

Split the indexing parity spec into an integration parity spec and an
`IngestionAdapter` spec that drives the indexer, defines each schema once,
uses one example per case, and covers NaN floats and out-of-range
`DateTime` string components. Add an `IndexerExtension` spec.

In the schema evolution specs, move the JSON-only dump checks into their
own examples so that the old-event ingestion examples run for protobuf
too. Only the deleted indexed type example remains pending for protobuf.
Replace the `respond_to?` publisher capture with a hook each ingestion
format implements.

Co-authored-by: Josh Wilson <joshuaw@squareup.com>
Signed-off-by: Josh Wilson <joshuaw@squareup.com>
…xerExtension

- Eagerly resolve nested `RecordValidator` type plans while holding `@mutex` once per root record, moving validation onto polymorphic `Type#error_for`, `AbstractType#error_for`, and `Field#error_for` (marked `@private` for YARD)
- Drop the empty `Data.define` block on `Descriptors::UnwrappedField` and mark it `@private`
- Lazily require `ingestion_adapter` inside `IndexerExtension#ingestion_adapters_by_format` so referencing `IndexerExtension.name` from `RuntimeMetadata::Schema` and `SchemaDefinition::ResultsExtension` does not cause a circular require or load the indexer at schema-definition time

Co-authored-by: Neon <f833053fa3445a7878359a1bd17c4f6b4ed1ceb3e7414f306f4929b1f9032d02@buzz>
Signed-off-by: Josh Wilson <joshuaw@squareup.com>
Apply the #1442 review feedback that moved `RecordPreparer` off its
mutex to `RecordValidator` too. `Support::ThreadSafeCache` takes a
reentrant `Monitor`, so `build_type` can still resolve nested types
through the same cache while the lock is held once per root record.

Co-authored-by: Executor1 <7c44932696c451281ba60b1d7e7d4ff253bb8a7f11e58ae1e8e3a5945334567c@sprout-oss.stage.blox.sqprod.co>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Josh Wilson <joshuaw@squareup.com>
Signed-off-by: Josh Wilson <joshuaw@squareup.com>
- Use `ProtoConversions::ABSTRACT_TYPE_ONEOF_NAME` and `ProtoConversions::LIST_WRAPPER_VALUES_FIELD_NAME` in `Descriptors`, `RecordValidator`, and `IngestionAdapter` instead of hardcoded `"value"` / `"values"` names
- Drop the unused `path` parameter from `RecordValidator#error_for` and extract `DATE_REGEX`
- Consolidate `IngestionAdapter` `@update_targets` and `@ingestible_types` into `@update_targets_by_type` and make the non-ingestible error message accurate for concrete and abstract types
- Replace `schema.respond_to?(:json_schema_version)` in `schema_evolution_spec.rb` with a format check and generalize the shared example descriptions
- Close mutation-testing gaps in `ingestion_adapter_spec.rb` (`Date` trailing characters, renamed scalar error name, `camelCase` field presence, concrete field named `value`), use `:STATE_UNSPECIFIED`, and qualify top-level constants with `::`

Co-authored-by: Neo <f833053fa3445a7878359a1bd17c4f6b4ed1ceb3e7414f306f4929b1f9032d02@buzz>
Signed-off-by: Josh Wilson <joshuaw@squareup.com>
@jwils
jwils force-pushed the joshuaw/proto-ingestion-adapter branch from 6536995 to 19209fc Compare November 30, 2026 19:05

This branch has not been deployed

No deployments
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