Skip to content

Commit 68abcc5

Browse files
committed
add StartTIme in one more place
1 parent d8ca1fb commit 68abcc5

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

internal/pkg/agent/application/coordinator/coordinator_state.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ func (c *Coordinator) applyComponentState(state runtime.ComponentComponentState)
157157
for i, other := range c.state.Components {
158158
// We want to update the component state if the incoming update is from the same instance or a newer instance of the component.
159159
// We determine this by comparing start times, since a newer instance would have a later start time.
160-
if other.Component.ID == state.Component.ID && (other.Component.StartTime <= state.Component.StartTime) {
160+
if other.Component.ID == state.Component.ID && (other.Component.StartTime.UnixNano() <= state.Component.StartTime.UnixNano()) {
161161
if other.State.Pid != state.State.Pid {
162162
c.componentPidRequiresUpdate.Store(true)
163163
}
164164
c.state.Components[i] = state
165165
found = true
166166
break
167-
} else if other.Component.ID == state.Component.ID && other.Component.StartTime > state.Component.StartTime {
167+
} else if other.Component.ID == state.Component.ID && other.Component.StartTime.UnixNano() > state.Component.StartTime.UnixNano() {
168168
// This is a case where a component has transitioned to a new state but we receive a late update from the older component.
169169
ignore = true
170170
break

internal/pkg/agent/application/coordinator/coordinator_state_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ func TestApplyComponentState_LateStoppedFromDifferentRuntimeIgnored(t *testing.T
2424
comp1 := pkgcomponent.Component{
2525
ID: "filestream-default",
2626
RuntimeManager: pkgcomponent.OtelRuntimeManager,
27-
StartTime: time.Now().UnixNano(),
27+
StartTime: time.Now(),
2828
}
2929
comp2 := pkgcomponent.Component{
3030
ID: "system/metrics-default",
3131
RuntimeManager: pkgcomponent.OtelRuntimeManager,
32-
StartTime: time.Now().UnixNano(),
32+
StartTime: time.Now(),
3333
}
3434
coord := &Coordinator{
3535
state: State{
@@ -69,12 +69,12 @@ func TestApplyComponentState_LateStoppedFromDifferentRuntimeIgnored(t *testing.T
6969
comp1New := pkgcomponent.Component{
7070
ID: "filestream-default",
7171
RuntimeManager: pkgcomponent.ProcessRuntimeManager,
72-
StartTime: time.Now().UnixNano(),
72+
StartTime: time.Now(),
7373
}
7474
comp2New := pkgcomponent.Component{
7575
ID: "system/metrics-default",
7676
RuntimeManager: pkgcomponent.ProcessRuntimeManager,
77-
StartTime: time.Now().UnixNano(),
77+
StartTime: time.Now(),
7878
}
7979

8080
coord.applyComponentState(runtime.ComponentComponentState{
@@ -203,7 +203,7 @@ func TestApplyComponentState_StartingFromNewRuntimeReplacesExisting(t *testing.T
203203
Component: pkgcomponent.Component{
204204
ID: "filestream-default",
205205
RuntimeManager: pkgcomponent.OtelRuntimeManager,
206-
StartTime: time.Now().Unix(),
206+
StartTime: time.Now(),
207207
},
208208
State: runtime.ComponentState{
209209
State: client.UnitStateHealthy,
@@ -217,7 +217,7 @@ func TestApplyComponentState_StartingFromNewRuntimeReplacesExisting(t *testing.T
217217
Component: pkgcomponent.Component{
218218
ID: "filestream-default",
219219
RuntimeManager: pkgcomponent.ProcessRuntimeManager,
220-
StartTime: time.Now().Unix(),
220+
StartTime: time.Now(),
221221
},
222222
State: runtime.ComponentState{
223223
State: client.UnitStateStarting,

pkg/component/component.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ type Component struct {
300300

301301
OutputStatusReporting *StatusReporting `yaml:"-"`
302302

303-
StartTime int64 `yaml:"-"`
303+
// StartTime is the time when the component was first created. The value is in nanoseconds since the Unix epoch.
304+
StartTime time.Time `yaml:"-"`
304305
}
305306

306307
type StatusReporting struct {
@@ -640,7 +641,7 @@ func (r *RuntimeSpecs) componentsForInputType(
640641
Features: featureFlags.AsProto(),
641642
Component: componentConfig.AsProto(),
642643
OutputStatusReporting: extractStatusReporting(output.Config),
643-
StartTime: time.Now().Unix(),
644+
StartTime: time.Now(),
644645
})
645646
}
646647
}
@@ -687,6 +688,7 @@ func (r *RuntimeSpecs) componentsForInputType(
687688
Features: featureFlags.AsProto(),
688689
Component: componentConfig.AsProto(),
689690
OutputStatusReporting: extractStatusReporting(output.Config),
691+
StartTime: time.Now(),
690692
})
691693
}
692694
}

0 commit comments

Comments
 (0)