feat: add nodepool_provisioning_duration metric - #40
Conversation
Updated internal/records/events_test.go to expect ProvisioningDuration: 1h and ProvisioningState: "success" for older test cases that calculate these values but previously defaulted to zero values in the test table.
|
Can you update the release notes and document the metric definition? perhaps start a docs/metrics.md and show what's expected for nodepools still being provisioned, failed and succeeded |
There was a problem hiding this comment.
Can you add a test case for the provisioning and failed case as well?
There was a problem hiding this comment.
Added unit test cases for ongoing provisioning (StateProvisioning) and failed provisioning (StateFailed) inside internal/records/events_test.go.
| }) | ||
|
|
||
| // Added to test provisioning duration for resources that never become UP. | ||
| It("should correctly summarize a flow that never becomes UP", func() { |
There was a problem hiding this comment.
can you assert the expectation of downtime_initial as well?
There was a problem hiding this comment.
Added the assertion for summary.DownTimeInitial to the integration test case.
There was a problem hiding this comment.
Can we add in the failed provisioning case?
There was a problem hiding this comment.
Added the new integration test case It("should correctly summarize a failed provisioning flow") to cover this.
| if n == 1 { | ||
| summary.DownTime = now.Sub(r.UpEvents[0].Timestamp) | ||
| summary.ProvisioningDuration = summary.DownTime | ||
| summary.ProvisioningState = "provisioning" |
There was a problem hiding this comment.
lets use const for valid values
There was a problem hiding this comment.
Defined StateProvisioning, StateSuccess, and StateFailed constants in internal/records/events.go and updated the code and tests to use them.
There was a problem hiding this comment.
Let's also assert the metric is correctly emitted as well
There was a problem hiding this comment.
Added the WithLabel helper to the test metric structure and implemented assertions to verify nodepool_provisioning_duration_seconds is correctly emitted with the right labels during integration runs.
echiugoog
left a comment
There was a problem hiding this comment.
Please also update RELEASE_NOTES.md
Created |
Updated |
|
|
||
| ## Nodepool Metrics | ||
|
|
||
| ### `megamon.nodepool.provisioning.duration` |
There was a problem hiding this comment.
maybe add a version introduced in
There was a problem hiding this comment.
Added the metric introduction version (v1.1.1) to the documentation.
| ## v1.1.1 | ||
|
|
||
| ### New features and improvements | ||
| * Add `nodepool.provisioning.duration` metric to track GKE NodePool provisioning latency with state tracking (`provisioning`, `success`, `failed`). |
There was a problem hiding this comment.
can you reference the docs/metrics.md file as well?
There was a problem hiding this comment.
Added a reference link pointing to the docs/metrics.md file.
| Attrs: utils.ExtractNodePoolAttrs(np), | ||
| Status: np.Status, | ||
| ExpectedDown: np.Status == "STOPPING" || np.Status == "DELETING", | ||
| Failed: np.Status == "ERROR" || np.Status == "RUNNING_WITH_ERROR", |
There was a problem hiding this comment.
Let's introduce const for these strings
There was a problem hiding this comment.
Defined constants for GKE status strings inside node_poller.go
| UpEvents []UpEvent `json:"upEvents"` | ||
| } | ||
|
|
||
| const ( |
There was a problem hiding this comment.
can we prefix this so we know it's for nodepool provisioning?
There was a problem hiding this comment.
Prefix-renamed state constants
| Attrs: utils.ExtractNodePoolAttrs(np), | ||
| Status: np.Status, | ||
| ExpectedDown: np.Status == "STOPPING" || np.Status == "DELETING", | ||
| Failed: np.Status == "ERROR" || np.Status == "RUNNING_WITH_ERROR", |
There was a problem hiding this comment.
Let's update node_poller_test.go to cover the change as well
There was a problem hiding this comment.
Expanded node_poller_test.go to cover these changes as well.
|
|
||
| // ProvisioningDuration is the time spent provisioning. | ||
| ProvisioningDuration time.Duration `json:"provisioningDuration"` | ||
| // ProvisioningState is the state of provisioning (provisioning or success). |
There was a problem hiding this comment.
it's not just provisioning or success? perhaps omit this part of the comment for brevity
There was a problem hiding this comment.
Omitted comment for brevity.
|
|
||
| ## Nodepool Metrics | ||
|
|
||
| ### `megamon.nodepool.provisioning.duration` |
|
|
||
| var log = logf.Log.WithName("upness") | ||
|
|
||
| const ( |
There was a problem hiding this comment.
can you use these in node_poller_test as well?
| UpEvents []UpEvent `json:"upEvents"` | ||
| } | ||
|
|
||
| const ( |
|
@nstogner could you please review this PR? It adds the NodePool provisioning duration metric and refactors statuses and states into typed constants (per Edwin's feedback). |
This PR introduces a new metric,
nodepool_provisioning_duration, to track and report the time taken for GKE NodePools to become ready after creation. This helps in monitoring provisioning latency, detecting scaling issues, and capturing provisioning failures.Results
We verified the new metric on (
megamon-test-cluster) by creating test TPU node pools and observing the output.Raw Metrics Output (Ongoing State)
Curling the metrics endpoint (
:8080/metrics) while the NodePool was still provisioning confirmed that the metric is emitted with the"provisioning"state:Raw Metrics Output (Success State)
Once the NodePool entered the
RUNNINGstatus, the metric successfully transitioned to the"success"state with the final duration frozen:Controller Logs
The GCS-serialized event record confirmed the internal calculation of
provisioningDuration(in nanoseconds) matching the external metrics:{ "type": "nodepools", "summary": { "downTimeProvisioned": 330000998025, "provisioningDuration": 330000998025, "provisioningState": "success" } }These results confirm that:
provisioning,success, andfailed).Key Changes
internal/records/events.go: AddedStateProvisioning,StateSuccess, andStateFailedconstants to eliminate magic strings, and implemented the failed provisioning timeline calculation.internal/records/report.go: Added theFailedflag toUpnessto bridge data from the poller to events.internal/aggregator/poller/node_poller.go: Mapped GKE"ERROR"and"RUNNING_WITH_ERROR"statuses to the internalFailedstate.internal/metrics/metrics.go: Registered and implemented the emission of the newnodepool_provisioning_durationmetric.internal/records/events_test.go: Added unit tests for ongoing and failed provisioning scenarios.test/integration/cases_test.go: Added integration specs verifying both ongoing and failed provisioning scenarios, addedDownTimeInitialassertions, and implemented label assertions for metrics.docs/metrics.md: [NEW] Created metric documentation and examples.docs/RELEASE_NOTES.md: Updated release notes for the upcomingv1.1.1release.go.mod: Resolved direct dependency alignment forsigs.k8s.io/lws.Context
This branch has been rebased on top of the latest
main(which includes the consolidated workload reconciler changes from PR #39) to ensure a clean and isolated diff containing only this feature. Conflict inevents_test.gowas resolved by combining assertions from both branches.