arc

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoArcInstance = errors.New("no arc instance configured for org")

ErrNoArcInstance is returned by Registry.Get when the requested org has no configured Arc instance. Surface as HTTP 503 at the request edge.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps the Arc HTTP API for writing and querying memories

func NewClient

func NewClient(baseURL, apiKey, database, measurement string, batchSize int, flushIntervalMS int, connectTimeout int, queryTimeout int, logger zerolog.Logger) *Client

NewClient creates a new Arc HTTP client

func (*Client) BufferWrite

func (c *Client) BufferWrite(record map[string]interface{}) error

BufferWrite adds a record to the write buffer. Flushes when batch size is reached. If the buffer exceeds maxBufferSize, the oldest records are dropped.

func (*Client) Close

func (c *Client) Close() error

Close stops the background flush and health check, then flushes remaining records. Safe to call multiple times.

func (*Client) Flush

func (c *Client) Flush(ctx context.Context) error

Flush writes all buffered records to Arc using columnar msgpack format. On failure, records are re-buffered so they can be retried on the next cycle. Serialized via flushMu to prevent concurrent flush races.

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns the last known connection state from the background health check.

func (*Client) MarkConnected

func (c *Client) MarkConnected()

MarkConnected sets the connection state to true. Called after a successful startup Ping.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping checks connectivity to Arc

func (*Client) Query

func (c *Client) Query(ctx context.Context, sql string) ([]map[string]interface{}, error)

Query executes a SQL query against Arc and returns the results as maps keyed by column name.

type Defaults

type Defaults struct {
	ConnectTimeout       int
	QueryTimeout         int
	WriteBatchSize       int
	WriteFlushIntervalMS int
}

Defaults are the timing/batch knobs shared by every Arc client. Per-org values (URL, API key, database, measurement) live in the metadata DB.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry resolves *Client instances by org_id. Built once at startup; per-org adds/removes go through Reload to keep the cache coherent.

func NewRegistry

func NewRegistry(ctx context.Context, store *metadata.ArcInstanceStore, defaults Defaults, logger zerolog.Logger) (*Registry, error)

NewRegistry eagerly builds clients for every row in arc_instances. Returns a non-nil registry even when the table is empty (Get will then return ErrNoArcInstance for every org until Reload is called).

func (*Registry) Close

func (r *Registry) Close() error

Close closes every cached client.

func (*Registry) Get

func (r *Registry) Get(orgID string) (*Client, error)

Get returns the *Client for an org, or ErrNoArcInstance if none is configured.

func (*Registry) Health

func (r *Registry) Health() map[string]bool

Health returns the per-org health snapshot from each client's background health check.

func (*Registry) Orgs

func (r *Registry) Orgs() []string

Orgs returns the org IDs with configured Arc instances.

func (*Registry) Reload

func (r *Registry) Reload(ctx context.Context, orgID string) error

Reload re-reads the row for orgID from the store and replaces the cached client. Pass an empty orgID to reload every instance. Closes the previous client(s) after the swap so in-flight requests on the old client finish.

func (*Registry) Remove

func (r *Registry) Remove(orgID string) error

Remove evicts and closes the client for orgID. Used when an org's arc instance is deleted via the admin CLI.

Jump to

Keyboard shortcuts

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