Skip to content

fix(estimator): inject call options in StructuredLogEstimator and document Google API guidelines - #900

Merged
kyasbal merged 1 commit into
GoogleCloudPlatform:mainfrom
kyasbal:push-qpzqrvsmmnvr
Aug 25, 2026
Merged

kyasbal merged 1 commit into
GoogleCloudPlatform:mainfrom
kyasbal:push-qpzqrvsmmnvr

Conversation

@kyasbal

@kyasbal kyasbal commented Aug 25, 2026

Copy link
Copy Markdown
Member

Summary

This PR ensures that Google Cloud API call options are properly injected into the request context before executing volume estimation queries in StructuredLogEstimator. It also introduces documentation and repository rules defining the mandatory usage of CallOptionInjector whenever calling Google Cloud APIs across KHI.

Background & Motivation

  1. Missing Call Option Injection in StructuredLogEstimator:
    StructuredLogEstimator queries Cloud Monitoring metrics and Cloud Logging probe entries during log volume estimation. Previously, InjectToCallContext was not invoked on the context prior to issuing these queries. Consequently, gRPC call options, custom request headers, and quota project parameters were not propagated, which could lead to API call failures or unexpected quota accounting.
  2. Standardizing Call Option Propagation in KHI:
    In KHI, all calls to Google Cloud APIs must carry options associated with their target resource container (googlecloud.Project, googlecloud.Folder, or googlecloud.Organization). A dedicated skill and rule documentation ensures all current and future tasks/components adhere to this requirement.

Key Changes

1. Go Backend

  • pkg/api/googlecloud/logestimator/estimator.go:
    • Added CallOptionInjector *googlecloud.CallOptionInjector field to StructuredLogEstimator.
    • Updated constructors NewStructuredLogEstimator and NewStructuredLogEstimatorFromClients to accept callOptionInjector.
    • In Estimate(), applied ctx = e.CallOptionInjector.InjectToCallContext(ctx, container) before spawning goroutines with errgroup.WithContext(ctx).
  • pkg/task/inspection/googlecloudcommon/contract/structured_listlogentries_task.go:
    • Added APIClientCallOptionsInjectorTaskID.Ref() to task dependencies.
    • In dry-run mode, retrieved callOptionInjector via coretask.GetTaskResultOptional and forwarded it to StructuredLogEstimator.
  • Unit Tests:
    • pkg/api/googlecloud/logestimator/estimator_test.go: Added TestStructuredLogEstimator_CallOptionInjector verifying context injection on Cloud Monitoring and Cloud Logging queries.
    • pkg/task/inspection/googlecloudcommon/contract/structured_listlogentries_task_test.go: Added TestStructuredListLogEntriesTask_DryRun_CallOptionInjector testing dependency resolution and call option propagation.
    • Updated existing estimator tests to pass injector or nil.

2. Developer & Agent Guidelines

  • .agents/skills/googlecloud_api/SKILL.md:
    • Created a new skill defining mandatory patterns and rules for calling Google Cloud APIs in KHI, covering task DAG dependencies, helper structs/fetchers, raw HTTP headers, and unit testing.
  • .agents/skills/khi_parser/SKILL.md:
    • Added reference to googlecloud-api skill in Step 2 (Log Query Tasks).
  • .agents/rules/khi-task-rule.md:
    • Added Section 6 requiring CallOptionInjector.InjectToCallContext for any task invoking Google Cloud APIs.

Verification

  • Unit Tests: make test-go passed (all 672 top-level tests, 2,732 subtests).
  • Linters & Formatters: make lint-go, make lint-md, make format-md, and make pre-commit passed with 0 issues.

@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 introduces mandatory rules and guidelines for calling Google Cloud APIs in KHI, including the addition of a new skill guide and task rules regarding the CallOptionInjector. The StructuredLogEstimator and StructuredListLogEntriesTask have been updated to support injecting call options into the context. The review feedback suggests strictly adhering to the new rules by retrieving the injector using coretask.GetTaskResult instead of GetTaskResultOptional in StructuredListLogEntriesTask, and simplifying the corresponding test by removing the unnecessary test case that runs without this mandatory dependency.

Pass CallOptionInjector into StructuredLogEstimator and call
InjectToCallContext prior to querying Cloud Monitoring metrics
and Cloud Logging probe entries. In StructuredListLogEntriesTask,
retrieve CallOptionInjector from task dependencies and provide it
during volume estimation.

Add googlecloud-api skill and update task rules to document mandatory
CallOptionInjector usage when calling Google APIs in KHI.
@kyasbal
kyasbal force-pushed the push-qpzqrvsmmnvr branch from fe8b49b to b57a18a Compare August 25, 2026 08:49
@kyasbal
kyasbal merged commit a09b3d0 into GoogleCloudPlatform:main Aug 25, 2026
16 checks passed
@kyasbal
kyasbal deleted the push-qpzqrvsmmnvr branch August 25, 2026 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant