Expand description
The entity-relationship graph: the physical declared-edge table DDL and the
typed DataFusion plan builders for the read-time derivation behind the
computed semantic_entities / semantic_relationships tables.
In OSS the graph is derived at read time, so the only stored part is the
declared-edge table: edges a user asserts by hand (provenance = 'declared').
The derivation is built as typed [Expr]s over [DataFrame]s (never as SQL
text), so user-controlled identifiers are plain values โ no quoting or SQL
injection surface โ and the plans compose with DataFusionโs optimizer,
including filter pushdown into the source table scans. See
docs/rfcs/2026-06-25-entity-relationships-and-graph-query.md.
Modulesยง
- conventions ๐
- The built-in derivation conventions of the entity graph, embedded as
conventions.yaml: the co-declared edge vocabulary, the virtual-destination candidates, and the implicit declarations of well-known Prometheus entity-descriptor metrics. The file is data shipped with the binary, not an operator-editable configuration surface; explicitgreptime.semantic.entity.*declarations always override it. - relationships ๐
- The
semantic_relationshipsderivation: the plan builders for every edge branch behind the computed table โ trace-derived servicecalls(with virtual-node edges for unmatched clients), agentcallsfrom span structure, same-row co-declared edges, and the declared-edge union. Shared expression helpers and the entity registry live in the parent module.
Structsยง
- Calls
Source - A trace tableโs scan paired with the entity declarations its derivations
key on โ a unit of
build_relationships_plan. Theservicedeclaration feeds service calls, theagentdeclaration agent calls; the two are independent, so a table whose service declaration is unusable still derives agent edges (and vice versa). - CoDeclared
Source - A declaring tableโs scan paired with its entity declarations, from which
the same-row co-declaration rules derive edges.
is_tracegates the agent-edge vocabulary, which the RFC ties to span structure. - Conventions
- The parsed, validated conventions file.
- Declared
Source - The declared-edge tableโs scan (
semantic_relationships_declared), whose rowsbuild_relationships_planunions into the edge set. - Entity
Declaration - A single tableโs entity-identity declaration, projected from
information_schema.table_semantics(greptime.semantic.entity.<type>.*). - Graph
Query Window - The read-time query window, resolved from the scanโs
observed_atpredicate (or the product default). Two half-open[start, end)millisecond ranges: - Implicit
Entity - One implicit entity declaration: of a whitelisted Prometheus or OTel info metric, or of a trace-v1 tableโs flattened resource attributes.
- Registry
Source - A declaring tableโs scan paired with the entity declarations it carries โ
the unit
build_registry_planderives registry rows from. - Relationship
Sources - Everything
build_relationships_planderives edges from.
Constantsยง
- BIN_
NANOS ๐ - Bin width for the temporal window of derived rows, matching the service-graph convention. Shared so ingestion-synthesized observations land in the same buckets.
- DECLARED_
EDGE_ ๐IDENTITY_ COLUMNS - The externally visible edge identity: the primary key minus
scopeandgeneration_id, which the computed table does not expose. Revision ranking uses this identity, or assertions differing only in those two columns would surface as indistinguishable duplicate rows. - DECLARED_
PRIMARY_ KEY_ COLUMNS - The primary-key (tag) columns, in key order. Starting with the source endpoint
makes out-edge lookup (
WHERE src_type=? AND src_id=?) a key-prefix scan;provenanceandgeneration_idare in the key so a declared edge and a (future) derived edge for the same pair coexist without clobbering. - DECLARED_
RELATIONSHIPS_ ๐TTL_ ENV - Environment variable overriding the declared-edge tableโs TTL at creation
time (e.g.
180d,forever). - DEFAULT_
DECLARED_ ๐RELATIONSHIPS_ TTL - Default retention for the declared-edge table; expiry slides the topology window.
- ENTITY_
TYPE_ GEN_ AI_ AGENT - ENTITY_
TYPE_ GEN_ AI_ MODEL - ENTITY_
TYPE_ GEN_ AI_ TOOL - ENTITY_
TYPE_ HOST - ENTITY_
TYPE_ K8S_ CONTAINER - ENTITY_
TYPE_ K8S_ NODE - ENTITY_
TYPE_ K8S_ POD - ENTITY_
TYPE_ K8S_ WORKLOAD - ENTITY_
TYPE_ PROCESS - ENTITY_
TYPE_ SERVICE - The built-in entity-type vocabulary. User-declared types are open-ended; the embedded conventions file must stay inside this set.
- ENTITY_
TYPE_ SERVICE_ INSTANCE - ID_
ESCAPE ๐ - ID_
QUALIFIER_ ๐SEPARATOR - Left unescaped:
<namespace>/<name>is how Prometheus rendersjob. - ID_
SEPARATOR ๐ - PROVENANCE_
AGENT - PROVENANCE_
ATTRIBUTE - PROVENANCE_
DECLARED - PROVENANCE_
TRACE - REGISTRY_
COLUMNS ๐ - REGISTRY_
VALID_ ๐COLUMN - REL_
TYPE_ CALLS - The relationship vocabulary (the RFCโs rel_type table) and the edge provenances.
- REL_
TYPE_ CONTAINS - REL_
TYPE_ DEPENDS_ ON - REL_
TYPE_ INVOKES - REL_
TYPE_ OWNS - REL_
TYPE_ PART_ OF - REL_
TYPE_ RUNS_ ON - REL_
TYPE_ USES
Staticsยง
- JSON_
OBJECT_ ๐UDF - The
json_objectUDF, resolved likePARSE_JSON_UDF. It assembles the JSONB binary directly from the value columns, so runtime values need no JSON text escaping. - PARSE_
JSON_ ๐UDF - The
parse_jsonUDF, shared by all derivation plans. Resolved from the global registry once: the UDF is stateless (itsFunctionContextis unused).
Functionsยง
- bin_
interval ๐ - bin_ms ๐
date_bin(60s, ts)cast to millisecond precision, so the output schema is deterministic regardless of the source columnโs precision (trace tables are nanosecond, metric tables millisecond).- build_
declared_ relationships_ expr - Builds the
CREATE TABLErequest for the declared-edge table. Columns mirror the computedsemantic_relationshipsshape (temporal window + endpoints + provenance/confidence + RED metrics) plus the declared-only business validity window (valid_from/valid_until), which โ unlike TTL (physical retention) โ expresses whether a hand-declared edge is still in effect. - build_
registry_ plan - Builds the
semantic_entitiesregistry plan: one branch and source scan per declaring table, filtered towindow, thenUNION ALLacross source tables. ReturnsNonewhen nothing declared an entity, so the computed table streams empty. - build_
relationships_ plan - Builds the
semantic_relationshipsplan: the service-calls, agent-calls, co-declared, and declared-edge branches unioned and re-projected to the 18-column contract. ReturnsNonewhen no source can contribute edges, so the computed table streams empty. - cast_
string_ ๐or_ empty coalesce(CAST(column AS STRING), ''): renders a nullable column for string concatenation without collapsing the result to NULL.- column ๐
- concat_
expr ๐ - conventions
- The embedded conventions.
Errmeans the embedded file is broken โ pinned by unit test, and propagated by the derivation paths rather than panicking. - declaration_
predicate ๐ - The row-level guard a declaration carries: every identity component present, and the superseding typeโs identity not complete. Every branch that turns a declaration into rows applies this, so the guard cannot drift between them.
- declared_
relationships_ schema_ matches - Whether an existing declared-edge table still matches the canonical
definition (
build_declared_relationships_expr): columns, time index, primary key, engine, and merge behaviour โ the union branchโs revision and dedup semantics lean on all of these. A mismatch (upgrade skew) must be surfaced, not silently derived wrong; DROP resets the table. - declared_
relationships_ ๐ttl - entity_
id_ ๐expr - The identity values in declared order (broad to narrow), escaped and joined.
- escaped_
id_ ๐value - Escapes so a composite id decodes back to its components. The escape character goes first, or it would double the escapes the separator pass introduces.
- field ๐
- identifies ๐
- A row identifies an entity only when every identity component is present
and non-empty: kube-state-metrics descriptors emit empty-string labels (an
unscheduled podโs
node, an owner-less podโsowner_*), and an empty string is never a meaningful entity id. The qualifier is optional by construction and so is not guarded. - interval ๐
- An
INTERVALliteral ofnanosnanoseconds. - json_
field ๐ - json_
object_ ๐expr - Builds a JSONB object with one entry per column: key = the column name,
value = the column rendered as a string, NULL coalesced to
""so one NULL column does not null the entry (descriptive columns are nullable). Keys come out sorted โ JSONB objects are key-ordered regardless of input order. - json_
quote ๐ - Renders a compile-time-known string as JSON text (quoted, fully escaped).
- null_
json ๐ - A NULL literal typed as JSONB storage (
Binary), so branches without a JSON value union-align with branches that produce one. - parse_
json_ ๐expr - Parses a JSON text expression into a JSONB value, cast from the UDFโs
BinaryViewoutput toBinaryโ the storage type the computed tablesโ declaredjsoncolumns map to in Arrow. - qcol ๐
- A column reference qualified by a join-side alias, built without string
parsing (so column names containing
.or"stay verbatim). - qualified_
id_ ๐expr <qualifier>/<value>, or barevaluewhen the qualifier is empty on this row โ the specโs rule composingjobfromservice.namespaceandservice.name.- registry_
source ๐ - Projects all entity declarations of one source table with one source scan
via
unnest_rows. - sorted_
kv_ ๐expr_ with - Renders pre-sorted columns as a
k=v,k=vconcatenation.nullablecoalesces each value to''(id columns are tags and non-null; scope columns carry no such guarantee). - tag ๐
- ts_
ms_ ๐lit - union_
all ๐ - Folds union branches without requiring a non-empty input.
- unnest_
rows ๐ - Expands one source row into one output row per entry of
rowswith a single source scan: each output field is first built as an array whose entries correspond to the rows, then unnested. Every row is[valid, values...]aligned withcolumns; rows whosevalidexpression is false are dropped, and the distinct output columns arecolumns.