This is an automated email from the ASF dual-hosted git repository.
lahirujayathilake pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
The following commit(s) were added to refs/heads/master by this push:
new 54bc3e827 Event graph edges from connectors only (#682)
54bc3e827 is described below
commit 54bc3e8278c318703d66a877a4d9bf5fef602392
Author: Yasith Jayawardana <[email protected]>
AuthorDate: Thu Nov 5 15:48:32 2026 -0500
Event graph edges from connectors only (#682)
---
internal/server/eventgraph/README.md | 12 ++
tools/eventgraph/analyse.go | 2 -
tools/eventgraph/graph.go | 37 +---
tools/eventgraph/graph_test.go | 54 ++++++
tools/eventgraph/transitions.go | 189 ---------------------
.../features/core/events/__tests__/graph.test.ts | 8 +-
.../core/events/components/EventGraphCanvas.tsx | 5 +-
.../core/events/components/EventGraphDetails.tsx | 6 +-
.../core/events/components/EventGraphPage.tsx | 3 +-
web/src/features/core/events/graph.ts | 10 +-
web/src/features/core/events/schemas.ts | 3 +-
11 files changed, 86 insertions(+), 243 deletions(-)
diff --git a/internal/server/eventgraph/README.md
b/internal/server/eventgraph/README.md
index 7fb48ba59..fc063ae69 100644
--- a/internal/server/eventgraph/README.md
+++ b/internal/server/eventgraph/README.md
@@ -23,6 +23,18 @@ under the License.
It lists every bus event, the transitions between them and the connector
handlers that end a flow.
The server embeds this directory and serves the graph at `GET /events/graph`.
+## Rules
+
+| Element | Meaning |
+|---|---|
+| Entry | A route, timer or connector loop publishes the event. |
+| Edge | A connector handler on `from` calls a core mark that publishes `to`. |
+| Term | A connector handler on `from` publishes nothing. |
+
+Events one write publishes together are siblings; no edge links them.
+An event no connector subscribes to is a leaf; no edge leaves it.
+Each edge is a step a disabled connector skips, a down connector delays and a
late connector catches up on.
+
## Generating
`graph.json` is gitignored. Generate it before building:
diff --git a/tools/eventgraph/analyse.go b/tools/eventgraph/analyse.go
index 3a653f507..1db8221ac 100644
--- a/tools/eventgraph/analyse.go
+++ b/tools/eventgraph/analyse.go
@@ -112,7 +112,6 @@ type state struct {
sinks map[*ssa.Function]*Sink
unresolved []map[string]any
loadErrs []string
- trans []Transition
}
func analyse() *state {
@@ -193,7 +192,6 @@ func analyse() *state {
st.emits = append(st.emits, best[t])
}
}
- st.trans = st.coreTransitions()
return st
}
diff --git a/tools/eventgraph/graph.go b/tools/eventgraph/graph.go
index bdd46616b..54780a173 100644
--- a/tools/eventgraph/graph.go
+++ b/tools/eventgraph/graph.go
@@ -20,7 +20,9 @@ package main
// graph shapes the JSON that GET /events/graph serves.
// Each Event is a bus topic. Its Entry list names what publishes it first:
// API, timer, startup or a connector type. Subs counts connector subscribers.
-// An Edge links two events. A Term ends a flow.
+// An Edge runs from an event to what a connector handler on it publishes.
+// Events one write publishes together are siblings, never linked; an event no
connector takes is a leaf.
+// A Term ends a flow.
import (
"cmp"
@@ -42,9 +44,7 @@ type Event struct {
Subs int `json:"subs"`
}
-// Edge is a transition from one event to the next.
-// Kind core: a core function publishes To after From.
-// Kind conn: a connector handler on From publishes To directly, not through
another of its topics.
+// Edge is a connector handler on From whose call into core publishes To.
type Edge struct {
From string `json:"from"`
To string `json:"to"`
@@ -54,8 +54,6 @@ type Edge struct {
Sites []string `json:"sites"`
Chain []string `json:"chain"`
Cond bool `json:"cond"`
- // Order marks a core pair published in a helper and then its caller:
sequence, not cause.
- Order bool `json:"order,omitempty"`
}
// Term is a connector handler on From that publishes no event.
@@ -142,7 +140,7 @@ func (st *state) graph() Graph {
node(e.To)
k := [3]string{e.From, e.To, e.Actor}
if o := edges[k]; o != nil {
- o.Cond, o.Order = o.Cond && e.Cond, o.Order && e.Order
+ o.Cond = o.Cond && e.Cond
for _, s := range e.Sites {
o.Sites = appendU(o.Sites, s)
}
@@ -156,30 +154,13 @@ func (st *state) graph() Graph {
node(o.topic)
pubSite[[2]string{o.chain[0], o.topic}] = o.pubPos
}
- trans := map[[2]string]bool{}
- for _, x := range st.trans {
- if x.From == x.To {
- continue
- }
- trans[[2]string{x.From, x.To}] = true
- edge(&Edge{From: x.From, To: x.To, Kind: "core", Conn: "core",
Actor: actor(x.Func), Sites: []string{x.SiteFrom + " → " + x.SiteTo},
- Chain: shorts(x.Chain), Cond: x.Conditional, Order:
actor(x.Chain[0]) != actor(x.Func)})
- }
-
- // An entry starts the topics its root publishes that no transition
from another of them explains.
for _, r := range st.roots {
if r.kind == "handler" {
continue
}
- var ts []string
for _, e := range st.emits {
if e.Handler == fname(r.fn) && e.RootKind == r.kind {
- ts = append(ts, e.Topic)
- }
- }
- for _, t := range ts {
- if !slices.ContainsFunc(ts, func(a string) bool {
return a != t && trans[[2]string{a, t}] }) {
- node(t).Entry = append(node(t).Entry,
Entry{st.entryKind(r), rootLabel(r.key)})
+ node(e.Topic).Entry =
append(node(e.Topic).Entry, Entry{st.entryKind(r), rootLabel(r.key)})
}
}
}
@@ -191,13 +172,9 @@ func (st *state) graph() Graph {
c := st.connName(s.Connector)
name := c + "." + actor(s.Handler)
node(s.Topic).Subs++
- var primary []string
- if s.hfn != nil {
- primary = st.handlerPrimary(st.trans, s.Handler, s.hfn)
- }
emitted := false
for _, e := range st.emits {
- if e.RootKind != "handler" || e.Handler != s.Handler ||
s.hfn != nil && !slices.Contains(primary, e.Topic) {
+ if e.RootKind != "handler" || e.Handler != s.Handler {
continue
}
emitted = true
diff --git a/tools/eventgraph/graph_test.go b/tools/eventgraph/graph_test.go
new file mode 100644
index 000000000..edcfd117e
--- /dev/null
+++ b/tools/eventgraph/graph_test.go
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package main
+
+import (
+ "path/filepath"
+ "testing"
+)
+
+// TestEdgesLeaveConnectorHandlers analyses the repository and checks every
edge
+// starts at a connector handler subscribed to its source event.
+func TestEdgesLeaveConnectorHandlers(t *testing.T) {
+ repoRoot, _ = filepath.Abs("../..")
+ st := analyse()
+ handlers := map[[2]string]bool{}
+ for _, s := range st.subs {
+ if s.Connector != "core" {
+ handlers[[2]string{s.Topic, st.connName(s.Connector) +
"." + actor(s.Handler)}] = true
+ }
+ }
+ g := st.graph()
+ subs := map[string]int{}
+ for _, e := range g.Events {
+ subs[e.ID] = e.Subs
+ }
+ if len(g.Edges) == 0 {
+ t.Fatal("no edges")
+ }
+ for _, e := range g.Edges {
+ switch {
+ case e.Kind != "conn":
+ t.Errorf("%s → %s: kind %q, want conn", e.From, e.To,
e.Kind)
+ case subs[e.From] == 0:
+ t.Errorf("%s → %s: edge out of a leaf", e.From, e.To)
+ case !handlers[[2]string{e.From, e.Actor}]:
+ t.Errorf("%s → %s: %s does not handle %s", e.From,
e.To, e.Actor, e.From)
+ }
+ }
+}
diff --git a/tools/eventgraph/transitions.go b/tools/eventgraph/transitions.go
deleted file mode 100644
index 90845b222..000000000
--- a/tools/eventgraph/transitions.go
+++ /dev/null
@@ -1,189 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-package main
-
-import (
- "sort"
-
- "golang.org/x/tools/go/ssa"
-)
-
-// Transition is To published after From on one core code path.
-type Transition struct {
- From string
- To string
- SiteFrom string
- SiteTo string
- Func string
- Chain []string
- Conditional bool
- fromFn *ssa.Function
-}
-
-// laterInstrs returns the instructions CFG-reachable after s in its function.
-func laterInstrs(s ssa.Instruction) []ssa.Instruction {
- b := s.Block()
- var out []ssa.Instruction
- after := false
- for _, in := range b.Instrs {
- if after {
- out = append(out, in)
- }
- if in == s {
- after = true
- }
- }
- seen := map[*ssa.BasicBlock]bool{}
- stack := append([]*ssa.BasicBlock{}, b.Succs...)
- for len(stack) > 0 {
- x := stack[len(stack)-1]
- stack = stack[:len(stack)-1]
- if seen[x] {
- continue
- }
- seen[x] = true
- out = append(out, x.Instrs...)
- stack = append(stack, x.Succs...)
- }
- return out
-}
-
-var baseReach = map[*ssa.Function]map[*ssa.Function]pathEl{}
-
-// coreTransitions climbs from each core publish through its callers.
-// In each caller it records the publishes reachable after the call.
-func (st *state) coreTransitions() []Transition {
- type key struct{ from, to, sf, stt string }
- best := map[key]Transition{}
- put := func(t Transition) {
- k := key{t.From, t.To, t.SiteFrom, t.SiteTo}
- if old, ok := best[k]; ok && len(old.Chain) <= len(t.Chain) {
- return
- }
- best[k] = t
- }
- // byEntry keys each origin by the call in its own function that leads
to Publish.
- byEntry := map[ssa.Instruction][]origin{}
- for _, o := range st.origins {
- byEntry[o.sites[0]] = append(byEntry[o.sites[0]], o)
- }
- // callers inverts succs over core code. A callback's caller is the
function that passes it.
- callers := map[*ssa.Function][]step{}
- for _, h := range st.modFns {
- if inConnectors(h) {
- continue
- }
- for _, stp := range succs(h) {
- if !inConnectors(stp.callee) {
- callers[stp.callee] =
append(callers[stp.callee], step{callee: h, site: stp.site, kind: stp.kind})
- }
- }
- }
- // scan records each publish reachable after at in G. prefix is the
chain from a.fn up to G.
- scan := func(a origin, G *ssa.Function, at ssa.Instruction, prefix
[]string) {
- for _, in := range laterInstrs(at) {
- for _, b := range byEntry[in] {
- c := condOf(append([]ssa.Instruction{in},
b.sites[1:]...))
- put(Transition{From: a.topic, To: b.topic,
SiteFrom: a.pubPos, SiteTo: b.pubPos, Func: fname(G),
- Chain: append(append([]string{},
prefix...), b.chain[1:]...), Conditional: c, fromFn: a.fn})
- }
- if _, ok := in.(ssa.CallInstruction); !ok {
- continue
- }
- for _, stp := range succs(G) {
- if stp.site != in || inConnectors(stp.callee) {
- continue
- }
- par := baseReach[stp.callee]
- if par == nil {
- par = bfs(stp.callee, true)
- baseReach[stp.callee] = par
- }
- for _, g := range sortedFns(par) {
- for _, b := range st.originsBy[g] {
- names, sites := pathTo(par,
stp.callee, g)
- chain :=
append(append(append([]string{}, prefix...), names...), b.chain[1:]...)
- c :=
condOf(append(append([]ssa.Instruction{in}, sites...), b.sites...))
- put(Transition{From: a.topic,
To: b.topic, SiteFrom: a.pubPos, SiteTo: b.pubPos, Func: fname(G),
- Chain: chain,
Conditional: c, fromFn: a.fn})
- }
- }
- }
- }
- }
- type up struct {
- G *ssa.Function
- at ssa.Instruction
- prefix []string
- }
- for _, a := range st.origins {
- if inConnectors(a.fn) {
- continue
- }
- seen := map[ssa.Instruction]bool{a.sites[0]: true}
- q := []up{{a.fn, a.sites[0], []string{fname(a.fn)}}}
- for len(q) > 0 {
- u := q[0]
- q = q[1:]
- scan(a, u.G, u.at, u.prefix)
- for _, cl := range callers[u.G] {
- if seen[cl.site] {
- continue
- }
- seen[cl.site] = true
- q = append(q, up{cl.callee, cl.site,
append(append([]string{}, u.prefix...), "^ "+fname(cl.callee))})
- }
- }
- }
- out := make([]Transition, 0, len(best))
- for _, t := range best {
- out = append(out, t)
- }
- sort.Slice(out, func(i, j int) bool {
- a, b := out[i], out[j]
- if a.From != b.From {
- return a.From < b.From
- }
- if a.To != b.To {
- return a.To < b.To
- }
- if a.SiteFrom != b.SiteFrom {
- return a.SiteFrom < b.SiteFrom
- }
- return a.SiteTo < b.SiteTo
- })
- return out
-}
-
-// handlerPrimary lists the topics a handler publishes directly.
-// A topic is indirect when a transition in the handler's reach leads to it
from another of its topics.
-func (st *state) handlerPrimary(trans []Transition, handler string, fn
*ssa.Function) []string {
- emitted := map[string]bool{}
- for _, e := range st.emits {
- if e.RootKind == "handler" && e.Handler == handler {
- emitted[e.Topic] = true
- }
- }
- par := st.reach[fn]
- for _, t := range trans {
- if _, ok := par[t.fromFn]; ok && t.From != t.To &&
emitted[t.From] {
- delete(emitted, t.To)
- }
- }
- return sortedKeys(emitted)
-}
diff --git a/web/src/features/core/events/__tests__/graph.test.ts
b/web/src/features/core/events/__tests__/graph.test.ts
index 8622aff25..557628200 100644
--- a/web/src/features/core/events/__tests__/graph.test.ts
+++ b/web/src/features/core/events/__tests__/graph.test.ts
@@ -50,14 +50,10 @@ const edge = (
const ev = (id: string, subs = 1) => ({ id, entry: [], subs });
describe("selectGraph", () => {
- it("drops order-only arrows and arrows into dead ends", () => {
+ it("drops arrows into dead ends", () => {
const graph: EventGraph = {
events: [ev("a::x"), ev("a::y"), ev("a::dead", 0), ev("a::z")],
- edges: [
- edge("a::x", "a::y", "c.H.f"),
- edge("a::x", "a::dead", "c.H.g"),
- edge("a::y", "a::z", "core.f", { kind: "core", order: true }),
- ],
+ edges: [edge("a::x", "a::y", "c.H.f"), edge("a::x", "a::dead", "c.H.g")],
terms: [],
};
const sel = selectGraph(graph, DEFAULT_GRAPH_OPTIONS);
diff --git a/web/src/features/core/events/components/EventGraphCanvas.tsx
b/web/src/features/core/events/components/EventGraphCanvas.tsx
index dc9bbefff..8d76739d0 100644
--- a/web/src/features/core/events/components/EventGraphCanvas.tsx
+++ b/web/src/features/core/events/components/EventGraphCanvas.tsx
@@ -33,7 +33,6 @@ import {
import type { GraphTerm } from "../types";
export const COLOR = {
- core: "var(--tone-accent-fg)",
conn: "var(--tone-warn-fg)",
entry: "var(--tone-info-fg)",
end: "var(--tone-warn-fg)",
@@ -172,7 +171,7 @@ export function EventGraphCanvas({
>
<defs>
<style>{"@keyframes eg-flow { to { stroke-dashoffset:
var(--eg-period); } }"}</style>
- {(["core", "conn", "entry"] as const).map((k) => (
+ {(["conn", "entry"] as const).map((k) => (
<marker
key={k}
id={`eg-${k}`}
@@ -272,7 +271,7 @@ function EdgeView({
onClick: (e: React.MouseEvent) => void;
}) {
const d = pathOf(edge);
- const cond = (edge.kind === "core" || edge.kind === "conn") &&
edge.transition.cond;
+ const cond = edge.kind === "conn" && edge.transition.cond;
// The line itself flows source to target: its dashes march; a solid arrow
dashes only while flowing.
const [dash, period] =
edge.kind === "entry" ? ["4 3", 7] : cond ? ["2 3", 5] : flowing ? ["9 3",
12] : [undefined, 0];
diff --git a/web/src/features/core/events/components/EventGraphDetails.tsx
b/web/src/features/core/events/components/EventGraphDetails.tsx
index 89edea8fe..bb8c2f27d 100644
--- a/web/src/features/core/events/components/EventGraphDetails.tsx
+++ b/web/src/features/core/events/components/EventGraphDetails.tsx
@@ -153,7 +153,7 @@ function TermDetails({ from, term }: { from: string; term:
GraphTerm }) {
}
function EdgeDetails({ edge }: { edge: LaidEdge | undefined }) {
- if (!edge || (edge.kind !== "core" && edge.kind !== "conn")) return null;
+ if (edge?.kind !== "conn") return null;
const t = edge.transition;
return (
<>
@@ -161,7 +161,7 @@ function EdgeDetails({ edge }: { edge: LaidEdge | undefined
}) {
{t.from} → {t.to}
</h2>
<div className="text-xs text-muted-foreground">
- {t.kind === "core" ? "core transition (automatic)" : `connector
transition · ${t.conn}`}
+ connector transition · {t.conn}
{t.cond ? " · conditional" : ""}
</div>
<Key>Performed by</Key>
@@ -245,7 +245,7 @@ function NodeDetails({
if (node.kind !== "event") return null;
const { event } = node;
const transitions = (edges: LaidEdge[], side: "from" | "to") => {
- const ts = edges.flatMap((e) => (e.kind === "core" || e.kind === "conn" ?
[e.transition] : []));
+ const ts = edges.flatMap((e) => (e.kind === "conn" ? [e.transition] : []));
return ts.length ? (
<ul className="list-disc pl-5">
{ts.map((t) => (
diff --git a/web/src/features/core/events/components/EventGraphPage.tsx
b/web/src/features/core/events/components/EventGraphPage.tsx
index 803371384..b83f8785c 100644
--- a/web/src/features/core/events/components/EventGraphPage.tsx
+++ b/web/src/features/core/events/components/EventGraphPage.tsx
@@ -65,7 +65,6 @@ const SHOW: {
label: string;
swatch: React.ReactNode;
}[] = [
- { key: "core", label: "Core", swatch: <Line color={COLOR.core} /> },
{ key: "connector", label: "Connector", swatch: <Line color={COLOR.conn} />
},
{ key: "ends", label: "End steps", swatch: <span style={{ color: COLOR.end
}}>⊣</span> },
{ key: "entries", label: "Triggers", swatch: <Line color={COLOR.entry}
dashed /> },
@@ -359,7 +358,7 @@ function highlight(layout: Layout, pick: Pick | undefined,
query: string): Lit {
e.from,
e.to,
...(e.kind === "entry" ? e.routes : []),
- ...(e.kind === "core" || e.kind === "conn" ? [e.transition.actor]
: []),
+ ...(e.kind === "conn" ? [e.transition.actor] : []),
].some(hit),
)
.map((e) => e.id),
diff --git a/web/src/features/core/events/graph.ts
b/web/src/features/core/events/graph.ts
index cbf99a1a7..7be55058d 100644
--- a/web/src/features/core/events/graph.ts
+++ b/web/src/features/core/events/graph.ts
@@ -18,7 +18,7 @@
// Event state machine from GET /events/graph, laid out by ELK layered.
// Events are grouped in one block per entity (the part before `::`); each
external trigger
// (API, a connector loop) is one box whose arrows carry the routes that start
an event.
-// Arrows are core transitions (core function) or connector transitions
(Connector.handler);
+// Arrows are connector transitions (Connector.handler);
// an end card lists handlers that take an event and emit nothing.
// A trace keeps only what lies on a path from one node to another, so it lays
out small and legible.
// All text is monospace, so a box is sized from its text length alone.
@@ -27,10 +27,9 @@
import ELK, { type ElkExtendedEdge, type ElkNode } from
"elkjs/lib/elk.bundled.js";
import type { EventGraph, GraphEdge, GraphEvent, GraphTerm } from "./types";
-export type GraphOptions = { core: boolean; connector: boolean; ends: boolean;
entries: boolean };
+export type GraphOptions = { connector: boolean; ends: boolean; entries:
boolean };
export const DEFAULT_GRAPH_OPTIONS: GraphOptions = {
- core: true,
connector: true,
ends: true,
entries: true,
@@ -49,8 +48,7 @@ const endId = (event: string) => `end:${event}`;
export function selectGraph(graph: EventGraph, o: GraphOptions): Selected {
const byId = new Map(graph.events.map((e) => [e.id, e]));
const terms = o.ends ? graph.terms : [];
- // Order-only: A was published in a helper and B later in its caller;
sequence, not cause.
- let edges = graph.edges.filter((e) => (e.kind === "core" ? o.core :
o.connector) && !e.order);
+ let edges = o.connector ? graph.edges : [];
// Drop transitions into events nobody handles and that lead nowhere, until
none remain.
for (let n = -1; n !== edges.length; ) {
n = edges.length;
@@ -164,7 +162,7 @@ export type LaidEdge = {
points: Point[];
label: (Point & { lines: string[]; width: number; height: number }) | null;
} & (
- | { kind: "core" | "conn"; transition: Transition }
+ | { kind: "conn"; transition: Transition }
| { kind: "entry"; routes: string[] }
| { kind: "end" }
);
diff --git a/web/src/features/core/events/schemas.ts
b/web/src/features/core/events/schemas.ts
index 875aa9d38..e0a69f342 100644
--- a/web/src/features/core/events/schemas.ts
+++ b/web/src/features/core/events/schemas.ts
@@ -75,13 +75,12 @@ export const eventGraphSchema = z.object({
z.object({
from: z.string(),
to: z.string(),
- kind: z.enum(["core", "conn"]),
+ kind: z.literal("conn"),
conn: z.string(),
actor: z.string(),
sites: list(z.string()),
chain: list(z.string()),
cond: z.boolean(),
- order: z.boolean().optional(),
}),
),
terms: z.array(