Skip to content

Commit

Permalink
misc renames
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Vasilev <[email protected]>
  • Loading branch information
Omrigan committed Jul 19, 2024
1 parent 280163e commit 9b07933
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
2 changes: 2 additions & 0 deletions neonvm/controllers/vm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,8 @@ func (r *VMReconciler) doReconcile(ctx context.Context, vm *vmv1.VirtualMachine)
// do nothing
}

// Propagate TargetRevision to CurrentRevision. This is done only if the VM is fully
// reconciled and running.
if vm.Status.Phase == vmv1.VmRunning && vm.Spec.TargetRevision != nil {
rev := vm.Spec.TargetRevision.WithTime(time.Now())
vm.Status.CurrentRevision = &rev
Expand Down
6 changes: 3 additions & 3 deletions pkg/agent/core/revsource/revsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ func Propagate(
now time.Time,
target vmv1.RevisionWithTime,
currentSlot *vmv1.Revision,
metricCB ObserveCallback,
cb ObserveCallback,
) {
if metricCB != nil {
if cb != nil {
diff := now.Sub(target.UpdatedAt.Time)
metricCB(diff, target.Flags)
cb(diff, target.Flags)
}
if currentSlot == nil {
return
Expand Down
15 changes: 9 additions & 6 deletions pkg/agent/core/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ type Config struct {
// RevisionSource is the source of revisions to track the progress during scaling.
RevisionSource RevisionSource `json:"-"`

// PromMetricsCallbacks are the callbacks to update the Prometheus metrics.
PromMetricsCallbacks ObservabilityCallbacks `json:"-"`
// ObservabilityCallbacks are the callbacks to submit datapoints for observability.
ObservabilityCallbacks ObservabilityCallbacks `json:"-"`
}

type LogConfig struct {
Expand Down Expand Up @@ -222,6 +222,9 @@ type neonvmState struct {
OngoingRequested *api.Resources
RequestFailedAt *time.Time

// TargetRevision is the revision agent works towards. Contrary to monitor/plugin, we
// store it not only in action, but also here. This is needed, because for NeonVM propagation
// happens after the changes are actually applied, when the action object is long gone.
TargetRevision vmv1.RevisionWithTime
CurrentRevision vmv1.Revision
}
Expand Down Expand Up @@ -889,7 +892,7 @@ func (s *state) updateNeonVMCurrentRevision(currentRevision vmv1.RevisionWithTim
revsource.Propagate(currentRevision.UpdatedAt.Time,
s.NeonVM.TargetRevision,
&s.NeonVM.CurrentRevision,
s.Config.PromMetricsCallbacks.NeonVMLatency,
s.Config.ObservabilityCallbacks.NeonVMLatency,
)
err := s.Config.RevisionSource.Observe(currentRevision.UpdatedAt.Time, currentRevision.Revision)
if err != nil {
Expand Down Expand Up @@ -1106,7 +1109,7 @@ func (h PluginHandle) RequestSuccessful(
revsource.Propagate(now,
targetRevision,
&h.s.Plugin.CurrentRevision,
h.s.Config.PromMetricsCallbacks.PluginLatency,
h.s.Config.ObservabilityCallbacks.PluginLatency,
)
return nil
}
Expand Down Expand Up @@ -1181,7 +1184,7 @@ func (h MonitorHandle) DownscaleRequestAllowed(now time.Time, rev vmv1.RevisionW
revsource.Propagate(now,
rev,
&h.s.Monitor.CurrentRevision,
h.s.Config.PromMetricsCallbacks.MonitorLatency,
h.s.Config.ObservabilityCallbacks.MonitorLatency,
)
}

Expand All @@ -1196,7 +1199,7 @@ func (h MonitorHandle) DownscaleRequestDenied(now time.Time, targetRevision vmv1
revsource.Propagate(now,
targetRevision,
&h.s.Monitor.CurrentRevision,
h.s.Config.PromMetricsCallbacks.MonitorLatency,
h.s.Config.ObservabilityCallbacks.MonitorLatency,
)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/agent/core/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func Test_DesiredResourcesFromMetricsOrRequestedUpscaling(t *testing.T) {
},
},
RevisionSource: revsource.NewRevisionSource(nil),
PromMetricsCallbacks: core.ObservabilityCallbacks{
ObservabilityCallbacks: core.ObservabilityCallbacks{
PluginLatency: nil,
MonitorLatency: nil,
NeonVMLatency: nil,
Expand Down Expand Up @@ -206,7 +206,7 @@ var DefaultInitialStateConfig = helpers.InitialStateConfig{
Warn: nil,
},
RevisionSource: &helpers.NilRevisionSource{},
PromMetricsCallbacks: core.ObservabilityCallbacks{
ObservabilityCallbacks: core.ObservabilityCallbacks{
PluginLatency: nil,
MonitorLatency: nil,
NeonVMLatency: nil,
Expand Down Expand Up @@ -503,7 +503,7 @@ func TestPeriodicPluginRequest(t *testing.T) {
DefaultInitialStateConfig,
helpers.WithStoredWarnings(a.StoredWarnings()),
helpers.WithConfigSetting(func(c *core.Config) {
c.PromMetricsCallbacks.PluginLatency = latencyObserver.observe
c.ObservabilityCallbacks.PluginLatency = latencyObserver.observe
// This time, we will test plugin latency
c.RevisionSource = revsource.NewRevisionSource(nil)
}),
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (r *Runner) Run(ctx context.Context, logger *zap.Logger, vmInfoUpdated util
Warn: coreExecLogger.Warn,
},
RevisionSource: revisionSource,
PromMetricsCallbacks: core.ObservabilityCallbacks{
ObservabilityCallbacks: core.ObservabilityCallbacks{
PluginLatency: WrapHistogramVec(&r.global.metrics.pluginLatency),
MonitorLatency: WrapHistogramVec(&r.global.metrics.monitorLatency),
NeonVMLatency: WrapHistogramVec(&r.global.metrics.neonvmLatency),
Expand Down

0 comments on commit 9b07933

Please sign in to comment.