feat: log context api#1687
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds a new ChangesLog Context Window Query Feature
Sequence Diagram(s)sequenceDiagram
participant Client
participant query_context as POST /query/context
participant PermissionProvider
participant StreamSchema
participant get_records_and_fields as Query Executor
Client->>query_context: LogContextRequest (stream, pTimestamp, contextWindow, matchField, cursor?)
query_context->>PermissionProvider: authenticate and authorize stream
PermissionProvider-->>query_context: authorized_tables
query_context->>StreamSchema: validate matchField exists and is string type
StreamSchema-->>query_context: field validated
par anchor count
query_context->>get_records_and_fields: execute anchor duplicate-count SQL
get_records_and_fields-->>query_context: anchor_count
and newer records
query_context->>get_records_and_fields: execute newer rows SQL with cursor
get_records_and_fields-->>query_context: newer_records
and older records
query_context->>get_records_and_fields: execute older rows SQL with cursor
get_records_and_fields-->>query_context: older_records
end
query_context->>query_context: merge records, compute anchor_index, build cursors
query_context-->>Client: LogContextResponse (records, anchor_index, previous/next cursors)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/handlers/http/query_context.rs`:
- Around line 407-418: The `get_filter_string` function in `alerts_utils.rs`
introduces a SQL injection vulnerability by directly interpolating user-provided
`inner_value` parameters into SQL without escaping (e.g., in
`list_condition_expr` where values are inserted into ARRAY expressions). To fix
this, implement proper escaping of all user-provided values before they are
interpolated into SQL strings, or refactor the implementation to use
parameterized queries instead of string concatenation. Ensure that the
`inner_value` parameter in `list_condition_expr` and any other user inputs are
safely escaped before being embedded in SQL expressions, preventing attackers
from breaking out of the ARRAY context with malicious input like `1] OR 1=1;
--`.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 08651597-4aa7-49df-b1b6-2a895de0f613
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (5)
src/handlers/http/mod.rssrc/handlers/http/modal/query_server.rssrc/handlers/http/modal/server.rssrc/handlers/http/query.rssrc/handlers/http/query_context.rs
3ba0904 to
02addf9
Compare
request -
```
{
"stream": "teststream",
"contextWindow": "1m",
"pTimestamp": "2026-06-18T07:39:59.995Z",
"pageSize": 500,
"message": "Application started",
"conditions": {
"operator": "and",
"groups": [
{
"operator": "or",
"conditionConfig": [
{
"column": "level",
"operator": "=",
"value": "warn",
"type": "text"
}
]
}
]
}
}
```
response -
```
{
"scope": "contextWindow",
"contextStartTime": "2026-06-18T07:38:00Z",
"contextEndTime": "2026-06-18T07:40:00Z",
"limit": 500,
"anchorIndex": 10,
"duplicateAnchorCount": 15,
"anchoredDuplicate": "first",
"records": [
{
"app_meta": "okcequedfmkqlgzheaidrcce",
"device_id": 126.0,
"host": "172.162.1.120",
"level": "warn",
"location": "uqwetjbuvjameflh",
"message": "Application is failing",
"meta-containerimage": "ghcr.io/parseablehq/quest",
"meta-containername": "log-generator",
"meta-host": "10.116.0.3",
"meta-namespace": "go-apasdp",
"meta-podlabels": "app=go-app,pod-template-hash=6c87bc9cc9",
"meta-source": "quest-test",
"os": "Windows",
"p_src_ip": "127.0.0.1",
"p_timestamp": "2026-06-18T07:39:59.995",
"p_user_agent": "Grafana k6/1.6.1",
"request_body": "vlywlgkpmciorkiklfruxcfnzaspahyscsazpmnqgquqrtahrzhmtojwvackzcqngscesuadnupwpdsryfrvlifembjotnftzuwx",
"session_id": "pqr",
"source_time": "2026-06-18T07:39:59.991",
"status_code": 500.0,
"user_id": 98513.0,
"uuid": "169fa593-fa27-4625-8576-1faab8b9cc71",
"version": "1.2.0"
}
],
"queries": {
"previous": {
"query": "SELECT * FROM (SELECT * FROM \"teststream\" WHERE ((\"p_timestamp\" >= TIMESTAMP '2026-06-18 07:38:00.000' AND \"p_timestamp\" < TIMESTAMP '2026-06-18 07:40:00.000') AND ((\"level\" = 'warn'))) AND (\"p_timestamp\" > TIMESTAMP '2026-06-18 07:39:59.995' OR (\"p_timestamp\" = TIMESTAMP '2026-06-18 07:39:59.995' AND \"message\" < 'Application is failing')) ORDER BY \"p_timestamp\" ASC, \"message\" DESC LIMIT 500) AS log_context_seek_page ORDER BY \"p_timestamp\" DESC, \"message\" ASC",
"startTime": "2026-06-18T07:38:00Z",
"endTime": "2026-06-18T07:40:00Z",
"sendNull": false
},
"next": {
"query": "SELECT * FROM \"teststream\" WHERE ((\"p_timestamp\" >= TIMESTAMP '2026-06-18 07:38:00.000' AND \"p_timestamp\" < TIMESTAMP '2026-06-18 07:40:00.000') AND ((\"level\" = 'warn'))) AND (\"p_timestamp\" < TIMESTAMP '2026-06-18 07:39:59.662' OR (\"p_timestamp\" = TIMESTAMP '2026-06-18 07:39:59.662' AND \"message\" > 'Logging a request')) ORDER BY \"p_timestamp\" DESC, \"message\" ASC LIMIT 500",
"startTime": "2026-06-18T07:38:00Z",
"endTime": "2026-06-18T07:40:00Z",
"sendNull": false
}
}
}
```
02addf9 to
046a454
Compare
request -
response -
Summary by CodeRabbit
POST /query/context) that returns a time-bounded window of records around an anchor timestamp for a selected dataset.