|
8 | 8 |
|
9 | 9 | require "elastic_graph/support/config" |
10 | 10 | require "elastic_graph/errors" |
| 11 | +require "elastic_graph/indexer/indexing_event_decoder" |
| 12 | +require "elastic_graph/schema_artifacts/runtime_metadata/extension_loader" |
11 | 13 |
|
12 | 14 | module ElasticGraph |
13 | 15 | class Indexer |
14 | | - class Config < Support::Config.define(:latency_slo_thresholds_by_timestamp_in_ms, :skip_derived_indexing_type_updates) |
| 16 | + class Config < Support::Config.define(:latency_slo_thresholds_by_timestamp_in_ms, :skip_derived_indexing_type_updates, :indexing_event_decoder) |
| 17 | + DEFAULT_INDEXING_EVENT_DECODER = { |
| 18 | + "name" => "ElasticGraph::Indexer::IndexingEventDecoder::JSONLines", |
| 19 | + "require_path" => "elastic_graph/indexer/indexing_event_decoder" |
| 20 | + } |
| 21 | + |
15 | 22 | json_schema at: "indexer", |
16 | 23 | optional: false, |
17 | 24 | description: "Configuration for indexing operations and metrics used by `elasticgraph-indexer`.", |
@@ -42,17 +49,64 @@ class Config < Support::Config.define(:latency_slo_thresholds_by_timestamp_in_ms |
42 | 49 | {}, # : untyped |
43 | 50 | {"WidgetWorkspace" => ["ABC12345678"]} |
44 | 51 | ] |
| 52 | + }, |
| 53 | + indexing_event_decoder: { |
| 54 | + description: "Extension object used to decode raw indexing payloads into ElasticGraph indexing event hashes. The default decoder expects JSON Lines.", |
| 55 | + type: "object", |
| 56 | + properties: { |
| 57 | + name: { |
| 58 | + description: "The name of the indexing event decoder extension class.", |
| 59 | + type: "string", |
| 60 | + minLength: 1, |
| 61 | + examples: ["MyCompany::ElasticGraph::CSVIndexingEventDecoder"] |
| 62 | + }, |
| 63 | + require_path: { |
| 64 | + description: "The path to require to load the indexing event decoder extension.", |
| 65 | + type: "string", |
| 66 | + minLength: 1, |
| 67 | + examples: ["./lib/my_company/elastic_graph/csv_indexing_event_decoder"] |
| 68 | + }, |
| 69 | + config: { |
| 70 | + description: "Configuration for the indexing event decoder. Will be passed into the decoder's `#initialize` method.", |
| 71 | + type: "object", |
| 72 | + default: {}, # : untyped |
| 73 | + examples: [ |
| 74 | + {}, # : untyped |
| 75 | + {"delimiter" => ","} |
| 76 | + ] |
| 77 | + } |
| 78 | + }, |
| 79 | + required: ["name", "require_path"], |
| 80 | + default: DEFAULT_INDEXING_EVENT_DECODER, |
| 81 | + examples: [ |
| 82 | + DEFAULT_INDEXING_EVENT_DECODER, |
| 83 | + { |
| 84 | + "name" => "MyCompany::ElasticGraph::CSVIndexingEventDecoder", |
| 85 | + "require_path" => "./lib/my_company/elastic_graph/csv_indexing_event_decoder", |
| 86 | + "config" => {"delimiter" => ","} |
| 87 | + } |
| 88 | + ] |
45 | 89 | } |
46 | 90 | } |
47 | 91 |
|
48 | 92 | private |
49 | 93 |
|
50 | | - def convert_values(skip_derived_indexing_type_updates:, latency_slo_thresholds_by_timestamp_in_ms:) |
| 94 | + def convert_values(skip_derived_indexing_type_updates:, latency_slo_thresholds_by_timestamp_in_ms:, indexing_event_decoder:) |
51 | 95 | { |
52 | 96 | skip_derived_indexing_type_updates: skip_derived_indexing_type_updates.transform_values(&:to_set), |
53 | | - latency_slo_thresholds_by_timestamp_in_ms: latency_slo_thresholds_by_timestamp_in_ms |
| 97 | + latency_slo_thresholds_by_timestamp_in_ms: latency_slo_thresholds_by_timestamp_in_ms, |
| 98 | + indexing_event_decoder: load_indexing_event_decoder(indexing_event_decoder) |
54 | 99 | } |
55 | 100 | end |
| 101 | + |
| 102 | + def load_indexing_event_decoder(config) |
| 103 | + loader = SchemaArtifacts::RuntimeMetadata::ExtensionLoader.new(IndexingEventDecoder::Interface) |
| 104 | + loader.load( |
| 105 | + config.fetch("name"), |
| 106 | + from: config.fetch("require_path"), |
| 107 | + config: config["config"] || {} |
| 108 | + ) |
| 109 | + end |
56 | 110 | end |
57 | 111 | end |
58 | 112 | end |
0 commit comments