Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makes uptimes and runtimes real #166

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions internal/agent-api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type AgentClient struct {
eventReceived EventCallback
logReceived LogCallback

execTotalNanos int64
workloadStartedAt time.Time

subz []*nats.Subscription
}

Expand Down Expand Up @@ -125,6 +128,7 @@ func (a *AgentClient) DeployWorkload(request *DeployRequest) (*DeployResponse, e
a.log.Error("Failed to deserialize deployment response", slog.Any("error", err))
return nil, err
}
a.workloadStartedAt = time.Now().UTC()
return &deployResponse, nil
}

Expand Down Expand Up @@ -162,6 +166,19 @@ func (a *AgentClient) Undeploy() error {
return nil
}

func (a *AgentClient) RecordExecTime(elapsedNanos int64) {
atomic.AddInt64(&a.execTotalNanos, elapsedNanos)
}

func (a *AgentClient) ExecTimeNanos() int64 {
return a.execTotalNanos
}

// Returns the time difference between now and when the agent started
func (a *AgentClient) UptimeMillis() time.Duration {
return time.Since(a.workloadStartedAt)
}

func (a *AgentClient) RunTrigger(ctx context.Context, tracer trace.Tracer, subject string, data []byte) (*nats.Msg, error) {
intmsg := nats.NewMsg(fmt.Sprintf("agentint.%s.trigger", a.agentID))
// TODO: inject tracer context into message header
Expand Down
34 changes: 0 additions & 34 deletions internal/node/controlapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,40 +353,6 @@ func summarizeMachines(workloads []controlapi.MachineSummary, namespace string)
return machines
}

// func summarizeMachines(vms *map[string]*runningFirecracker, namespace string) []controlapi.MachineSummary {
// machines := make([]controlapi.MachineSummary, 0)
// now := time.Now().UTC()
// for _, v := range *vms {
// if v.namespace == namespace {
// var desc string
// if v.deployRequest.Description != nil {
// desc = *v.deployRequest.Description // FIXME-- audit controlapi.WorkloadSummary
// }

// var workloadType string
// if v.deployRequest.WorkloadType != nil {
// workloadType = *v.deployRequest.WorkloadType
// }

// machine := controlapi.MachineSummary{
// Id: v.vmmID,
// Healthy: true, // TODO cache last health status
// Uptime: myUptime(now.Sub(v.machineStarted)),
// Workload: controlapi.WorkloadSummary{
// Name: v.deployRequest.DecodedClaims.Subject,
// Description: desc,
// Runtime: myUptime(now.Sub(v.workloadStarted)),
// WorkloadType: workloadType,
// //Hash: v.deployedWorkload.DecodedClaims.Data["hash"].(string),
// },
// }

// machines = append(machines, machine)
// }
// }
// return machines
// }

func validateIssuer(issuer string, validIssuers []string) bool {
if len(validIssuers) == 0 {
return true
Expand Down
29 changes: 27 additions & 2 deletions internal/node/workload_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,39 @@ func (w *WorkloadManager) RunningWorkloads() ([]controlapi.MachineSummary, error
summaries := make([]controlapi.MachineSummary, len(procs))

for i, p := range procs {
uptimeFriendly := "unknown"
autodidaddict marked this conversation as resolved.
Show resolved Hide resolved
runtimeFriendly := "unknown"
agentClient, ok := w.activeAgents[p.ID]
if ok {
uptimeFriendly = myUptime(agentClient.UptimeMillis())
if *p.DeployRequest.WorkloadType == "v8" || *p.DeployRequest.WorkloadType == "wasm" {
nanoTime := fmt.Sprintf("%dns", agentClient.ExecTimeNanos())
rt, err := time.ParseDuration(nanoTime)
if err == nil {
if rt.Nanoseconds() < 1000 {
runtimeFriendly = nanoTime
} else if rt.Milliseconds() < 1000 {
runtimeFriendly = fmt.Sprintf("%dms", rt.Milliseconds())
} else {
runtimeFriendly = myUptime(rt)
}
} else {
w.log.Warn("Failed to generate parsed time from nanos", slog.Any("error", err))
}
} else {
runtimeFriendly = uptimeFriendly
}
}

summaries[i] = controlapi.MachineSummary{
Id: p.ID,
Healthy: true,
Uptime: "TBD",
Uptime: uptimeFriendly,
Namespace: p.Namespace,
Workload: controlapi.WorkloadSummary{
Name: p.Name,
Description: *p.DeployRequest.WorkloadName,
Runtime: "TBD", // TODO: replace with function exec time OR service uptime
Runtime: runtimeFriendly,
WorkloadType: *p.DeployRequest.WorkloadType,
Hash: p.DeployRequest.Hash,
},
Expand Down Expand Up @@ -479,6 +503,7 @@ func (w *WorkloadManager) generateTriggerHandler(workloadID string, tsub string,
w.log.Warn("failed to log function runtime", slog.Any("err", err))
}
_ = w.publishFunctionExecSucceeded(workloadID, tsub, runTimeNs64)
agentClient.RecordExecTime(runTimeNs64)
parentSpan.AddEvent("published success event")

w.t.FunctionTriggers.Add(w.ctx, 1)
Expand Down
2 changes: 1 addition & 1 deletion nex/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func renderNodeInfo(info *controlapi.InfoResponse, id string) {
cols.Println()
cols.AddRow("Id", m.Id)
cols.AddRow("Healthy", m.Healthy)
cols.AddRow("Runtime", m.Uptime)
cols.AddRow("Runtime", m.Workload.Runtime)
cols.AddRow("Name", m.Workload.Name)
cols.AddRow("Description", m.Workload.Description)
}
Expand Down
Loading