Skip to content

Preview a calc rule

POST
/calc-rules:preview
curl --request POST \
--url https://example.com/api/v1/calc-rules:preview \
--header 'Content-Type: application/json' \
--data '{ "inputs": [ { "alias": "example", "key": "example" } ], "name": "example", "output_key": "example", "owner_kind": "component", "reduce": { "expr": "example" }, "selector": { "component_types": [ "example" ], "components": [ "example" ], "system_types": [ "example" ], "systems": [ "example" ] } }'

Computes a candidate calc rule now, on each owner it selects that the caller may read, with the reduce the tick runs, and writes nothing (a read-only transaction). For each owner it answers the value the rule would write, the output’s current value and whether they differ, the inputs with no value, the members skipped and the instances left out as stale (named when the caller may read the component, else counted). An expression that reads one member’s value by position (members[1].value.t, or an element of an input’s list) over a system with a member the caller may not read is withheld on that system, its error counting the members out of scope; one that folds each input’s list whole (avg(t), max(t)) shows the aggregate. A component rule previews the selected components holding one of its inputs, as the tick would mark them. The owners holding a current value of the output are computed first, so the cap never hides one, and the answer lists the owners holding a value or that the rule would write one on first, each by name. At most owner_cap owners are computed, and a bound on total input reads stops a preview over large systems early, a whole owner at a time (owners_judged of owners_total, truncated past either). The candidate is checked as a save would check it: a reduce that does not compile, a cycle in the key graph, an output another enabled rule or a collection writes, or health are each a 422, so the author learns before saving; given a saved rule’s name it is judged as an edit of that rule. The selector’s names resolve in the caller’s read scope: a name that does not exist and one the caller may not read are the same 422, and a name shared in and out of scope means the one in scope. A preview takes no lock a save waits on. Gated by rule:read.

Media type application/json
object
$schema

A URL to the JSON Schema for this object.

string format: uri
inputs
required

The keys the rule reads, each by a unique alias its reduce uses

Array<object> | null
>= 1 items <= 16 items
object
alias
required

The name the reduce’s expression binds the input by: an identifier of at most 64, not a keyword, a builtin or list function’s name, or one of the calc site’s own bindings (component, has, members, system, value); unique in the rule

string
>= 1 characters <= 64 characters /^[A-Za-z_][A-Za-z0-9_]*$/
key
required

The property or metric the input reads, by name or uuid; the rule holds it by uuid, so a rename changes nothing

string
>= 1 characters
name

A saved rule’s name, to preview an edit of it (its stored version is then not a second writer of its key); absent for a new rule

string
output_key
required

The property or metric the rule would write

string
>= 1 characters
owner_kind
required

What the rule derives a value on

string
Allowed values: component system
reduce
required

An expression over the inputs by alias

object
expr
required

An expression over the inputs by alias, each bound as the list of its current values (one per instance on a component, every member’s on a system), yielding the output key’s type: max(tcp), avg(temp), any(call) || max(people) > 0

string
>= 1 characters
selector

The owners the rule derives for; absent is every owner of its kind

object
component_types

A component rule: derive on components whose type falls within one of these component types

Array<string> | null
components

A component rule: derive on these components (by name or id on write; ids on read)

Array<string> | null
system_types

A system rule: derive on systems whose type falls within one of these system types (subtypes included)

Array<string> | null
systems

A system rule: derive on these systems (by name or id on write; ids on read)

Array<string> | null

OK

Media type application/json
object
$schema

A URL to the JSON Schema for this object.

string format: uri
owner_cap
required

The most owners one preview computes

integer format: int64
owners
required

What the rule would do on each owner it selects that the caller may read, by owner id

Array<object> | null
object
current

The output key’s current value on the owner; absent when it has none

differs
required

Whether the value differs from the current one, so the rule would write a sample

boolean
error

Why the rule could not compute on the owner

string
missing
required

The input keys no value was found for

Array<string> | null
no_members
required

A system with no role-bound members: the rule would write nothing

boolean
owner
required

The owner, by name

string
owner_id
required

The owner’s uuid

string
owner_kind
required

What the owner is

string
Allowed values: component system
skipped
required

A system rule’s members that held no value of an input, those the caller may read

Array<object> | null
object
component
required

The member component, by name

string
component_id
required

The member component’s uuid

string
key
required

The input key the member held no value of

string
skipped_hidden
required

How many more skipped members the caller may not read

integer format: int64
stale
required

The instances an input’s list would leave out as stale, on components the caller may read

Array<object> | null
object
component
required

The component the instance is on, by name

string
component_id
required

The component’s uuid

string
instance
required

The instance left out as stale

string
key
required

The input key

string
stale_hidden
required

How many more stale instances the caller may not read

integer format: int64
value

The value the rule would write now; absent when it would write nothing

owners_judged
required

How many owners were computed

integer format: int64
owners_total
required

How many owners the rule selects that the caller may read

integer format: int64
truncated
required

The cap stopped the preview short of every owner

boolean
Example
{
"$schema": "/api/v1/schemas/CalcPreviewOutputBody.json",
"owners": [
{
"owner_kind": "component"
}
]
}

Error

Media type application/problem+json
object
$schema

A URL to the JSON Schema for this object.

string format: uri
detail

A human-readable explanation specific to this occurrence of the problem.

string
errors

Optional list of individual error details

Array<object> | null
object
location

Where the error occurred, e.g. ‘body.items[3].tags’ or ‘path.thing-id’

string
message

Error message text

string
value

The value at the given location

instance

A URI reference that identifies the specific occurrence of the problem.

string format: uri
status

HTTP status code

integer format: int64
title

A short, human-readable summary of the problem type. This value should not change between occurrences of the error.

string
type

A URI reference to human-readable documentation for the error.

string format: uri
default: about:blank
Example
{
"$schema": "/api/v1/schemas/ErrorModel.json",
"detail": "Property foo is required but is missing.",
"instance": "https://example.com/error-log/abc123",
"status": 400,
"title": "Bad Request",
"type": "about:blank"
}