Class: ElasticGraph::Indexer

Inherits:
Object
  • Object
show all
Extended by:
Support::FromYamlFile
Defined in:
lib/elastic_graph/indexer.rb,
lib/elastic_graph/indexer/config.rb,
lib/elastic_graph/indexer/event_id.rb,
lib/elastic_graph/indexer/processor.rb,
lib/elastic_graph/indexer/hash_differ.rb,
lib/elastic_graph/indexer/record_preparer.rb,
lib/elastic_graph/indexer/operation/result.rb,
lib/elastic_graph/indexer/operation/update.rb,
lib/elastic_graph/indexer/operation/upsert.rb,
lib/elastic_graph/indexer/operation/factory.rb,
lib/elastic_graph/indexer/failed_event_error.rb,
lib/elastic_graph/indexer/indexing_failures_error.rb,
lib/elastic_graph/indexer/test_support/converters.rb,
lib/elastic_graph/indexer/indexing_preparers/no_op.rb,
lib/elastic_graph/indexer/datastore_indexing_router.rb,
lib/elastic_graph/indexer/indexing_preparers/integer.rb,
lib/elastic_graph/indexer/indexing_preparers/untyped.rb,
lib/elastic_graph/indexer/operation/count_accumulator.rb

Defined Under Namespace

Modules: IndexingPreparers, Operation, TestSupport Classes: Config, DatastoreIndexingRouter, FailedEventError, HashDiffer, IndexingFailuresError, Processor, RecordPreparer

Constant Summary collapse

EventID =

A unique identifier for an event ingested by the indexer. As a string, takes the form of “[type]:@v”, such as “Widget:123abc@v7”. This format was designed to make it easy to put these ids in a comma-seperated list.

::Data.define(:type, :id, :version) do
  # @implements EventID
  def self.from_event(event)
    new(type: event["type"], id: event["id"], version: event["version"])
  end

  def to_s
    "#{type}:#{id}@v#{version}"
  end
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config:, datastore_core:, datastore_router: nil, monotonic_clock: nil, clock: nil) ⇒ Indexer

Returns a new instance of Indexer.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/elastic_graph/indexer.rb', line 29

def initialize(
  config:,
  datastore_core:,
  datastore_router: nil,
  monotonic_clock: nil,
  clock: nil
)
  @config = config
  @datastore_core = datastore_core
  @logger = datastore_core.logger
  @datastore_router = datastore_router
  @schema_artifacts = @datastore_core.schema_artifacts
  @monotonic_clock = monotonic_clock
  @clock = clock || ::Time
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



18
19
20
# File 'lib/elastic_graph/indexer.rb', line 18

def config
  @config
end

#datastore_coreObject (readonly)

Returns the value of attribute datastore_core.



18
19
20
# File 'lib/elastic_graph/indexer.rb', line 18

def datastore_core
  @datastore_core
end

#loggerObject (readonly)

Returns the value of attribute logger.



18
19
20
# File 'lib/elastic_graph/indexer.rb', line 18

def logger
  @logger
end

#schema_artifactsObject (readonly)

Returns the value of attribute schema_artifacts.



18
19
20
# File 'lib/elastic_graph/indexer.rb', line 18

def schema_artifacts
  @schema_artifacts
end

Class Method Details

.from_parsed_yaml(parsed_yaml, &datastore_client_customization_block) ⇒ Object

A factory method that builds an Indexer instance from the given parsed YAML config. ‘from_yaml_file(file_name, &block)` is also available (via `Support::FromYamlFile`).



22
23
24
25
26
27
# File 'lib/elastic_graph/indexer.rb', line 22

def self.from_parsed_yaml(parsed_yaml, &datastore_client_customization_block)
  new(
    config: Indexer::Config.from_parsed_yaml(parsed_yaml),
    datastore_core: DatastoreCore.from_parsed_yaml(parsed_yaml, for_context: :indexer, &datastore_client_customization_block)
  )
end

Instance Method Details

#datastore_routerObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/elastic_graph/indexer.rb', line 45

def datastore_router
  @datastore_router ||= begin
    require "elastic_graph/indexer/datastore_indexing_router"
    DatastoreIndexingRouter.new(
      datastore_clients_by_name: datastore_core.clients_by_name,
      mappings_by_index_def_name: schema_artifacts.index_mappings_by_index_def_name,
      monotonic_clock: monotonic_clock,
      logger: datastore_core.logger
    )
  end
end

#monotonic_clockObject



91
92
93
94
95
96
# File 'lib/elastic_graph/indexer.rb', line 91

def monotonic_clock
  @monotonic_clock ||= begin
    require "elastic_graph/support/monotonic_clock"
    Support::MonotonicClock.new
  end
end

#operation_factoryObject



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/elastic_graph/indexer.rb', line 77

def operation_factory
  @operation_factory ||= begin
    require "elastic_graph/indexer/operation/factory"
    Operation::Factory.new(
      schema_artifacts: schema_artifacts,
      index_definitions_by_graphql_type: datastore_core.index_definitions_by_graphql_type,
      record_preparer_factory: record_preparer_factory,
      logger: datastore_core.logger,
      skip_derived_indexing_type_updates: config.skip_derived_indexing_type_updates,
      configure_record_validator: nil
    )
  end
end

#processorObject



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/elastic_graph/indexer.rb', line 64

def processor
  @processor ||= begin
    require "elastic_graph/indexer/processor"
    Processor.new(
      datastore_router: datastore_router,
      operation_factory: operation_factory,
      indexing_latency_slo_thresholds_by_timestamp_in_ms: config.latency_slo_thresholds_by_timestamp_in_ms,
      clock: @clock,
      logger: datastore_core.logger
    )
  end
end

#record_preparer_factoryObject



57
58
59
60
61
62
# File 'lib/elastic_graph/indexer.rb', line 57

def record_preparer_factory
  @record_preparer_factory ||= begin
    require "elastic_graph/indexer/record_preparer"
    RecordPreparer::Factory.new(schema_artifacts)
  end
end