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

Commit b654e92

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 b654e92

File tree

7 files changed

+22
-11
lines changed

7 files changed

+22
-11
lines changed

api/state_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ func TestUnitStateList(t *testing.T) {
3333
us2 := unit.UnitState{UnitName: "BBB", ActiveState: "inactive", MachineID: "XXX"}
3434
us3 := unit.UnitState{UnitName: "CCC", ActiveState: "active", MachineID: "XXX"}
3535
us4 := unit.UnitState{UnitName: "CCC", ActiveState: "inactive", MachineID: "YYY"}
36-
sus1 := &schema.UnitState{Name: "AAA", SystemdActiveState: "active"}
37-
sus2 := &schema.UnitState{Name: "BBB", SystemdActiveState: "inactive", MachineID: "XXX"}
38-
sus3 := &schema.UnitState{Name: "CCC", SystemdActiveState: "active", MachineID: "XXX"}
39-
sus4 := &schema.UnitState{Name: "CCC", SystemdActiveState: "inactive", MachineID: "YYY"}
36+
sus1 := &schema.UnitState{Name: "AAA", SystemdActiveState: "active", SystemdActiveEnterTimestamp: "0"}
37+
sus2 := &schema.UnitState{Name: "BBB", SystemdActiveState: "inactive", MachineID: "XXX", SystemdActiveEnterTimestamp: "0"}
38+
sus3 := &schema.UnitState{Name: "CCC", SystemdActiveState: "active", MachineID: "XXX", SystemdActiveEnterTimestamp: "0"}
39+
sus4 := &schema.UnitState{Name: "CCC", SystemdActiveState: "inactive", MachineID: "YYY", SystemdActiveEnterTimestamp: "0"}
4040

4141
for i, tt := range []struct {
4242
url string
@@ -163,12 +163,12 @@ func TestUnitStateList(t *testing.T) {
163163
return
164164
}
165165

166-
expect1 := &schema.UnitState{Name: "XXX", SystemdActiveState: "active"}
166+
expect1 := &schema.UnitState{Name: "XXX", SystemdActiveState: "active", SystemdActiveEnterTimestamp: "0"}
167167
if !reflect.DeepEqual(expect1, page.States[0]) {
168168
t.Errorf("expected first entity %#v, got %#v", expect1, page.States[0])
169169
}
170170

171-
expect2 := &schema.UnitState{Name: "YYY", SystemdActiveState: "inactive"}
171+
expect2 := &schema.UnitState{Name: "YYY", SystemdActiveState: "inactive", SystemdActiveEnterTimestamp: "0"}
172172
if !reflect.DeepEqual(expect2, page.States[1]) {
173173
t.Errorf("expected first entity %#v, got %#v", expect2, page.States[1])
174174
}

fleetctl/list_units.go

+3-1
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

+1-1
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

+1-1
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

+5-2
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

+3
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

+3
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)