Skip to content

feat(mcp): align summary section routing and record per-query log counts - #1194

Merged
kyasbal merged 2 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-msqqkutxnvkr
Oct 29, 2026
Merged

kyasbal merged 2 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-msqqkutxnvkr

Conversation

@kyasbal

@kyasbal kyasbal commented Oct 29, 2026

Copy link
Copy Markdown
Member

Fixes #1120

Background

Inspection summaries exposed via khi://inspections/{id} group recorded queries, properties, and task observations into Feature sections, Common Properties, and Shared & Filter Context by walking the resolved task DAG. Previously, two gaps caused inaccurate routing and log counts:

  1. Indiscriminate edge traversal and arbitrary tie-breaking: Section resolution walked all outgoing edges (except from feature-gated tasks) without distinguishing mandatory Use dependencies from optional (UseOptional) or fan-in (UseTag) dependencies, and without stopping at FormTask or fan-in inventory aggregator boundaries. As a result, shared inventory tasks, ungated discovery tasks, form helpers, and optionally referenced tasks could be pulled into a downstream Feature section. In addition, when an upstream helper was genuinely required by multiple Features, findNearestFeature picked only a single Feature by hop distance and display order, making each Feature section's contents depend on which other Features happened to be enabled.
  2. Overwritten multi-query entries: When DefineStructuredListLogEntriesTask executed multiple split StructuredLogQuery filters (for example, GCE Serial Port Logs across large node sets), every sub-query reused the same taskID key in summary.RecordQuery, overwriting earlier queries and attaching the merged log total to the final query only.

Approach

  • Dependency scope on resolved edges: TaskEdge now retains the resolved DependencyScope (taking the strongest scope when duplicate edges between the same pair of tasks are merged) so downstream graph consumers can distinguish mandatory point-to-point dependencies (CardinalityPointToPoint with ScopeAll) directly from DAG metadata without summary-specific task labels.
  • Boundary-aware multi-feature section routing:
    • FeatureTask, FormTask, and fan-in aggregator tasks (tasks declaring CardinalityFanIn inputs, such as DefineInventoryTask) are classified as section boundaries whose outgoing edges do not propagate Feature ownership downstream.
    • Ownership traversal walks only mandatory point-to-point (ScopeAll) edges starting from a task's feature gate (WithFeatureGate) if present, or the task itself otherwise, and collects all reachable FeatureTasks.
    • Tasks reaching 1 or more Features write their queries, properties, and task reports to every reachable Feature section so each Feature section remains self-contained; tasks reaching 0 Features route to Shared & Filter Context.
  • Per-query summary IDs and fetched log counts: Multi-query DefineStructuredListLogEntriesTask executions now key summary entries with zero-padded per-query IDs (<taskID>#<04d>) while keeping single-query IDs and Web UI QueryMetadata unchanged, recording each sub-query's fetched log count individually before k-way merging.

UI / Output Changes

Multi-query log tasks in khi://inspections/{id} now preserve every split query in execution order with its individual fetched log count instead of collapsing into the last sub-query:

### Queries

- **container-logs-0** (2 logs)
  ```
  resource.type="k8s_container"
  resource.labels.node_name="node-a"
  timestamp >= "2025-01-01T01:00:00+0000"
  timestamp <= "2025-01-01T01:01:00+0000"
  ```
- **container-logs-1** (0 logs)
  ```
  resource.type="k8s_container"
  resource.labels.node_name="node-b"
  timestamp >= "2025-01-01T01:00:00+0000"
  timestamp <= "2025-01-01T01:01:00+0000"
  ```

Alternatives Considered

  • Routing tasks required by 2+ Features to Shared & Filter Context vs. nearest-hop tie-breaking: Breaking ties by hop distance or Feature display order hides required upstream queries/observations from all but one Feature, whereas moving them to Shared & Filter Context causes a task to jump between Feature and Shared sections depending on whether a second Feature is enabled. Fanning writes out to every reachable Feature keeps each Feature section deterministic and self-contained while reserving Shared & Filter Context strictly for cross-feature fan-in aggregators and feature-independent tasks.
@kyasbal kyasbal added type:feature New feature or request area:backend-core Core backend frameworks, DAG task runner, and server API area:backend-parser Log parsers and log timeline mapper tasks labels Oct 29, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the task summary section resolution to support multi-feature fan-out and properly handle boundaries like fan-in tasks. Specifically, the destination struct now tracks a slice of featureIDs instead of a single ID, allowing queries, properties, and markdown to propagate to all reachable features. Additionally, the task graph resolver has been updated to propagate and preserve dependency scopes on task edges, and structured log fetching now records log counts individually for split queries. Extensive test coverage has been added or updated to reflect these changes. There are no review comments, so no feedback is provided.

Comment on lines +159 to +161
wantLogsString []string
wantSummaryQueries []summary.Query
wantError error

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 789a6b7: unified the split want* fields and in-loop summary.Snapshot construction into single whole-struct want outcome fields in both TestStructuredListLogEntriesTask_Run_FetchLogs and TestDefineStructuredListLogEntriesTask.

Comment thread pkg/core/task/graphresolver_test.go Outdated
@@ -155,7 +155,7 @@ func TestResolveGraph_OptionalDependencies(t *testing.T) {
initialTasks []UntypedTask
availableTasks []UntypedTask
wantTaskIDs []string

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 789a6b7: unified wantTaskIDs and wantEdges into a single want resolvedGraph outcome struct in both TestResolveGraph_OptionalDependencies and TestResolveGraph_PointToPointScopeActiveFeatures.

@kyasbal
kyasbal added this pull request to the merge queue Oct 29, 2026
Merged via the queue into GoogleCloudPlatform:main with commit 60d5e69 Oct 29, 2026
17 checks passed
@kyasbal
kyasbal deleted the push-msqqkutxnvkr branch October 29, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend-core Core backend frameworks, DAG task runner, and server API area:backend-parser Log parsers and log timeline mapper tasks type:feature New feature or request

1 participant