Documentation
¶
Overview ¶
Package factory builds a store from configuration, so that every process of an installation — the event processor, the backend, the plugins — reaches its data the same way and the choice of engine is a setting, not code.
The configuration names a primary store and, optionally, a secondary one that is read-only and holds what came before a cutover. With a secondary configured the result is a composite store; without one it is the primary alone.
primary:
engine: clickhouse
clickhouse:
addr: ["clickhouse:9000"]
database: utmstack
tenantColumn: tenantId
tables: {logs: logs, alerts: alerts}
secondary:
engine: opensearch
opensearch:
urls: ["https://opensearch:9200"]
tenantField: tenantId
layout: {logs: {prefix: v11-log, includeDataType: true, dateFormat: "2006.01.02"}}
cutover: "2026-11-01T00:00:00Z"
expires: "2026-12-01T00:00:00Z"
tenant: ce66672c-e36d-4761-a8c8-90058fee1a24
datasets: [logs]
fieldPrefix: {primary: log, secondary: event}
fieldValueMaps: {status: {"Open": "2", "In review": "3", "Completed": "5", "Automatic review": "1"}}
disabled: false
Switching the secondary off is a setting too: secondary.disabled set to true keeps the rest of the section where it is. A process that starts with it set never connects to the secondary and answers from the primary alone. The configuration is read when a process starts, so one that was already running has to be restarted to see it.
Index ¶
Constants ¶
const ( EngineClickHouse = "clickhouse" EngineOpenSearch = "opensearch" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Built ¶
type Built struct {
// Store is the store to use.
Store store.Store
// Composite is Store when a secondary is configured and enabled, and nil
// otherwise. It reports whether the secondary is still reachable.
Composite *composite.Store
// SecondaryDisabled is true when a secondary is configured but switched off.
SecondaryDisabled bool
// ResolveIndexPattern turns the index pattern a v11 rule names into a
// dataType. It is nil when no OpenSearch layout is configured. Install it
// with plugins.SetIndexPatternResolver.
ResolveIndexPattern func(dataset store.Dataset, pattern string) (dataType string, ok bool)
// contains filtered or unexported fields
}
Built is what New makes.
type ClickHouse ¶
type ClickHouse struct {
Addr []string `json:"addr"`
Database string `json:"database"`
Username string `json:"username"`
Password string `json:"password"`
Tables map[string]string `json:"tables"`
TenantColumn string `json:"tenantColumn"`
TimeColumn string `json:"timeColumn,omitempty"`
DataTypeColumn string `json:"dataTypeColumn,omitempty"`
TextColumns map[string]string `json:"textColumns,omitempty"`
IDColumns map[string]string `json:"idColumns,omitempty"`
ColdVolume string `json:"coldVolume,omitempty"`
}
type Config ¶
type DatasetLayout ¶
type DatasetLayout struct {
Prefix string `json:"prefix"`
IncludeDataType bool `json:"includeDataType,omitempty"`
DateFormat string `json:"dateFormat,omitempty"`
}
DatasetLayout is opensearch.DatasetSpec: how a dataset's indices are named.
type Engine ¶
type Engine struct {
Engine string `json:"engine"`
ClickHouse *ClickHouse `json:"clickhouse,omitempty"`
OpenSearch *OpenSearch `json:"opensearch,omitempty"`
}
Engine selects one engine and carries the settings of the one it selects.
type FieldPrefix ¶
type OpenSearch ¶
type OpenSearch struct {
URLs []string `json:"urls"`
Username string `json:"username"`
Password string `json:"password"`
TenantField string `json:"tenantField"`
TimestampField string `json:"timestampField,omitempty"`
RetentionPolicyID string `json:"retentionPolicyId,omitempty"`
Layout map[string]DatasetLayout `json:"layout"`
TextFields map[string]string `json:"textFields,omitempty"`
KeywordFields []string `json:"keywordFields,omitempty"`
}
type Options ¶
type Options struct {
// OnSecondaryError is told about a secondary failure that TolerateFailure hid.
OnSecondaryError func(op string, err error)
// OnReject is told about every row a ClickHouse writer permanently drops.
OnReject func(row []byte, err error)
// Now is the clock, replaceable in tests.
Now func() time.Time
}
Options are what cannot come from a file.
type Secondary ¶
type Secondary struct {
Engine
// Cutover is when the secondary stopped receiving writes (RFC 3339).
Cutover string `json:"cutover"`
// Expires is when the secondary is switched off (RFC 3339); empty means never.
Expires string `json:"expires,omitempty"`
// Disabled switches the secondary off without removing its settings: nothing
// connects to it and the rest of the section is not even checked, since it
// is no longer used. The index pattern resolver still works, because v11
// rules keep naming the indices they were written against.
Disabled bool `json:"disabled,omitempty"`
// Tenant is the one tenant the secondary data belongs to.
Tenant string `json:"tenant"`
// Datasets lists the datasets the secondary serves.
Datasets []string `json:"datasets"`
// TolerateFailure answers from the primary when the secondary fails, instead
// of failing the read.
TolerateFailure bool `json:"tolerateFailure,omitempty"`
// FieldPrefix maps the object that holds parsed fields: the primary's name
// for it and the secondary's ("log" and "event"). It applies to field names in
// queries and to the records that come back.
FieldPrefix *FieldPrefix `json:"fieldPrefix,omitempty"`
// FieldValueMaps swaps a filter's value per field before it reaches the secondary,
// for fields the two stores name the same but keep in different forms. The v11
// alerts index stores status as a numeric code where the primary stores the string,
// so {status: {"Open": "2"}} turns a status=="Open" filter into status=="2" on the
// way to the legacy index. Keys are the secondary's field name. Optional.
FieldValueMaps map[string]map[string]string `json:"fieldValueMaps,omitempty"`
}
Secondary is a read-only store holding what came before Cutover.