Skip to content

Commit 2f8718d

Browse files
nikhilsinhaparseableclaude
authored andcommitted
update: tool catalog (parseablehq#1831)
Port of upstream parseablehq/parseable 32979cb. add get_trace_activity to tool catalog update executor to have tool implementations and reuse in enterprise Fork conflict resolutions: - tool_catalog: use upstream's validate_one_of helper (same exactly-one semantics and message as the fork's inline check) and keep the fork's `const` validation; tool counts become 54 total / 41 read. - tool_executor: adopt upstream's parser-based validate_tool_sql and bounded_tool_sql; keep fork time-expression imports, the Result handling for list_dashboards_internal, and the fork's call_tool_registry (dashboard tool routing, suspension and Query gates); keep calling execute_oss_tool_inner there because the spec is already validated. - tests: merge both suites; update the fork bounded-SQL test to avoid a wildcard CTE that upstream's validator now rejects. Also add tests for get_trace_activity (executed against a DataFusion fixture), its argument validation, resolve_dataset/get_log_context schema changes, timezone day boundaries and sample_events range pairing, and document the new and changed tools in docs/tool-api.md. (cherry picked from commit 32979cb) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6aaee1d commit 2f8718d

6 files changed

Lines changed: 1597 additions & 247 deletions

File tree

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ tracing-actix-web = "0.7"
139139

140140
# Time and Date
141141
chrono = "0.4"
142+
chrono-tz = "0.10"
142143
chrono-humanize = "0.2"
143144
humantime = "2.1.0"
144145
humantime-serde = "1.1"

‎docs/tool-api.md‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,95 @@ and last-seen value, and coalesces supported aliases per row. Its `total` is the
130130
number of returned groups, not an unbounded count of all matching groups. The
131131
native Errors page additionally separates issues by message, so its grouping
132132
and pagination are not identical to this summary tool.
133+
134+
## SQL tool limits
135+
136+
`query_sql`, `explain_query` and other tools that run SQL internally parse the
137+
statement with DataFusion's SQL parser and accept exactly one `SELECT` or `WITH`
138+
query. A trailing semicolon and trailing comments are allowed. Every `SELECT`
139+
projection, including those inside nested queries and set operations, must
140+
name at most 10 explicit columns. `*` and `table.*` are rejected. Casts to
141+
`INT64`, `UINT64` or `FLOAT64` are rejected with a hint to use `BIGINT` or
142+
`DOUBLE`. The statement is wrapped with an outer `LIMIT 500`. `sample_events`
143+
returns at most 10 columns, choosing common observability fields such as
144+
`p_timestamp`, `service.name`, `severity_text`, `body` and `trace_id` before
145+
other fields.
146+
147+
## Dataset and time resolution
148+
149+
`list_datasets`, `resolve_dataset` and `discover_datasets` omit internal
150+
datasets.
151+
152+
`resolve_dataset` accepts an optional `telemetryType` (`logs`, `metrics` or
153+
`traces`) and `limit` (1–20, default 5). It resolves a `selectedDataset` or
154+
`contextDataset` exactly, or resolves the only visible dataset. Otherwise it
155+
ranks visible datasets by name match against `query`. It resolves only a
156+
unique high-confidence name match. In every other case it returns
157+
`status: "ambiguous"` with up to `limit` scored `candidates`, or `"not_found"`.
158+
It never falls back to an arbitrary dataset. A selected dataset whose telemetry
159+
type does not match `telemetryType` returns `not_found`.
160+
161+
`discover_datasets` counts events in the requested range for each visible
162+
dataset of the requested telemetry type that the caller can query. It returns
163+
active datasets ordered by event count as `{ name, eventsInRange }`, together
164+
with `selectedDatasets`, `activeDatasetCount`, `truncated` and up to 20
165+
`unavailableDatasets`. If no dataset is active and at least one could not be
166+
counted, the result has `status: "error"` and no datasets.
167+
168+
`resolve_time_range` accepts any IANA `timezone` (default `UTC`), and uses it
169+
for `today` and `yesterday` day boundaries. It also accepts `last <duration>`,
170+
`past <duration>`, `now-<duration>`, `<start> to <end>` and RFC3339 start
171+
times. An unknown timezone is an error.
172+
173+
`sample_events` accepts an explicit `startTime` and `endTime`, which must be
174+
provided together. They take precedence over `minutes`.
175+
176+
## Log context
177+
178+
`get_log_context` uses the same implementation as `POST /api/v1/query/context`.
179+
Arguments must include exactly one of `log`, `body` or `message`, holding the
180+
anchor row's exact value. The schema enforces this with `oneOf`, so calls with
181+
none or more than one are rejected with `400`. If no context bounds are given,
182+
the window defaults to `contextWindow: "5 minutes"`. Returned records keep at
183+
most 10 fields per row, preferring `p_timestamp`, service, severity, message
184+
and trace identifiers. The response also includes the anchor index, scope and
185+
the executed queries.
186+
187+
## Trace activity
188+
189+
`get_trace_activity` returns a bucketed span and trace activity series for one
190+
traces dataset:
191+
192+
```json
193+
{
194+
"name": "get_trace_activity",
195+
"arguments": {
196+
"dataset": "otel-traces",
197+
"startTime": "2026-10-22T00:00:00Z",
198+
"endTime": "2026-10-22T01:00:00Z",
199+
"groupBy": ["service.name"],
200+
"filters": { "span_status_code": 2 },
201+
"bucketCount": 60
202+
}
203+
}
204+
```
205+
206+
`dataset`, `startTime` and `endTime` are required. `groupBy` takes up to 5
207+
exact field names. `filters` maps exact field names to JSON scalars: strings,
208+
numbers and booleans test equality, and `null` tests `IS NULL`. `bucketCount`
209+
is 1–100, default 60. It approximates the number of `DATE_BIN` buckets over the
210+
dataset's time partition, or `p_timestamp` if none is configured. The dataset
211+
must have traces telemetry and contain `span_span_id` and `span_trace_id`.
212+
Unknown fields are rejected. `span_count` is `COUNT(DISTINCT span_span_id)` and
213+
`trace_count` is `COUNT(DISTINCT span_trace_id)`, so duplicate span rows are
214+
not double counted. The result contains the exact executed SQL as `query`,
215+
along with `bucketInterval`, `semantics` and up to 500 `rows`. Clients can
216+
rerun that SQL unchanged, for example in a dashboard tile.
217+
218+
## Argument schema validation
219+
220+
`inputSchema` is enforced server-side for `type`, `required`,
221+
`additionalProperties`, `enum`, `const`, `minLength`/`maxLength`,
222+
`minimum`/`maximum`, `minItems`/`maxItems`, `items`, `anyOf` and `oneOf`.
223+
`oneOf` passes only when exactly one variant matches. Combinators are checked
224+
in addition to sibling keywords; they do not replace them.

‎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> {

0 commit comments

Comments
 (0)