Skip to content

Commit e821d97

Browse files
coderabbit comments fix
1 parent 86fb873 commit e821d97

3 files changed

Lines changed: 218 additions & 157 deletions

File tree

‎src/handlers/http/query_context.rs‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,26 @@ pub async fn query_context(
138138
let permissions = Users.get_permissions(&creds);
139139

140140
create_streams_for_distributed(vec![context_request.dataset.clone()], &tenant_id).await?;
141-
let authorized_datasets = vec![context_request.dataset.clone()];
142141
user_auth_for_datasets(
143142
&permissions,
144143
std::slice::from_ref(&context_request.dataset),
145144
&tenant_id,
146145
)
147146
.await?;
148147

148+
query_context_for_authorized_dataset(context_request, &tenant_id)
149+
.await
150+
.map(web::Json)
151+
}
152+
153+
/// Fetches log context after the caller has authorized the dataset and made it
154+
/// available on the local query node.
155+
pub(crate) async fn query_context_for_authorized_dataset(
156+
context_request: LogContextRequest,
157+
tenant_id: &Option<String>,
158+
) -> Result<LogContextResponse, QueryError> {
159+
let span = Span::current();
160+
let authorized_datasets = vec![context_request.dataset.clone()];
149161
let page_size = normalize_log_context_page_size(context_request.page_size)?;
150162
span.record("page_size", page_size);
151163
let anchor_timestamp = parse_log_context_timestamp(&context_request.p_timestamp)?;
@@ -164,7 +176,7 @@ pub async fn query_context(
164176
"query context request normalized"
165177
);
166178

167-
let dataset = PARSEABLE.get_stream(&context_request.dataset, &tenant_id)?;
179+
let dataset = PARSEABLE.get_stream(&context_request.dataset, tenant_id)?;
168180
let schema = dataset.get_schema();
169181
validate_log_context_schema(schema.as_ref(), DEFAULT_TIMESTAMP_KEY)?;
170182
let match_fields = normalize_log_context_match_fields(
@@ -191,7 +203,7 @@ pub async fn query_context(
191203
&authorized_datasets,
192204
&context_start_time_str,
193205
&context_end_time_str,
194-
&tenant_id,
206+
tenant_id,
195207
)
196208
.await?;
197209
debug!(
@@ -242,8 +254,8 @@ pub async fn query_context(
242254
);
243255

244256
let (newer_records, older_records) = tokio::try_join!(
245-
execute_log_context_rows(&newer_payload, &authorized_datasets, &tenant_id),
246-
execute_log_context_rows(&older_payload, &authorized_datasets, &tenant_id),
257+
execute_log_context_rows(&newer_payload, &authorized_datasets, tenant_id),
258+
execute_log_context_rows(&older_payload, &authorized_datasets, tenant_id),
247259
)?;
248260
let (records, anchor_index) =
249261
build_log_context_records_window(newer_records, older_records, page_size)?;
@@ -274,7 +286,7 @@ pub async fn query_context(
274286
tenant_id.as_deref().unwrap_or(DEFAULT_TENANT),
275287
);
276288

277-
Ok(web::Json(LogContextResponse {
289+
Ok(LogContextResponse {
278290
scope,
279291
context_start_time: context_start_time_str,
280292
context_end_time: context_end_time_str,
@@ -284,7 +296,7 @@ pub async fn query_context(
284296
anchored_duplicate: LOG_CONTEXT_ANCHORED_DUPLICATE,
285297
records,
286298
queries,
287-
}))
299+
})
288300
}
289301

290302
fn normalize_log_context_page_size(page_size: Option<u64>) -> Result<u64, QueryError> {

‎src/tool_catalog.rs‎

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub fn validate_tool_arguments(schema: &Value, arguments: &Value) -> Result<(),
136136

137137
fn validate_schema_value(schema: &Value, value: &Value, path: &str) -> Result<(), String> {
138138
if let Some(result) = validate_any_of(schema, value, path) {
139-
return result;
139+
result?;
140140
}
141141

142142
validate_enum(schema, value, path)?;
@@ -337,7 +337,9 @@ pub fn oss_read_tool_specs() -> Vec<ToolSpec> {
337337
json!({
338338
"query": string_property("User request or dataset search text."),
339339
"selectedDataset": { "type": "string" },
340-
"contextDataset": { "type": "string" }
340+
"contextDataset": { "type": "string" },
341+
"telemetryType": { "type": "string", "enum": ["logs", "metrics", "traces"] },
342+
"limit": { "type": "integer", "minimum": 1, "maximum": 20, "default": 5 }
341343
}),
342344
&["query"],
343345
),
@@ -391,21 +393,29 @@ pub fn oss_read_tool_specs() -> Vec<ToolSpec> {
391393
"get_log_context",
392394
"Get surrounding log context",
393395
"Fetch records around an exact anchor log row.",
394-
object_schema(
395-
json!({
396-
"dataset": string_property("Dataset containing the anchor row."),
397-
"pTimestamp": string_property("Exact p_timestamp from the anchor row."),
398-
"log": { "type": "string" },
399-
"body": { "type": "string" },
400-
"message": { "type": "string" },
401-
"contextWindow": { "type": "string" },
402-
"contextStartTime": { "type": "string" },
403-
"contextEndTime": { "type": "string" },
404-
"conditions": { "type": "object", "additionalProperties": true },
405-
"pageSize": { "type": "integer", "minimum": 1, "maximum": 500, "default": 100 },
406-
}),
407-
&["dataset", "pTimestamp"],
408-
),
396+
{
397+
let mut schema = object_schema(
398+
json!({
399+
"dataset": string_property("Dataset containing the anchor row."),
400+
"pTimestamp": string_property("Exact p_timestamp from the anchor row."),
401+
"log": string_property("Exact log value from the anchor row. Provide exactly one of log, body, or message."),
402+
"body": string_property("Exact body value from the anchor row. Provide exactly one of log, body, or message."),
403+
"message": string_property("Exact message value from the anchor row. Provide exactly one of log, body, or message."),
404+
"contextWindow": { "type": "string" },
405+
"contextStartTime": { "type": "string" },
406+
"contextEndTime": { "type": "string" },
407+
"conditions": { "type": "object", "additionalProperties": true },
408+
"pageSize": { "type": "integer", "minimum": 1, "maximum": 500, "default": 100 },
409+
}),
410+
&["dataset", "pTimestamp"],
411+
);
412+
schema["anyOf"] = json!([
413+
{ "required": ["log"] },
414+
{ "required": ["body"] },
415+
{ "required": ["message"] }
416+
]);
417+
schema
418+
},
409419
),
410420
ToolSpec::new(
411421
"list_log_errors",
@@ -1043,6 +1053,42 @@ mod tests {
10431053
.validate_arguments(&serde_json::json!({ "dataset": "logs" }))
10441054
.is_ok()
10451055
);
1056+
1057+
let resolve_tool = oss_tool_specs()
1058+
.into_iter()
1059+
.find(|tool| tool.name == "resolve_dataset")
1060+
.unwrap();
1061+
assert!(
1062+
resolve_tool
1063+
.validate_arguments(&serde_json::json!({
1064+
"query": "metrics",
1065+
"telemetryType": "metrics",
1066+
"limit": 10
1067+
}))
1068+
.is_ok()
1069+
);
1070+
1071+
let context_tool = oss_tool_specs()
1072+
.into_iter()
1073+
.find(|tool| tool.name == "get_log_context")
1074+
.unwrap();
1075+
assert!(
1076+
context_tool
1077+
.validate_arguments(&serde_json::json!({
1078+
"dataset": "logs",
1079+
"pTimestamp": "2026-10-22T00:00:00Z"
1080+
}))
1081+
.is_err()
1082+
);
1083+
assert!(
1084+
context_tool
1085+
.validate_arguments(&serde_json::json!({
1086+
"dataset": "logs",
1087+
"pTimestamp": "2026-10-22T00:00:00Z",
1088+
"message": "failed"
1089+
}))
1090+
.is_ok()
1091+
);
10461092
}
10471093

10481094
#[actix_web::test]

0 commit comments

Comments
 (0)