Skip to content

feat: implement sandbox_client_discovery_latency_ms metric#381

Open
chw120 wants to merge 2 commits intokubernetes-sigs:mainfrom
chw120:feat/sandbox-client-discovery-latency-12171877838811801471
Open

feat: implement sandbox_client_discovery_latency_ms metric#381
chw120 wants to merge 2 commits intokubernetes-sigs:mainfrom
chw120:feat/sandbox-client-discovery-latency-12171877838811801471

Conversation

@chw120
Copy link
Contributor

@chw120 chw120 commented Mar 9, 2026

Summary

This PR implements the sandbox_client_discovery_latency_ms Prometheus metric for the Python SDK. This metric tracks the time taken for the client to establish a connection to the sandbox, specifically covering Gateway IP assignment (Production mode) or kubectl port-forward setup (Developer mode).

Note: In addition to the status label proposed in #245, I have added a mode label to differentiate between the various discovery mechanisms used.

Key Changes

  • Enhanced Metric Definition: Created clients/python/agentic-sandbox-client/k8s_agent_sandbox/metrics.py to define the histogram with status and mode labels.
  • Mode-Aware Instrumentation: Updated SandboxClient.__enter__ in sandbox_client.py to identify and record the discovery mode:
    • gateway: Used when a Gateway Name is provided (Production Mode).
    • port_forward: Used for the default developer mode setup.
    • The metric is explicitly skipped for preconfigured URLs to avoid skewing discovery data.
  • Dependencies: Added prometheus-client to pyproject.toml.
  • Testing:
    • Updated test_metrics.py with parameterized tests to verify that the correct mode and status labels are applied in different scenarios.
    • Included a validation check in test_client.py to ensure metrics are recorded during standard client initialization.

Working on #245.

chw120 and others added 2 commits March 7, 2026 11:09
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: chw120
Once this PR has been reviewed and has the lgtm label, please assign janetkuo for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 9, 2026
@k8s-ci-robot
Copy link
Contributor

Hi @chw120. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@netlify
Copy link

netlify bot commented Mar 9, 2026

Deploy Preview for agent-sandbox canceled.

Name Link
🔨 Latest commit d658b83
🔍 Latest deploy log https://app.netlify.com/projects/agent-sandbox/deploys/69af01e7e1e9d00008ab37fb

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 9, 2026
@aditya-shantanu
Copy link
Contributor

/assign @igooch

@yongruilin
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 9, 2026
@k8s-ci-robot
Copy link
Contributor

@chw120: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
presubmit-test-autogen-up-to-date d658b83 link true /test presubmit-test-autogen-up-to-date

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@chw120
Copy link
Contributor Author

chw120 commented Mar 9, 2026

/hold
Holding this PR until the client migration proposed in KEP-359 (https://github.com/kubernetes-sigs/agent-sandbox/tree/main/docs/keps/359-refactor-python-sdk) is complete.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants