-
Notifications
You must be signed in to change notification settings - Fork 33
feat: controller lease acquisition metrics (JEP-0013 Phase 2) #932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RoddieKieley
wants to merge
3
commits into
jumpstarter-dev:main
Choose a base branch
from
RoddieKieley:jep-0013-phase2-controller-metrics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+707
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
controller/deploy/operator/internal/controller/jumpstarter/controller_metrics_bind_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| Copyright 2026. The Jumpstarter Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package jumpstarter | ||
|
|
||
| import ( | ||
| operatorv1alpha1 "github.com/jumpstarter-dev/jumpstarter/controller/deploy/operator/api/v1alpha1" | ||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| var _ = Describe("createControllerDeployment metrics bind", func() { | ||
| var r *JumpstarterReconciler | ||
| var js *operatorv1alpha1.Jumpstarter | ||
|
|
||
| BeforeEach(func() { | ||
| r = &JumpstarterReconciler{} | ||
| js = &operatorv1alpha1.Jumpstarter{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "jumpstarter", | ||
| Namespace: "jumpstarter-lab", | ||
| }, | ||
| Spec: operatorv1alpha1.JumpstarterSpec{ | ||
| Controller: operatorv1alpha1.ControllerConfig{ | ||
| Image: "example.com/controller:test", | ||
| ImagePullPolicy: corev1.PullIfNotPresent, | ||
| Replicas: 1, | ||
| }, | ||
| }, | ||
| } | ||
| }) | ||
|
|
||
| It("exposes -metrics-bind-address=:8080 and metrics port 8080", func() { | ||
| dep := r.createControllerDeployment(js, "testhash") | ||
| Expect(dep).NotTo(BeNil()) | ||
| Expect(dep.Spec.Template.Spec.Containers).NotTo(BeEmpty()) | ||
|
|
||
| c := dep.Spec.Template.Spec.Containers[0] | ||
| Expect(c.Args).To(ContainElement("-metrics-bind-address=:8080")) | ||
|
|
||
| var metricsPort *corev1.ContainerPort | ||
| for i := range c.Ports { | ||
| if c.Ports[i].Name == "metrics" { | ||
| metricsPort = &c.Ports[i] | ||
| break | ||
| } | ||
| } | ||
| Expect(metricsPort).NotTo(BeNil(), "expected container port named metrics") | ||
| Expect(metricsPort.ContainerPort).To(Equal(int32(8080))) | ||
| }) | ||
| }) |
75 changes: 75 additions & 0 deletions
75
controller/internal/controller/lease_acquisition_metrics_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| Copyright 2026. The Jumpstarter Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package controller | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| jumpstarterdevv1alpha1 "github.com/jumpstarter-dev/jumpstarter/controller/api/v1alpha1" | ||
| jmpmetrics "github.com/jumpstarter-dev/jumpstarter/controller/internal/metrics" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| func TestLeaseAcquisitionTransitionResult_SuccessOnce(t *testing.T) { | ||
| lease := &jumpstarterdevv1alpha1.Lease{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: "lease-1"}, | ||
| Status: jumpstarterdevv1alpha1.LeaseStatus{ | ||
| ExporterRef: &corev1.LocalObjectReference{Name: "exporter-a"}, | ||
| }, | ||
| } | ||
|
|
||
| result, ok := leaseAcquisitionTransitionResult(nil, false, lease) | ||
| if !ok || result != jmpmetrics.ResultSuccess { | ||
| t.Fatalf("first transition: got (%q, %v), want (%q, true)", result, ok, jmpmetrics.ResultSuccess) | ||
| } | ||
|
|
||
| // Reconcile retry after status persisted: priorExporterRef is set. | ||
| result, ok = leaseAcquisitionTransitionResult(lease.Status.ExporterRef, false, lease) | ||
| if ok { | ||
| t.Fatalf("second observation after persist must not record, got %q", result) | ||
| } | ||
| } | ||
|
|
||
| func TestLeaseAcquisitionTransitionResult_FailureOnce(t *testing.T) { | ||
| lease := &jumpstarterdevv1alpha1.Lease{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: "lease-2"}, | ||
| } | ||
| lease.SetStatusUnsatisfiable("NoAccess", "no exporters approved") | ||
|
|
||
| result, ok := leaseAcquisitionTransitionResult(nil, false, lease) | ||
| if !ok || result != jmpmetrics.ResultFailure { | ||
| t.Fatalf("first unsatisfiable transition: got (%q, %v), want (%q, true)", result, ok, jmpmetrics.ResultFailure) | ||
| } | ||
|
|
||
| // Reconcile retry after Unsatisfiable was persisted. | ||
| result, ok = leaseAcquisitionTransitionResult(nil, true, lease) | ||
| if ok { | ||
| t.Fatalf("second unsatisfiable observation after persist must not record, got %q", result) | ||
| } | ||
| } | ||
|
|
||
| func TestLeaseAcquisitionTransitionResult_NoTransition(t *testing.T) { | ||
| lease := &jumpstarterdevv1alpha1.Lease{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: "lease-3"}, | ||
| } | ||
|
|
||
| result, ok := leaseAcquisitionTransitionResult(nil, false, lease) | ||
| if ok { | ||
| t.Fatalf("pending lease with no exporter/unsatisfiable must not record, got %q", result) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from the pov of exemplars and useful data, each lease_id is different, so it would not provide much statistical value.
What do you think about recording the assigned exporter name instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having only really run this in development in my own homelab I requested an evaluation of the implications of having lease_id both with and without and additional exporter as the initial take was 'The JEP has a specific design and the lease_id should not be removed'. The results sound reasonable, but as one of the authors of the JEP-0013 you might have a better idea than me if it simply "sounds reasonable" or is actually reasonable:
Verdict for #932
Keep JEP defaults:
client+lease_id. Do not replacelease_idwith exporter.Optional later (or a short PR reply to mangelajo): on success only, also attach
exporterwhenStatus.ExporterRefis set, still under the allowlist / 128-rune budget — additive drill-down, not a substitute forlease_id.That matches the JEP table:
lease_idis exemplar-for-drill-down;exporteris primarily a bounded Prom/Loki label on exporter-scoped metrics, not the lease-acquire join key.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kirkbrauer @raballew As others who reviewed the original JEP-0013 PR #631 will likely be afk for a few days at least maybe you have an educated opinion to chime in with?