ingest

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 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 ingest owns the AI-agent telemetry upload path: the stricter enterprise-config gate (this file) and the HTTP client that POSTs events to /v1/{customer_id}/ai-agents/events.

The stricter gate exists because DMG's `config.IsEnterpriseMode()` checks only APIKey — that's the right call for the scan/telemetry paths, but it's too lax for the hook upload path. A missing CustomerID or APIEndpoint here would silently misroute uploads, so we require all three credentials to be present and not bearing build-time `{{...}}` placeholders.

Index

Constants

View Source
const DefaultHookUploadTimeout = 5 * time.Second

DefaultHookUploadTimeout caps how long the hot path will wait on the backend per hook invocation. Each hook is a fresh process, so every upload pays a cold TCP+TLS handshake; tighter caps proved fragile under load. Past this, the right answer is an async sidecar approach, not a bigger sync timeout.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client posts events to a single configured endpoint. Safe to share across goroutines; the underlying *http.Client carries connection state.

func New

func New(cfg Config, h *http.Client) (*Client, bool)

New returns a client when the supplied Config has all enterprise credentials present and non-placeholder. The bool is false when no upload should be attempted; callers MUST treat that as a no-op rather than an error. The gate matches Snapshot's: trims surrounding whitespace, then rejects empty values and `{{...}}` placeholders. New owns the gate so a caller passing a hand-built Config (not the product of Snapshot) cannot bypass it.

func (*Client) UploadEvents

func (c *Client) UploadEvents(ctx context.Context, customerID string, events []event.Event) error

UploadEvents POSTs events to /v1/{customer_id}/ai-agents/events as a raw JSON array. Each event already carries its own schema_version, identity, and policy fields, so no envelope wraps the array — the backend reads the indexed columns directly from each event.

Statuses 200, 201, 202, and 409 are treated as success. 409 is success because backend ingestion is idempotent on (device_id, event_id); duplicate retries must not become client errors.

type Config

type Config struct {
	CustomerID  string
	APIEndpoint string
	APIKey      string
}

Config is a snapshot of the three credentials required to upload AI-agent events. All fields are TrimSpace'd at read time.

func Snapshot

func Snapshot() (Config, bool)

Snapshot reads the current process-wide DMG config (populated by an earlier call to config.Load) and returns it alongside an "enterprise ready" bool. The bool is true iff every field is non-empty after trimming AND none contain the build-time placeholder marker `{{`.

Env-var overrides (DMG_CUSTOMER_ID, DMG_API_ENDPOINT, DMG_API_KEY) take precedence over the config file when set and non-empty. They exist for local dev where an MDM agent may revert the on-disk file.

The returned Config is always populated for diagnostics — callers should NOT use its values when ok is false.

Jump to

Keyboard shortcuts

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