-
Notifications
You must be signed in to change notification settings - Fork 8
Add a metric to track job creation to pod creation time. #13
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ import ( | |
| "k8s.io/client-go/tools/cache" | ||
| "k8s.io/client-go/util/workqueue" | ||
| "k8s.io/klog/v2" | ||
| "k8s.io/perf-tests/clusterloader2/pkg/framework/client" | ||
| "k8s.io/perf-tests/clusterloader2/pkg/measurement" | ||
| measurementutil "k8s.io/perf-tests/clusterloader2/pkg/measurement/util" | ||
| "k8s.io/perf-tests/clusterloader2/pkg/measurement/util/informer" | ||
|
|
@@ -60,6 +61,8 @@ func createJobLifecycleLatencyMeasurement() measurement.Measurement { | |
| selector: util.NewObjectSelector(), | ||
| jobStateEntries: measurementutil.NewObjectTransitionTimes(jobLifecycleLatencyMeasurementName), | ||
| eventQueue: workqueue.New(), | ||
| podCreationTime: measurementutil.NewPodCreationEventTimes(), | ||
| eventTicker: time.NewTicker(time.Minute), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This means that the measurement will run very 1 minute to collect data right? I wonder if we should do second for more fine-grained result? Or allow users to customize the frequency with a variable?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct me if I'm wrong, but the events are stored in ETCD for a while, every time we list, it will return all the events in its cache. As long as the interval is smaller than the life span the cache, it should not miss anything.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Talked to Anson, I'm working on a new version that uses informer of pods instead of ListEvents. |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -69,6 +72,8 @@ type jobLifecycleLatencyMeasurement struct { | |
| stopCh chan struct{} | ||
| eventQueue *workqueue.Type | ||
| jobStateEntries *measurementutil.ObjectTransitionTimes | ||
| podCreationTime *measurementutil.PodCreationEventTimes | ||
| eventTicker *time.Ticker | ||
| } | ||
|
|
||
| // Execute supports two actions: | ||
|
|
@@ -130,6 +135,7 @@ func (p *jobLifecycleLatencyMeasurement) start(c clientset.Interface) error { | |
| p.addEvent, | ||
| ) | ||
| go p.processEvents() | ||
| go measurementutil.RunEveryTick(p.eventTicker, p.getFuncToListJobEvents(c), p.stopCh) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or do we have to measure periodically? or it can be event driven |
||
| return informer.StartAndSync(i, p.stopCh, informerSyncTimeout) | ||
| } | ||
|
|
||
|
|
@@ -222,6 +228,12 @@ func (p *jobLifecycleLatencyMeasurement) gather(identifier string, timeout time. | |
| } | ||
| p.stop() | ||
| jobLifecycleLatency := p.jobStateEntries.CalculateTransitionsLatency(jobLifecycleTransitions, measurementutil.MatchAll) | ||
| jobCreationTimes := make(map[string]time.Time) | ||
| for jobName := range p.jobStateEntries.Keys() { | ||
| jobCreationTimes[jobName], _ = p.jobStateEntries.Get(jobName, jobCreated) | ||
| } | ||
| podCreationTime := p.podCreationTime.CalculateLatency(jobCreationTimes) | ||
| jobLifecycleLatency["create_to_pod_start"] = &podCreationTime | ||
| content, jsonErr := util.PrettyPrintJSON(measurementutil.LatencyMapToPerfData(jobLifecycleLatency)) | ||
| if jsonErr != nil { | ||
| return nil, jsonErr | ||
|
|
@@ -234,3 +246,27 @@ func (p *jobLifecycleLatencyMeasurement) gather(identifier string, timeout time. | |
| func createMetaNamespaceKey(namespace, name string) string { | ||
| return namespace + "/" + name | ||
| } | ||
|
|
||
| func (p *jobLifecycleLatencyMeasurement) getFuncToListJobEvents(c clientset.Interface) func() { | ||
| return func() { | ||
| klog.V(2).Infof("%s: list job events", p) | ||
| options := metav1.ListOptions{ | ||
| FieldSelector: "involvedObject.kind=Job", | ||
| } | ||
| events, err := client.ListEventsWithOptions(c, p.selector.Namespace, options) | ||
| if err != nil { | ||
| klog.Errorf("Failed to list events: %v", err) | ||
| return | ||
| } | ||
| for _, event := range events.Items { | ||
| key := createMetaNamespaceKey(event.InvolvedObject.Namespace, event.InvolvedObject.Name) | ||
| if !p.jobStateEntries.Exists(key) { | ||
| continue | ||
| } | ||
| if event.Reason != "SuccessfulCreate" { | ||
| continue | ||
| } | ||
| p.podCreationTime.Set(key, &event) | ||
| } | ||
| } | ||
| } | ||
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.
can we change the order of these two functions, it will make resolve conflicts easier