Closed Bug 2077138 Opened 1 month ago Closed 2 days ago

Implement the flow lifecycle and the `glean.flow_end` event

Categories

(Data Platform and Tools :: Glean: SDK, enhancement, P1)

enhancement

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: travis_, Assigned: travis_)

References

(Blocks 5 open bugs)

Details

Attachments

(2 external files)

Open and close flow instances when their boundary events are recorded, and record glean.flow_end when an instance closes. Depends on the tagging bug. Session-end termination, auto_close_timeout, persistence, and the kill switch are separate bugs that build on this one.

Both transitions happen while the triggering event is being recorded. Order within EventMetric::record_sync, after should_record():

  1. If the event is in a flow's starts_on and that flow has no active instance, open one: assign the next flow_seq from the session-wide counter and update in-memory state. Nothing is recorded.
  2. Compute the event's session context and flows entries, including any instance opened in step 1. Compute these once, before step 4 closes anything, so an exit event is tagged with the instance it closes.
  3. Record the event.
  4. If the event is in a flow's ends_on and that flow has an active instance, close it and record glean.flow_end with reason: exit. Recording it after the triggering event gives it the higher session.event_seq.

Rules:

  • An entry event while the flow is already active does nothing. The instance is not replaced, unlike session_start().
  • An exit event while the flow is not active does nothing.
  • No instance opens when no session is active. (The glean.flows_not_started diagnostic is a separate bug.)
  • Because boundary handling comes after should_record(), a suppressed or disabled event does not open or close anything.

State: record_sync has &Glean, so the flow manager needs interior mutability. State is a map of active instances plus the session-wide counter, so use a lock.

glean.flow_end:

  • Defined in glean-core/metrics.yaml and recorded through event_data_store.record() directly, like glean.session_end, but with an in-session context, not OutOfSession. It never has flows entries itself.
  • glean_timestamp from Utc::now().timestamp_millis(). Don't copy the session boundary events, which use the monotonic clock (Bug XXXXXXX).
  • Combine the bool returned by EventDatabase::record for flow_end with the triggering event's result, since flow_end can be the event that crosses the buffered-event threshold.
  • Extras: flow_name, flow_seq, reason, plus terminating_event when reason is exit and session_id when reason is abnormal.

Tests: the worked example in the proposal, including the assertion that settings.opened has no flows entry. Decide here whether a test accessor for live flow state is worth adding, which is one of the open questions on the meta.

Blocks: 2077139
Blocks: 2077141
Blocks: 2077144
Blocks: 2077146
Blocks: 2077147
Blocks: 2077152

(via GitHub webhook, authenticated as shared-secret)

(via GitHub webhook, authenticated as shared-secret)

Assignee: nobody → tlong
Priority: P3 → P1
Status: NEW → ASSIGNED
Status: ASSIGNED → RESOLVED
Closed: 2 days ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: