-
Notifications
You must be signed in to change notification settings - Fork 37
Route events through a typed Event value #1398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Copyright 2024 - 2026 Block, Inc. | ||
| # | ||
| # Use of this source code is governed by an MIT-style | ||
| # license that can be found in the LICENSE file or at | ||
| # https://opensource.org/licenses/MIT. | ||
| # | ||
| # frozen_string_literal: true | ||
|
|
||
| require "elastic_graph/constants" | ||
| require "elastic_graph/indexer/event_id" | ||
|
|
||
| module ElasticGraph | ||
| class Indexer | ||
| # An indexing event with a validated envelope. Ingestion adapters build events after they | ||
| # validate the envelope in their own format, so every `Event` instance has typed envelope | ||
| # fields. `record` keeps the adapter's native record type (a `Hash` for JSON events). | ||
| # | ||
| # @!attribute [r] op | ||
| # @return [String] the operation to apply (`upsert`) | ||
| # @!attribute [r] type | ||
| # @return [String] the GraphQL type of the record | ||
| # @!attribute [r] id | ||
| # @return [String] the unique identifier of the record | ||
| # @!attribute [r] version | ||
| # @return [Integer] version used to order events for the same `type` and `id` | ||
| # @!attribute [r] record | ||
| # @return [Object] the record payload, in the ingestion adapter's native type | ||
| # @!attribute [r] schema_version | ||
| # @return [Integer] the version of the ingestion schema the publisher used | ||
| # @!attribute [r] ingestion_format | ||
| # @return [String] the format tag that selects the ingestion adapter | ||
| # @!attribute [r] message_id | ||
| # @return [String, nil] the id of the transport message that carried the event | ||
| # @!attribute [r] latency_timestamps | ||
| # @return [Hash<String, String>] ISO8601 timestamps from which indexing latency is measured | ||
| Event = ::Data.define(:op, :type, :id, :version, :record, :schema_version, :ingestion_format, :message_id, :latency_timestamps) do | ||
| # @implements Event[R] | ||
|
|
||
| def initialize(op:, type:, id:, version:, record:, schema_version:, ingestion_format:, message_id: nil, latency_timestamps: {}) | ||
| super | ||
| end | ||
|
|
||
| # @return [EventID] identifies this event by its `type`, `id`, and `version` | ||
| def event_id | ||
| EventID.new(type: type, id: id, version: version) | ||
| end | ||
|
|
||
| # Builds an event from a JSON event hash whose envelope has already been validated. | ||
| # | ||
| # @param hash [Hash<String, Object>] a validated JSON event | ||
| # @return [Event] | ||
| def self.from_validated_hash(hash) | ||
| latency_timestamps = hash["latency_timestamps"] || {} # : ::Hash[::String, ::String] | ||
|
|
||
| new( | ||
| op: hash.fetch("op"), | ||
| type: hash.fetch("type"), | ||
| id: hash.fetch("id"), | ||
| version: hash.fetch("version"), | ||
| record: hash.fetch("record"), | ||
| schema_version: hash.fetch(JSON_SCHEMA_VERSION_KEY), | ||
| ingestion_format: hash.fetch(INGESTION_FORMAT_KEY, "json"), | ||
|
myronmarston marked this conversation as resolved.
|
||
| message_id: hash["message_id"], | ||
| latency_timestamps: latency_timestamps | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| # Steep weirdly expects them here... | ||
|
myronmarston marked this conversation as resolved.
|
||
| # @dynamic initialize, config, datastore_core, schema_artifacts, datastore_router, monotonic_clock | ||
| # @dynamic processor, operation_factory, ingestion_adapters_by_format, logger | ||
| # @dynamic self.from_parsed_yaml | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,7 @@ def event | |
| end | ||
|
|
||
| def event_id | ||
| EventID.from_event(event) | ||
| event.event_id | ||
| end | ||
|
|
||
| def summary | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.