|
| 1 | +// Copyright Quesma, licensed under the Elastic License 2.0. |
| 2 | +// SPDX-License-Identifier: Elastic-2.0 |
| 3 | +package frontend_connectors |
| 4 | + |
| 5 | +import ( |
| 6 | + "fmt" |
| 7 | + "strings" |
| 8 | +) |
| 9 | + |
| 10 | +type Decision struct { |
| 11 | + // input |
| 12 | + IndexPattern string "json:\"index_pattern\"" |
| 13 | + |
| 14 | + // obvious fields |
| 15 | + IsClosed bool "json:\"is_closed\"" |
| 16 | + Err error "json:\"error\"" |
| 17 | + IsEmpty bool "json:\"is_empty\"" |
| 18 | + |
| 19 | + EnableABTesting bool "json:\"enable_ab_testing\"" |
| 20 | + |
| 21 | + // which connector to use, and how |
| 22 | + UseConnectors []ConnectorDecision "json:\"use_connectors\"" |
| 23 | + |
| 24 | + // who made the decision and why |
| 25 | + Reason string "json:\"reason\"" |
| 26 | + ResolverName string "json:\"resolver_name\"" |
| 27 | +} |
| 28 | + |
| 29 | +func (d *Decision) String() string { |
| 30 | + |
| 31 | + var lines []string |
| 32 | + |
| 33 | + if d.IsClosed { |
| 34 | + lines = append(lines, "Returns a closed index message.") |
| 35 | + } |
| 36 | + |
| 37 | + if d.IsEmpty { |
| 38 | + lines = append(lines, "Returns an empty result.") |
| 39 | + } |
| 40 | + |
| 41 | + if d.Err != nil { |
| 42 | + lines = append(lines, fmt.Sprintf("Returns error: '%v'.", d.Err)) |
| 43 | + } |
| 44 | + |
| 45 | + for _, connector := range d.UseConnectors { |
| 46 | + lines = append(lines, connector.Message()) |
| 47 | + } |
| 48 | + |
| 49 | + if d.EnableABTesting { |
| 50 | + lines = append(lines, "Enable AB testing.") |
| 51 | + } |
| 52 | + |
| 53 | + lines = append(lines, fmt.Sprintf("%s (%s).", d.Reason, d.ResolverName)) |
| 54 | + |
| 55 | + return strings.Join(lines, " ") |
| 56 | +} |
| 57 | + |
| 58 | +type ConnectorDecision interface { |
| 59 | + Message() string |
| 60 | +} |
| 61 | + |
| 62 | +type ConnectorDecisionElastic struct { |
| 63 | + // TODO instance of elastic connector |
| 64 | + ManagementCall bool "json:\"management_call\"" |
| 65 | +} |
| 66 | + |
| 67 | +func (d *ConnectorDecisionElastic) Message() string { |
| 68 | + var lines []string |
| 69 | + lines = append(lines, "Pass to Elasticsearch.") |
| 70 | + if d.ManagementCall { |
| 71 | + lines = append(lines, "Management call.") |
| 72 | + } |
| 73 | + return strings.Join(lines, " ") |
| 74 | +} |
| 75 | + |
| 76 | +type ConnectorDecisionClickhouse struct { |
| 77 | + // TODO instance of clickhouse connector |
| 78 | + |
| 79 | + ClickhouseTableName string "json:\"clickhouse_table_name\"" |
| 80 | + ClickhouseTables []string "json:\"clickhouse_tables\"" |
| 81 | + IsCommonTable bool "json:\"is_common_table\"" |
| 82 | +} |
| 83 | + |
| 84 | +func (d *ConnectorDecisionClickhouse) Message() string { |
| 85 | + var lines []string |
| 86 | + |
| 87 | + lines = append(lines, "Pass to clickhouse.") |
| 88 | + if len(d.ClickhouseTableName) > 0 { |
| 89 | + lines = append(lines, fmt.Sprintf("Table: '%s' .", d.ClickhouseTableName)) |
| 90 | + } |
| 91 | + if d.IsCommonTable { |
| 92 | + lines = append(lines, "Common table.") |
| 93 | + } |
| 94 | + if len(d.ClickhouseTables) > 0 { |
| 95 | + lines = append(lines, fmt.Sprintf("Indexes: %v.", d.ClickhouseTables)) |
| 96 | + } |
| 97 | + |
| 98 | + return strings.Join(lines, " ") |
| 99 | +} |
| 100 | + |
| 101 | +// PatternDecisions is a struct that holds the pattern and the decisions made for that pattern |
| 102 | +type PatternDecisions struct { |
| 103 | + Pattern string |
| 104 | + Decisions map[string]*Decision |
| 105 | +} |
| 106 | + |
| 107 | +// TODO hardcoded pipeline names |
| 108 | +const ( |
| 109 | + QueryPipeline = "Query" |
| 110 | + IngestPipeline = "Ingest" |
| 111 | +) |
0 commit comments