Skip to content

Bug2020962 sessions#3438

Open
travis79 wants to merge 8 commits intomozilla:mainfrom
travis79:Bug2020962-Sessions
Open

Bug2020962 sessions#3438
travis79 wants to merge 8 commits intomozilla:mainfrom
travis79:Bug2020962-Sessions

Conversation

@travis79
Copy link
Copy Markdown
Member

@travis79 travis79 commented Apr 16, 2026

I attempted to structure the commits here to make this easier to review, so I recommend reviewing it that way rather than as a whole.

@travis79 travis79 force-pushed the Bug2020962-Sessions branch from 7471f21 to 00f8341 Compare April 16, 2026 11:30
Copy link
Copy Markdown
Member

@badboy badboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave this a first somewhat-thorough review and left lots of comments.

High-level I think this is a good approach, some clarifications in the details needed maybe.
I have not yet gone through all the new test; I'd like to do that before I'm out tomorrow.

What's currently missing though is docs, both dev docs about all the new state we're storing (and the state changes! oh is it time for a new diagram?), and user-facing docs.
Fine if they land in followups, but should be there before we get this out to applications.

@@ -83,6 +83,9 @@ pub fn metric_dispatcher_benchmark(c: &mut Criterion) {
ping_schedule: Default::default(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a note to the very first line of the diff for the first commit, because one still can't leave a comment for the whole commit (or the message).

Thanks for splitting it up into individual commits. That's certainly helpful, though unfortunately this commit is not working on its own, introducing use of the SessionMode before it's defined.
I think I can cope with it in review though, just comments might be a bit out of order then.

Comment thread glean-core/benchmark/benches/dispatcher.rs
Comment thread glean-core/src/common_metric_data.rs Outdated
Comment thread glean-core/src/common_metric_data.rs Outdated
Comment thread glean-core/src/internal_metrics.rs Outdated
Comment thread glean-core/src/session/mod.rs
Comment thread glean-core/src/session/mod.rs
Comment thread glean-core/python/tests/test_glean.py Outdated
Comment thread glean-core/src/lib_unit_tests.rs Outdated
Comment thread glean-core/src/lib_unit_tests.rs
@travis79 travis79 force-pushed the Bug2020962-Sessions branch from 73c309a to a62b6a6 Compare May 5, 2026 15:43
travis79 added 6 commits May 5, 2026 10:47
Introduce the `out_of_session` flag on `CommonMetricData` (defaulting to
`true`) so metrics can declare whether they participate in session-level
sampling.  Add session configuration fields (`session_mode`,
`session_sample_rate`, `session_inactivity_timeout_ms`) to
`InternalConfiguration` and the RLB `Configuration` struct, and add
`session_sample_rate` to `RemoteSettingsConfig` for server-side overrides.

Update all existing test, benchmark, and example call sites to supply
the new configuration fields.
Implement the session management engine for Glean:

- New `session` module with `SessionManager`, `SessionMode` (Auto,
  Lifecycle, Manual), `SessionState`, `SessionMetadata`, and
  `EventSessionContext` types, plus persistence helpers for session_id,
  session_seq, event_seq, inactive_since, and session_start_time.

- Core lifecycle integration in `Glean`: session_start/session_end,
  handle_client_active/inactive transitions, inactivity timeout
  evaluation, dirty-flag crash recovery emitting synthetic
  session_end("abnormal"/"abnormal_inactive"), orphaned session cleanup
  on mode-mismatch across builds (session_end("abandoned")), and
  session state restoration across clean restarts in AUTO mode.

- Boundary events: `glean.session_start` and `glean.session_end` defined
  in metrics.yaml and emitted as out-of-session events carrying
  session_id, session_seq, session_start_time, and sampled_in.

- Session sampling gate in `MetricType::should_record()` suppresses
  in-session metrics when the active session is sampled out, applying
  uniformly to all metric types.

- Event-session integration: `EventSessionContext` flows through
  `event_database::record()` so in-session events carry per-event
  session metadata (session_id, session_seq, event_seq,
  session_sample_rate, session_start_time).

- Remote Settings override for session_sample_rate is intentionally
  in-memory only; RS refreshes on every startup so persistence would
  risk making stale values sticky.

- session_start_time uses millisecond-precision RFC 3339 serialization
  for consistency with millisecond event timestamps.
Add session lifecycle methods to the UniFFI interface definition and
wire them through all language bindings:

- UDL: export SessionMode enum, session_start(), session_end(),
  handle_client_active/inactive session hooks, and
  apply_server_knobs_config session_sample_rate support.

- Android/Kotlin: forward handle_client_active/inactive calls through
  the Glean singleton; update test configuration for session fields.

- iOS/Swift: forward handle_client_active/inactive calls; update test
  helpers and assertions for session-aware event payloads.

- Python: forward handle_client_active/inactive calls; update
  _RecordingUploader to accept a list of filter strings (needed because
  session lifecycle now submits additional pings on inactive); update
  test configuration.

- RLB: expose session_start/session_end and configuration fields on the
  public Configuration struct.
Comprehensive test coverage for session management:

- tests/session.rs (30 tests): Auto/Lifecycle/Manual mode basics,
  session_seq persistence and monotonic increase across restarts,
  event_seq increment and reset semantics, event_seq continuity across
  AUTO mode restarts, session metadata on in-session events,
  out-of-session event bypass, sampling gate enforcement, boundary
  event emission, inactivity timeout evaluation, session resumption
  vs. new session on restart, session_start_time persistence,
  sampled-out session resumption, sessions_seen diagnostic counter,
  and mode-mismatch orphaned session cleanup.

- lib_unit_tests.rs (4 tests): dirty-flag crash recovery emitting
  session_end("abnormal") for active crashes and
  session_end("abnormal_inactive") for mid-shutdown crashes, no-op
  when no session is persisted, and session_seq continuity after
  crash recovery.
@travis79 travis79 force-pushed the Bug2020962-Sessions branch from a62b6a6 to 6da3515 Compare May 5, 2026 15:47
This commit includes the refactoring of `out_of_session` to `in_session` to avoid the inversion
@travis79 travis79 force-pushed the Bug2020962-Sessions branch from 6da3515 to 008e380 Compare May 5, 2026 15:50
@travis79
Copy link
Copy Markdown
Member Author

travis79 commented May 5, 2026

Okay, Part 1 commit of addressing change requests should cover just the refactoring to remove the inversion by changing out_of_session to in_session. Moving on to the rest of the comments now.

@badboy
Copy link
Copy Markdown
Member

badboy commented May 6, 2026

Oh can you update the PR title to be a bit more descriptive?

Comment thread glean-core/src/metrics/event.rs Outdated
@travis79 travis79 force-pushed the Bug2020962-Sessions branch from 5f5940f to a9fdbdf Compare May 7, 2026 19:00
@travis79 travis79 marked this pull request as ready for review May 7, 2026 19:10
@travis79 travis79 requested a review from a team as a code owner May 7, 2026 19:10
@travis79 travis79 requested review from badboy and removed request for a team May 7, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants