feat: user session sequence analyzer for API behaviour modelling#4813
Open
gauravakto wants to merge 4 commits intofeature/mini-runtime-releasefrom
Open
feat: user session sequence analyzer for API behaviour modelling#4813gauravakto wants to merge 4 commits intofeature/mini-runtime-releasefrom
gauravakto wants to merge 4 commits intofeature/mini-runtime-releasefrom
Conversation
Introduces a new behaviour_modelling module under mini-runtime that tracks per-user API call sequences within tumbling 10-minute windows and aggregates transition counts for downstream sequence probability modelling.
…equencesFlusher - DataActor: add abstract writeApiSequences(List<ApiSequences>) - DbActor: implement with $inc upsert directly against ApiSequencesDao - ClientActor: implement with batched HTTP POST to /writeApiSequences - ApiSequencesFlusher: WindowFlusher impl that converts WindowSnapshot to ApiSequences and calls dataActor.writeApiSequences() - Main.java: wire ApiSequencesFlusher into SessionAnalyzer initialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
How It Works
Per-record hot path
flowchart TD A[HttpResponseParams arrives] --> B[AktoPolicyNew.generateFromHttpResponseParams\nRaw URL → templatized ApiInfoKey] B --> C{ApiInfoKey known in\napiInfoCatalogMap?} C -- No, unknown API --> X[Skip record] C -- Yes --> D[UserIdentifier.extractUserId\nIP address for now] D --> E{UserSessionState\nexists?} E -- No --> F[Create new state\ndeque = empty\nsessionStart = now] E -- Yes --> G{sessionStart\n< windowStart?} F --> H G -- Yes, stale window --> I[Reset deque\nsessionStart = now] G -- No, same window --> H I --> H[Check deque size\nsequenceLength - 1 = 1] H -- deque has 1 entry --> J[Build TransitionKey\ndeque-0 → current ApiInfoKey\ne.g. GET:/orders → POST:/checkout] H -- deque empty --> K J --> K[WindowAccumulator\nrecordTransition + recordApiCall] K --> L[Push ApiInfoKey onto deque\npop front if size >= sequenceLength-1]2-length sequence example (single user, one 10-min window)
10-minute window flip
sequenceDiagram participant K as Kafka records participant SA as SessionAnalyzer participant CA as CurrentAccumulator (Window N) participant NA as NewAccumulator (Window N+1) participant F as ApiSequencesFlusher K->>SA: process() calls stream in continuously Note over SA,CA: t = 0..10min, all writes go to Window N Note over SA: t = 10min — onWindowEnd() fires SA->>NA: create fresh accumulator SA-->>CA: volatile swap: currentAccumulator = NA Note over K,NA: new process() calls now write to Window N+1 SA->>CA: snapshot(windowStart, windowEnd) SA->>F: CompletableFuture.runAsync → flush(snapshot) Note over F: async — hot path unblocked immediately F->>F: Build ApiSequences list\nfor each TransitionKey:\n paths = [from.toString(), to.toString()]\n transitionCount, prevStateCount, probability F->>DA: DataActor.writeApiSequences(List<ApiSequences>) DA->>DB: MongoDB bulkWrite $inc + $setOnInsert upsert\non (apiCollectionId, paths) Note over SA,NA: t = 10..20min, all writes go to Window N+1Flush payload → MongoDB `api_sequences`
Each flushed transition becomes an upsert keyed on `(apiCollectionId, paths)`:
Module Structure
DataActor layer additions:
Test plan
🤖 Generated with Claude Code