Skip to content

Commit bd53a07

Browse files
committed
Move JSON ingestion into elasticgraph-json_ingestion via an indexer extension
The JSON ingestion adapter and JSON-schema-based record preparer factory move from elasticgraph-indexer to elasticgraph-json_ingestion, and the JSON ingestion schema definition extension registers an indexer extension in runtime metadata that makes the adapter available at indexing time. Any schema defined with JSON ingestion support automatically gets JSON event ingestion--no settings needed--and elasticgraph-indexer no longer contains (or refers to) any JSON-specific ingestion logic. The be_a_valid_elastic_graph_event matcher moves to elastic_graph/json_ingestion/spec_support/event_matcher, and suites that build indexers from the shared test schema artifacts gain a development dependency on elasticgraph-json_ingestion (whose indexer extension those artifacts now reference).
1 parent 1f731a7 commit bd53a07

41 files changed

Lines changed: 831 additions & 637 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Steepfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ target :elasticgraph_gems do
4141
elasticgraph-graphql/lib/elastic_graph/graphql/schema/type.rb
4242
])
4343

44-
# elasticgraph-indexer: existing files that don't type check yet.
44+
# elasticgraph-json_ingestion: RSpec matcher DSL that doesn't type check.
4545
ignore(*%w[
46-
elasticgraph-indexer/lib/elastic_graph/indexer/spec_support/event_matcher.rb
46+
elasticgraph-json_ingestion/lib/elastic_graph/json_ingestion/spec_support/event_matcher.rb
4747
])
4848

4949
# elasticgraph-local: existing files that don't type check yet.

config/schema/artifacts/runtime_metadata.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3219,6 +3219,10 @@ index_definitions_by_name:
32193219
frequency: yearly
32203220
timestamp_field_path: created_at
32213221
route_with: workspace_id2
3222+
indexer_extension_modules:
3223+
- extension_ref:
3224+
name: ElasticGraph::JSONIngestion::IndexerExtension
3225+
require_path: elastic_graph/json_ingestion/indexer_extension
32223226
object_types_by_name:
32233227
Address:
32243228
graphql_fields_by_name:

config/schema/artifacts_with_apollo/runtime_metadata.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3248,6 +3248,10 @@ index_definitions_by_name:
32483248
frequency: yearly
32493249
timestamp_field_path: created_at
32503250
route_with: workspace_id2
3251+
indexer_extension_modules:
3252+
- extension_ref:
3253+
name: ElasticGraph::JSONIngestion::IndexerExtension
3254+
require_path: elastic_graph/json_ingestion/indexer_extension
32513255
object_types_by_name:
32523256
Address:
32533257
graphql_fields_by_name:

elasticgraph-apollo/elasticgraph-apollo.gemspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ Gem::Specification.new do |spec|
5252
spec.add_development_dependency "elasticgraph-schema_definition", ElasticGraph::VERSION
5353
spec.add_development_dependency "elasticgraph-admin", ElasticGraph::VERSION
5454
spec.add_development_dependency "elasticgraph-elasticsearch", ElasticGraph::VERSION
55+
# The test suite builds indexers from the shared test schema artifacts, whose runtime metadata
56+
# registers the JSON ingestion indexer extension provided by `elasticgraph-json_ingestion`.
57+
spec.add_development_dependency "elasticgraph-json_ingestion", ElasticGraph::VERSION
5558
spec.add_development_dependency "elasticgraph-opensearch", ElasticGraph::VERSION
5659
spec.add_development_dependency "elasticgraph-indexer", ElasticGraph::VERSION
5760
end

elasticgraph-indexer/lib/elastic_graph/indexer.rb

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# frozen_string_literal: true
88

99
require "elastic_graph/datastore_core"
10+
require "elastic_graph/errors"
1011
require "elastic_graph/indexer/config"
1112
require "elastic_graph/support/from_yaml_file"
1213

@@ -56,21 +57,11 @@ def datastore_router
5657
end
5758
end
5859

59-
def record_preparer_factory
60-
@record_preparer_factory ||= begin
61-
require "elastic_graph/indexer/record_preparer"
62-
RecordPreparer::Factory.new(schema_artifacts)
63-
end
64-
end
65-
66-
# The ingestion adapters available for processing events. For now, only the JSON events
67-
# adapter is available; indexer extension modules will be able to contribute additional
68-
# adapters as alternate ingestion formats are supported.
60+
# The ingestion adapters available for processing events. Returns an empty list by default;
61+
# ingestion format gems contribute adapters via indexer extension modules that override this
62+
# method.
6963
def ingestion_adapters
70-
@ingestion_adapters ||= begin
71-
require "elastic_graph/indexer/ingestion_adapter/json_events"
72-
[IngestionAdapter::JSONEvents.new(schema_artifacts: schema_artifacts, logger: logger)]
73-
end
64+
[] # : ::Array[IngestionAdapter::adapter]
7465
end
7566

7667
def processor
@@ -88,6 +79,13 @@ def processor
8879

8980
def operation_factory
9081
@operation_factory ||= begin
82+
if ingestion_adapters.empty?
83+
raise Errors::ConfigError, "No ingestion adapters are available to process events. Ingestion format gems " \
84+
"make an adapter available by registering an indexer extension (via `register_indexer_extension`) during " \
85+
"schema definition; ensure your schema definition uses an ingestion format extension and regenerate your " \
86+
"schema artifacts (or configure an extension via the `indexer.extension_modules` setting)."
87+
end
88+
9189
require "elastic_graph/indexer/operation/factory"
9290
Operation::Factory.new(
9391
schema_artifacts: schema_artifacts,

elasticgraph-indexer/lib/elastic_graph/indexer/event_id.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def to_s
2626

2727
# Steep weirdly expects them here...
2828
# @dynamic initialize, config, datastore_core, schema_artifacts, datastore_router, monotonic_clock
29-
# @dynamic record_preparer_factory, processor, operation_factory, ingestion_adapters, logger
29+
# @dynamic processor, operation_factory, ingestion_adapters, logger
3030
# @dynamic self.from_parsed_yaml
3131
end
3232
end

elasticgraph-indexer/lib/elastic_graph/indexer/ingestion_adapter/json_events.rb

Lines changed: 0 additions & 138 deletions
This file was deleted.

elasticgraph-indexer/lib/elastic_graph/indexer/record_preparer.rb

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,58 +11,6 @@
1111
module ElasticGraph
1212
class Indexer
1313
class RecordPreparer
14-
# Provides the ability to get a `RecordPreparer` for a specific JSON schema version.
15-
class Factory
16-
def initialize(schema_artifacts)
17-
@schema_artifacts = schema_artifacts
18-
19-
scalar_types_by_name = schema_artifacts.runtime_metadata.scalar_types_by_name
20-
indexing_preparer_by_scalar_type_name = ::Hash.new do |hash, type_name|
21-
hash[type_name] = scalar_types_by_name[type_name]&.load_indexing_preparer&.extension_class
22-
end # : ::Hash[::String, SchemaArtifacts::RuntimeMetadata::extensionClass?]
23-
24-
@preparers_by_json_schema_version = ::Hash.new do |hash, version|
25-
hash[version] = RecordPreparer.new(
26-
indexing_preparer_by_scalar_type_name,
27-
build_type_metas_from(@schema_artifacts.json_schemas_for(version))
28-
)
29-
end
30-
end
31-
32-
# Gets the `RecordPreparer` for the given JSON schema version.
33-
def for_json_schema_version(json_schema_version)
34-
@preparers_by_json_schema_version[json_schema_version] # : RecordPreparer
35-
end
36-
37-
# Gets the `RecordPreparer` for the latest JSON schema version. Intended primarily
38-
# for use in tests for convenience.
39-
def for_latest_json_schema_version
40-
for_json_schema_version(@schema_artifacts.latest_json_schema_version)
41-
end
42-
43-
private
44-
45-
def build_type_metas_from(json_schemas)
46-
json_schemas.fetch("$defs").filter_map do |type, type_def|
47-
next if type == EVENT_ENVELOPE_JSON_SCHEMA_NAME
48-
49-
properties = type_def.fetch("properties") do
50-
{} # : ::Hash[::String, untyped]
51-
end # : ::Hash[::String, untyped]
52-
53-
eg_meta_by_field_name = properties.filter_map do |prop_name, prop|
54-
eg_meta = prop["ElasticGraph"]
55-
[prop_name, eg_meta] if eg_meta
56-
end.to_h
57-
58-
TypeMetadata.new(
59-
name: type,
60-
eg_meta_by_field_name: eg_meta_by_field_name
61-
)
62-
end
63-
end
64-
end
65-
6614
# An alternate `RecordPreparer` implementation that implements the identity function:
6715
# it just echoes back the record it is given.
6816
#

elasticgraph-indexer/sig/elastic_graph/indexer.rbs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,12 @@ module ElasticGraph
1919
@datastore_router: Indexer::_DatastoreRouter?
2020
def datastore_router: () -> Indexer::_DatastoreRouter
2121

22-
@record_preparer_factory: RecordPreparer::Factory?
23-
def record_preparer_factory: () -> RecordPreparer::Factory
24-
2522
@processor: Processor?
2623
def processor: () -> Processor
2724

2825
@operation_factory: Operation::Factory?
2926
def operation_factory: () -> Operation::Factory
3027

31-
@ingestion_adapters: ::Array[IngestionAdapter::adapter]?
3228
def ingestion_adapters: () -> ::Array[IngestionAdapter::adapter]
3329

3430
@monotonic_clock: Support::MonotonicClock?

elasticgraph-indexer/sig/elastic_graph/indexer/ingestion_adapter/json_events.rbs

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)