functions

package
v1.801.307 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package functions mounts the Hanzo Cloud /v1/functions surface: a per-org serverless function registry. Every function belongs to exactly one org (the gateway-minted X-Org-Id, HIP-0026); org isolation is the org column, enforced on every query. The registry stores a function's runtime, source, resource limits, and the NAMES of the secrets it mounts — never a secret value (values live in KMS by reference, the Secret-Manager principle).

Surface (the shape console's FunctionsModule / functions.ts consume):

GET    /v1/functions                    list functions           -> {functions:[...]}
POST   /v1/functions                    create / redeploy        -> ServerlessFunction
GET    /v1/functions/metrics            invocations chart + donut -> {series,status,costCents}
GET    /v1/functions/triggers           all triggers (HTTP)      -> {triggers:[...]}
GET    /v1/functions/deployments        current deployments      -> {functions:[...]}
GET    /v1/functions/secrets            mounted secret NAMES      -> {secrets:[...]}
GET    /v1/functions/:name              detail + triggers + calls -> FunctionDetail
DELETE /v1/functions/:name              delete (+ its invocations)
GET    /v1/functions/:name/invocations  recent invocations       -> {invocations:[...]}
GET    /v1/functions/:name/logs         last invocation output   -> {logs:"..."}
POST   /v1/functions/:name/invoke       run the function {input} -> Invocation

Invoke delegates to the sandboxed code executor (CODE_EXEC_UPSTREAM) — this binary NEVER runs org code in-process. When the sandbox is not configured invoke fails closed (503) and fabricates nothing. Every metric the Overview shows is DERIVED from real invocation rows; there is no invented rollup.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Mount

func Mount(app cloud.Router, deps cloud.Deps) error

Mount wires the functions surface onto app per HIP-0106. Complex flavour: it holds a package-global (mounted) so Shutdown can close every per-org store, so it constructs the Service value directly rather than via cloud.Mount.

func Shutdown

func Shutdown() error

Shutdown closes every open per-org functions store. Idempotent.

Types

type Function

type Function struct {
	ID           string
	Org          string
	Name         string
	Namespace    string
	Runtime      string
	Image        string
	Code         string
	Handler      string
	Target       string // "" = sandbox (default) | "fleet" = org GPU fleet (fn.run)
	TimeoutSec   int
	MemoryLimit  string
	EnvNames     []string
	Status       string
	DeployVer    int
	CreatedAt    int64
	LastDeployAt int64
}

Function is the org-scoped definition of a serverless function: a runtime (environment) + source code + resource limits + the NAMES of the secrets it mounts (values live in KMS, never here). Org isolation is the org column.

type InvStats

type InvStats struct {
	Count       int
	Errors      int
	SumDuration int64
}

InvStats is a real per-function rollup over a time window (since unix).

type Invocation

type Invocation struct {
	ID           string
	Org          string
	FunctionName string
	Status       string // ok | error | timeout
	StatusCode   int
	Method       string
	DurationMs   int64
	Output       string
	Error        string
	CreatedAt    int64
}

Invocation is one execution of a function: real history, one row per call.

type Store

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

Store is one org's functions database — ONE SQLite file per org at {DataDir}/orgs/{orgSlug}/functions.db (opened via cloud.OrgDB). functions is org-scoped (it carries no project axis); org-scoping is PHYSICAL, with the org column retained as defense-in-depth.

func (*Store) Close

func (s *Store) Close() error

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, org, name string) (bool, error)

Delete removes a function and its invocation history. Reports whether a row went.

func (*Store) Get

func (s *Store) Get(ctx context.Context, org, name string) (Function, error)

Get returns the function for (org,name) or errNotFound.

func (*Store) InsertInvocation

func (s *Store) InsertInvocation(ctx context.Context, iv Invocation) error

InsertInvocation records one function execution.

func (*Store) InvocationsSince

func (s *Store) InvocationsSince(ctx context.Context, org string, since int64, limit int) ([]Invocation, error)

InvocationsSince returns raw invocation rows for an org since a unix time (newest first, capped) — the real basis for the metrics chart. One query across all the org's functions; bucketing happens in memory.

func (*Store) List

func (s *Store) List(ctx context.Context, org string) ([]Function, error)

List returns every function for org, most-recently-deployed first.

func (*Store) ListInvocations

func (s *Store) ListInvocations(ctx context.Context, org, fn string, limit int) ([]Invocation, error)

ListInvocations returns invocation history for (org,function), newest first.

func (*Store) StatsSince

func (s *Store) StatsSince(ctx context.Context, org, fn string, since int64) (InvStats, error)

StatsSince returns invocation aggregates for (org,function) since a unix time — the REAL basis for invocations7d / successRate / avgDurationMs. Never a fabricated rollup.

func (*Store) Upsert

func (s *Store) Upsert(ctx context.Context, f Function) (Function, error)

Upsert creates a function at deploy version 1 or, when (org,name) already exists, redeploys it (advances deploy_version, updates the spec). One transaction so the record never drifts. Returns the post-write function.

Jump to

Keyboard shortcuts

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