-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We try to calculate state of EdgeNode and objects inside of it. We construct the state based on info and metric messages from the controller. Info and metric messages are great for debugging, but in case of long time work we may hit the problem where state calculation consume more and more time. Let's slightly refactor the state logic to be able to store it locally and reuse. Signed-off-by: Petr Fedchenkov <[email protected]>
- Loading branch information
Showing
13 changed files
with
371 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package eve | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/lf-edge/eden/pkg/controller" | ||
"github.com/lf-edge/eden/pkg/device" | ||
"github.com/lf-edge/eve/api/go/info" | ||
"github.com/lf-edge/eve/api/go/metrics" | ||
) | ||
|
||
// NodeState describes state of edge node | ||
type NodeState struct { | ||
UsedMem uint32 | ||
AvailMem uint32 | ||
UsedPercentageMem float64 | ||
|
||
LastRebootTime time.Time | ||
LastRebootReason string | ||
|
||
// interface to ip mapping | ||
RemoteIPs map[string][]string | ||
|
||
LastSeen time.Time | ||
|
||
Version string | ||
} | ||
|
||
func (ctx *State) initNodeState(_ controller.Cloud, _ *device.Ctx) error { | ||
ctx.EveState = &NodeState{} | ||
return nil | ||
} | ||
|
||
func (ctx *State) applyOldStateNodeState(state *State) { | ||
ctx.EveState = state.EveState | ||
} | ||
|
||
func (ctx *State) processNodeStateByInfo(msg *info.ZInfoMsg) { | ||
infoTime := msg.AtTimeStamp.AsTime() | ||
if infoTime.After(ctx.EveState.LastSeen) { | ||
ctx.EveState.LastSeen = infoTime | ||
} | ||
if deviceInfo := msg.GetDinfo(); deviceInfo != nil { | ||
ctx.EveState.RemoteIPs = make(map[string][]string) | ||
for _, nw := range deviceInfo.Network { | ||
ctx.EveState.RemoteIPs[nw.LocalName] = nw.IPAddrs | ||
} | ||
ctx.EveState.LastRebootTime = deviceInfo.LastRebootTime.AsTime() | ||
ctx.EveState.LastRebootReason = deviceInfo.LastRebootReason | ||
if len(deviceInfo.SwList) > 0 { | ||
ctx.EveState.Version = deviceInfo.SwList[0].ShortVersion | ||
} | ||
} | ||
} | ||
|
||
func (ctx *State) processNodeStateByMetric(msg *metrics.ZMetricMsg) { | ||
metricTime := msg.AtTimeStamp.AsTime() | ||
if metricTime.After(ctx.EveState.LastSeen) { | ||
ctx.EveState.LastSeen = metricTime | ||
} | ||
if deviceMetric := msg.GetDm(); deviceMetric != nil { | ||
ctx.EveState.AvailMem = deviceMetric.Memory.GetAvailMem() | ||
ctx.EveState.UsedMem = deviceMetric.Memory.GetUsedMem() | ||
ctx.EveState.UsedPercentageMem = deviceMetric.Memory.GetUsedPercentage() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.