factory

package
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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}
  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

View Source
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.

func New

func New(cfg Config, opts Options) (*Built, error)

New builds the store the configuration describes.

func (*Built) Close

func (b *Built) Close() error

Close releases what New opened.

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 Config struct {
	Primary   Engine     `json:"primary"`
	Secondary *Secondary `json:"secondary,omitempty"`
}

func Parse

func Parse(raw []byte) (Config, error)

Parse reads YAML or JSON. An unknown field is an error, so a misspelt setting is found at startup rather than ignored.

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 FieldPrefix struct {
	Primary   string `json:"primary"`
	Secondary string `json:"secondary"`
}

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"`
}

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"`
}

Secondary is a read-only store holding what came before Cutover.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL