Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit f73c0bd

Browse files
author
Dongsu Park
committed
schema,etc: add more fields for systemdActiveEnterTimestamp
* fix typo in registry/unit_state*.go, from ActiveEnterTimestamp to activeEnterTimestamp. * Add a new field systemdActiveEnterTimestamp to both v1-json.go and v1.json.
1 parent 46c9557 commit f73c0bd

6 files changed

Lines changed: 16 additions & 5 deletions

File tree

fleetctl/list_units.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package main
1717
import (
1818
"fmt"
1919
"sort"
20+
"strconv"
2021
"strings"
2122
"time"
2223

@@ -83,7 +84,8 @@ var (
8384
}
8485
// SystemdActiveEnterTimestamp is in microseconds, while time.Unix
8586
// requires the 2nd parameter as value in nanoseconds.
86-
tm := time.Unix(0, int64(us.SystemdActiveEnterTimestamp)*1000)
87+
ts, _ := strconv.Atoi(us.SystemdActiveEnterTimestamp)
88+
tm := time.Unix(0, int64(ts)*1000)
8789
duration := time.Now().Sub(tm)
8890
return fmt.Sprintf("%s, Since %ss", tm.Format(tmFormatString), strings.Split(duration.String(), ".")[0])
8991
},

registry/unit_state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ type unitStateModel struct {
244244
SubState string `json:"subState"`
245245
MachineState *machine.MachineState `json:"machineState"`
246246
UnitHash string `json:"unitHash"`
247-
ActiveEnterTimestamp uint64 `json:"ActiveEnterTimestamp"`
247+
ActiveEnterTimestamp uint64 `json:"activeEnterTimestamp"`
248248
}
249249

250250
func modelToUnitState(usm *unitStateModel, name string) *unit.UnitState {

registry/unit_state_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func TestSaveUnitState(t *testing.T) {
122122
us.UnitHash = "quickbrownfox"
123123
r.SaveUnitState(j, us, time.Second)
124124

125-
json := `{"loadState":"abc","activeState":"def","subState":"ghi","machineState":{"ID":"mymachine","PublicIP":"","Metadata":null,"Capabilities":null,"Version":""},"unitHash":"quickbrownfox","ActiveEnterTimestamp":1234567890}`
125+
json := `{"loadState":"abc","activeState":"def","subState":"ghi","machineState":{"ID":"mymachine","PublicIP":"","Metadata":null,"Capabilities":null,"Version":""},"unitHash":"quickbrownfox","activeEnterTimestamp":1234567890}`
126126
p1 := "/fleet/state/foo.service"
127127
p2 := "/fleet/states/foo.service/mymachine"
128128
want := []action{

schema/mapper.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package schema
1616

1717
import (
18+
"strconv"
19+
1820
gsunit "github.com/coreos/go-systemd/unit"
1921

2022
"github.com/coreos/fleet/job"
@@ -135,7 +137,7 @@ func MapUnitStateToSchemaUnitState(entity *unit.UnitState) *UnitState {
135137
SystemdLoadState: entity.LoadState,
136138
SystemdActiveState: entity.ActiveState,
137139
SystemdSubState: entity.SubState,
138-
SystemdActiveEnterTimestamp: entity.ActiveEnterTimestamp,
140+
SystemdActiveEnterTimestamp: strconv.Itoa(int(entity.ActiveEnterTimestamp)),
139141
}
140142

141143
return &us
@@ -144,14 +146,15 @@ func MapUnitStateToSchemaUnitState(entity *unit.UnitState) *UnitState {
144146
func MapSchemaUnitStatesToUnitStates(entities []*UnitState) []*unit.UnitState {
145147
us := make([]*unit.UnitState, len(entities))
146148
for i, e := range entities {
149+
ts, _ := strconv.Atoi(e.SystemdActiveEnterTimestamp)
147150
us[i] = &unit.UnitState{
148151
UnitName: e.Name,
149152
UnitHash: e.Hash,
150153
MachineID: e.MachineID,
151154
LoadState: e.SystemdLoadState,
152155
ActiveState: e.SystemdActiveState,
153156
SubState: e.SystemdSubState,
154-
ActiveEnterTimestamp: e.SystemdActiveEnterTimestamp,
157+
ActiveEnterTimestamp: uint64(ts),
155158
}
156159
}
157160

schema/v1-json.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ const DiscoveryJSON = `{
162162
},
163163
"systemdSubState": {
164164
"type": "string"
165+
},
166+
"systemdActiveEnterTimestamp": {
167+
"type": "string"
165168
}
166169
}
167170
},

schema/v1.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@
141141
},
142142
"systemdSubState": {
143143
"type": "string"
144+
},
145+
"systemdActiveEnterTimestamp": {
146+
"type": "string"
144147
}
145148
}
146149
},

0 commit comments

Comments
 (0)