2015-09-16 20:58:33 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-05-31 21:51:23 +00:00
|
|
|
"strings"
|
2015-09-16 20:58:33 +00:00
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/api"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2015-09-18 17:03:23 +00:00
|
|
|
// updateWait is the amount of time to wait between status
|
|
|
|
// updates. Because the monitor is poll-based, we use this
|
|
|
|
// delay to avoid overwhelming the API server.
|
|
|
|
updateWait = time.Second
|
2015-09-16 20:58:33 +00:00
|
|
|
)
|
|
|
|
|
2015-09-18 17:03:23 +00:00
|
|
|
// evalState is used to store the current "state of the world"
|
|
|
|
// in the context of monitoring an evaluation.
|
|
|
|
type evalState struct {
|
2017-07-07 02:55:58 +00:00
|
|
|
status string
|
|
|
|
desc string
|
|
|
|
node string
|
|
|
|
deployment string
|
|
|
|
job string
|
|
|
|
allocs map[string]*allocState
|
|
|
|
wait time.Duration
|
|
|
|
index uint64
|
2015-09-18 17:03:23 +00:00
|
|
|
}
|
|
|
|
|
2015-09-22 17:27:30 +00:00
|
|
|
// newEvalState creates and initializes a new monitorState
|
|
|
|
func newEvalState() *evalState {
|
|
|
|
return &evalState{
|
|
|
|
status: structs.EvalStatusPending,
|
|
|
|
allocs: make(map[string]*allocState),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-18 17:03:23 +00:00
|
|
|
// allocState is used to track the state of an allocation
|
|
|
|
type allocState struct {
|
|
|
|
id string
|
|
|
|
group string
|
|
|
|
node string
|
|
|
|
desired string
|
|
|
|
desiredDesc string
|
|
|
|
client string
|
2015-09-21 22:55:10 +00:00
|
|
|
clientDesc string
|
2015-09-18 17:03:23 +00:00
|
|
|
index uint64
|
|
|
|
}
|
|
|
|
|
2015-09-16 20:58:33 +00:00
|
|
|
// monitor wraps an evaluation monitor and holds metadata and
|
|
|
|
// state information.
|
|
|
|
type monitor struct {
|
|
|
|
ui cli.Ui
|
|
|
|
client *api.Client
|
2015-09-16 23:27:55 +00:00
|
|
|
state *evalState
|
2016-01-19 23:02:17 +00:00
|
|
|
|
|
|
|
// length determines the number of characters for identifiers in the ui.
|
2016-01-14 20:57:43 +00:00
|
|
|
length int
|
2015-09-16 20:58:33 +00:00
|
|
|
|
|
|
|
sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
// newMonitor returns a new monitor. The returned monitor will
|
2016-01-19 23:02:17 +00:00
|
|
|
// write output information to the provided ui. The length parameter determines
|
|
|
|
// the number of characters for identifiers in the ui.
|
2016-01-14 20:57:43 +00:00
|
|
|
func newMonitor(ui cli.Ui, client *api.Client, length int) *monitor {
|
2018-03-30 22:44:06 +00:00
|
|
|
if colorUi, ok := ui.(*cli.ColoredUi); ok {
|
|
|
|
// Disable Info color for monitored output
|
|
|
|
ui = &cli.ColoredUi{
|
|
|
|
ErrorColor: colorUi.ErrorColor,
|
|
|
|
WarnColor: colorUi.WarnColor,
|
|
|
|
InfoColor: cli.UiColorNone,
|
|
|
|
Ui: colorUi.Ui,
|
|
|
|
}
|
|
|
|
}
|
2015-09-18 17:03:23 +00:00
|
|
|
mon := &monitor{
|
2015-09-17 00:36:14 +00:00
|
|
|
ui: &cli.PrefixedUi{
|
|
|
|
InfoPrefix: "==> ",
|
|
|
|
OutputPrefix: " ",
|
|
|
|
ErrorPrefix: "==> ",
|
|
|
|
Ui: ui,
|
|
|
|
},
|
2015-09-16 20:58:33 +00:00
|
|
|
client: client,
|
2015-09-22 17:27:30 +00:00
|
|
|
state: newEvalState(),
|
2016-01-14 20:57:43 +00:00
|
|
|
length: length,
|
2015-09-16 20:58:33 +00:00
|
|
|
}
|
2015-09-18 17:03:23 +00:00
|
|
|
return mon
|
2015-09-16 20:58:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// update is used to update our monitor with new state. It can be
|
|
|
|
// called whether the passed information is new or not, and will
|
|
|
|
// only dump update messages when state changes.
|
2015-09-21 18:25:22 +00:00
|
|
|
func (m *monitor) update(update *evalState) {
|
2015-09-16 20:58:33 +00:00
|
|
|
m.Lock()
|
|
|
|
defer m.Unlock()
|
|
|
|
|
|
|
|
existing := m.state
|
|
|
|
|
2015-09-21 18:25:22 +00:00
|
|
|
// Swap in the new state at the end
|
|
|
|
defer func() {
|
|
|
|
m.state = update
|
|
|
|
}()
|
2015-09-16 20:58:33 +00:00
|
|
|
|
2015-09-21 22:55:10 +00:00
|
|
|
// Check if the evaluation was triggered by a node
|
|
|
|
if existing.node == "" && update.node != "" {
|
|
|
|
m.ui.Output(fmt.Sprintf("Evaluation triggered by node %q",
|
2016-01-27 18:42:10 +00:00
|
|
|
limit(update.node, m.length)))
|
2015-09-21 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the evaluation was triggered by a job
|
|
|
|
if existing.job == "" && update.job != "" {
|
|
|
|
m.ui.Output(fmt.Sprintf("Evaluation triggered by job %q", update.job))
|
|
|
|
}
|
|
|
|
|
2017-07-07 02:55:58 +00:00
|
|
|
// Check if the evaluation was triggered by a deployment
|
|
|
|
if existing.deployment == "" && update.deployment != "" {
|
|
|
|
m.ui.Output(fmt.Sprintf("Evaluation within deployment: %q", limit(update.deployment, m.length)))
|
|
|
|
}
|
|
|
|
|
2015-09-16 21:45:21 +00:00
|
|
|
// Check the allocations
|
|
|
|
for allocID, alloc := range update.allocs {
|
2015-09-16 22:37:08 +00:00
|
|
|
if existing, ok := existing.allocs[allocID]; !ok {
|
2015-09-18 03:18:33 +00:00
|
|
|
switch {
|
|
|
|
case alloc.index < update.index:
|
|
|
|
// New alloc with create index lower than the eval
|
|
|
|
// create index indicates modification
|
2015-09-18 17:03:23 +00:00
|
|
|
m.ui.Output(fmt.Sprintf(
|
2015-09-18 03:18:33 +00:00
|
|
|
"Allocation %q modified: node %q, group %q",
|
2016-01-27 18:42:10 +00:00
|
|
|
limit(alloc.id, m.length), limit(alloc.node, m.length), alloc.group))
|
2015-09-18 03:18:33 +00:00
|
|
|
|
|
|
|
case alloc.desired == structs.AllocDesiredStatusRun:
|
|
|
|
// New allocation with desired status running
|
2015-09-18 17:03:23 +00:00
|
|
|
m.ui.Output(fmt.Sprintf(
|
2015-09-18 03:18:33 +00:00
|
|
|
"Allocation %q created: node %q, group %q",
|
2016-01-27 18:42:10 +00:00
|
|
|
limit(alloc.id, m.length), limit(alloc.node, m.length), alloc.group))
|
2015-09-16 22:37:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-09-18 03:18:33 +00:00
|
|
|
switch {
|
|
|
|
case existing.client != alloc.client:
|
2016-05-25 01:42:05 +00:00
|
|
|
description := ""
|
|
|
|
if alloc.clientDesc != "" {
|
|
|
|
description = fmt.Sprintf(" (%s)", alloc.clientDesc)
|
|
|
|
}
|
2015-09-18 03:18:33 +00:00
|
|
|
// Allocation status has changed
|
2015-09-18 17:03:23 +00:00
|
|
|
m.ui.Output(fmt.Sprintf(
|
2016-05-25 01:42:05 +00:00
|
|
|
"Allocation %q status changed: %q -> %q%s",
|
|
|
|
limit(alloc.id, m.length), existing.client, alloc.client, description))
|
2015-09-16 21:45:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-21 19:53:48 +00:00
|
|
|
// Check if the status changed. We skip any transitions to pending status.
|
|
|
|
if existing.status != "" &&
|
|
|
|
update.status != structs.AllocClientStatusPending &&
|
|
|
|
existing.status != update.status {
|
2015-09-18 17:03:23 +00:00
|
|
|
m.ui.Output(fmt.Sprintf("Evaluation status changed: %q -> %q",
|
2015-09-21 18:25:22 +00:00
|
|
|
existing.status, update.status))
|
2015-09-16 20:58:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// monitor is used to start monitoring the given evaluation ID. It
|
|
|
|
// writes output directly to the monitor's ui, and returns the
|
2016-01-07 23:43:30 +00:00
|
|
|
// exit code for the command. If allowPrefix is false, monitor will only accept
|
|
|
|
// exact matching evalIDs.
|
2015-09-21 19:19:34 +00:00
|
|
|
//
|
|
|
|
// The return code will be 0 on successful evaluation. If there are
|
|
|
|
// problems scheduling the job (impossible constraints, resources
|
|
|
|
// exhausted, etc), then the return code will be 2. For any other
|
|
|
|
// failures (API connectivity, internal errors, etc), the return code
|
|
|
|
// will be 1.
|
2016-01-07 23:25:08 +00:00
|
|
|
func (m *monitor) monitor(evalID string, allowPrefix bool) int {
|
2015-09-21 19:19:34 +00:00
|
|
|
// Track if we encounter a scheduling failure. This can only be
|
|
|
|
// detected while querying allocations, so we use this bool to
|
|
|
|
// carry that status into the return code.
|
|
|
|
var schedFailure bool
|
|
|
|
|
2016-01-14 20:57:43 +00:00
|
|
|
// The user may have specified a prefix as eval id. We need to lookup the
|
|
|
|
// full id from the database first. Since we do this in a loop we need a
|
|
|
|
// variable to keep track if we've already written the header message.
|
|
|
|
var headerWritten bool
|
|
|
|
|
2015-09-22 17:27:30 +00:00
|
|
|
// Add the initial pending state
|
|
|
|
m.update(newEvalState())
|
|
|
|
|
2015-09-16 20:58:33 +00:00
|
|
|
for {
|
2015-09-16 23:27:55 +00:00
|
|
|
// Query the evaluation
|
2015-09-16 20:58:33 +00:00
|
|
|
eval, _, err := m.client.Evaluations().Info(evalID, nil)
|
|
|
|
if err != nil {
|
2016-01-07 23:25:08 +00:00
|
|
|
if !allowPrefix {
|
|
|
|
m.ui.Error(fmt.Sprintf("No evaluation with id %q found", evalID))
|
|
|
|
return 1
|
|
|
|
}
|
2016-01-21 21:21:35 +00:00
|
|
|
if len(evalID) == 1 {
|
|
|
|
m.ui.Error(fmt.Sprintf("Identifier must contain at least two characters."))
|
2016-01-21 19:53:05 +00:00
|
|
|
return 1
|
|
|
|
}
|
2016-01-07 23:25:08 +00:00
|
|
|
|
2018-03-11 18:52:59 +00:00
|
|
|
evalID = sanitizeUUIDPrefix(evalID)
|
2015-12-24 10:46:59 +00:00
|
|
|
evals, _, err := m.client.Evaluations().PrefixList(evalID)
|
|
|
|
if err != nil {
|
|
|
|
m.ui.Error(fmt.Sprintf("Error reading evaluation: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
if len(evals) == 0 {
|
|
|
|
m.ui.Error(fmt.Sprintf("No evaluation(s) with prefix or id %q found", evalID))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
if len(evals) > 1 {
|
|
|
|
// Format the evaluations
|
|
|
|
out := make([]string, len(evals)+1)
|
2016-01-21 20:35:56 +00:00
|
|
|
out[0] = "ID|Priority|Type|Triggered By|Status"
|
2015-12-24 10:46:59 +00:00
|
|
|
for i, eval := range evals {
|
|
|
|
out[i+1] = fmt.Sprintf("%s|%d|%s|%s|%s",
|
2016-01-27 18:42:10 +00:00
|
|
|
limit(eval.ID, m.length),
|
2015-12-24 10:46:59 +00:00
|
|
|
eval.Priority,
|
|
|
|
eval.Type,
|
|
|
|
eval.TriggeredBy,
|
|
|
|
eval.Status)
|
|
|
|
}
|
2016-01-06 23:08:47 +00:00
|
|
|
m.ui.Output(fmt.Sprintf("Prefix matched multiple evaluations\n\n%s", formatList(out)))
|
2015-12-24 10:46:59 +00:00
|
|
|
return 0
|
|
|
|
}
|
2016-01-06 21:46:57 +00:00
|
|
|
// Prefix lookup matched a single evaluation
|
2015-12-24 10:46:59 +00:00
|
|
|
eval, _, err = m.client.Evaluations().Info(evals[0].ID, nil)
|
|
|
|
if err != nil {
|
|
|
|
m.ui.Error(fmt.Sprintf("Error reading evaluation: %s", err))
|
|
|
|
}
|
2015-09-16 20:58:33 +00:00
|
|
|
}
|
|
|
|
|
2016-01-14 20:57:43 +00:00
|
|
|
if !headerWritten {
|
2016-01-27 18:42:10 +00:00
|
|
|
m.ui.Info(fmt.Sprintf("Monitoring evaluation %q", limit(eval.ID, m.length)))
|
2016-01-14 20:57:43 +00:00
|
|
|
headerWritten = true
|
|
|
|
}
|
|
|
|
|
2015-09-21 18:25:22 +00:00
|
|
|
// Create the new eval state.
|
2015-09-22 17:27:30 +00:00
|
|
|
state := newEvalState()
|
|
|
|
state.status = eval.Status
|
|
|
|
state.desc = eval.StatusDescription
|
|
|
|
state.node = eval.NodeID
|
|
|
|
state.job = eval.JobID
|
2017-07-07 02:55:58 +00:00
|
|
|
state.deployment = eval.DeploymentID
|
2015-09-22 17:27:30 +00:00
|
|
|
state.wait = eval.Wait
|
|
|
|
state.index = eval.CreateIndex
|
2015-09-21 18:25:22 +00:00
|
|
|
|
2015-09-16 23:27:55 +00:00
|
|
|
// Query the allocations associated with the evaluation
|
2015-12-19 20:05:17 +00:00
|
|
|
allocs, _, err := m.client.Evaluations().Allocations(eval.ID, nil)
|
2015-09-16 21:45:21 +00:00
|
|
|
if err != nil {
|
|
|
|
m.ui.Error(fmt.Sprintf("Error reading allocations: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2015-09-21 18:25:22 +00:00
|
|
|
// Add the allocs to the state
|
|
|
|
for _, alloc := range allocs {
|
|
|
|
state.allocs[alloc.ID] = &allocState{
|
|
|
|
id: alloc.ID,
|
|
|
|
group: alloc.TaskGroup,
|
|
|
|
node: alloc.NodeID,
|
|
|
|
desired: alloc.DesiredStatus,
|
|
|
|
desiredDesc: alloc.DesiredDescription,
|
|
|
|
client: alloc.ClientStatus,
|
2015-09-21 22:55:10 +00:00
|
|
|
clientDesc: alloc.ClientDescription,
|
2015-09-21 18:25:22 +00:00
|
|
|
index: alloc.CreateIndex,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-16 20:58:33 +00:00
|
|
|
// Update the state
|
2015-09-21 18:25:22 +00:00
|
|
|
m.update(state)
|
2015-09-16 21:45:21 +00:00
|
|
|
|
|
|
|
switch eval.Status {
|
2016-05-19 05:02:51 +00:00
|
|
|
case structs.EvalStatusComplete, structs.EvalStatusFailed, structs.EvalStatusCancelled:
|
|
|
|
if len(eval.FailedTGAllocs) == 0 {
|
|
|
|
m.ui.Info(fmt.Sprintf("Evaluation %q finished with status %q",
|
|
|
|
limit(eval.ID, m.length), eval.Status))
|
|
|
|
} else {
|
|
|
|
// There were failures making the allocations
|
2016-05-25 01:42:05 +00:00
|
|
|
schedFailure = true
|
2016-05-19 05:02:51 +00:00
|
|
|
m.ui.Info(fmt.Sprintf("Evaluation %q finished with status %q but failed to place all allocations:",
|
|
|
|
limit(eval.ID, m.length), eval.Status))
|
|
|
|
|
|
|
|
// Print the failures per task group
|
|
|
|
for tg, metrics := range eval.FailedTGAllocs {
|
|
|
|
noun := "allocation"
|
|
|
|
if metrics.CoalescedFailures > 0 {
|
|
|
|
noun += "s"
|
|
|
|
}
|
|
|
|
m.ui.Output(fmt.Sprintf("Task Group %q (failed to place %d %s):", tg, metrics.CoalescedFailures+1, noun))
|
2016-05-31 21:51:23 +00:00
|
|
|
metrics := formatAllocMetrics(metrics, false, " ")
|
|
|
|
for _, line := range strings.Split(metrics, "\n") {
|
|
|
|
m.ui.Output(line)
|
|
|
|
}
|
2016-05-19 05:02:51 +00:00
|
|
|
}
|
2016-05-19 20:16:10 +00:00
|
|
|
|
2016-05-25 01:12:59 +00:00
|
|
|
if eval.BlockedEval != "" {
|
|
|
|
m.ui.Output(fmt.Sprintf("Evaluation %q waiting for additional capacity to place remainder",
|
|
|
|
limit(eval.BlockedEval, m.length)))
|
2016-05-19 20:16:10 +00:00
|
|
|
}
|
2016-05-19 05:02:51 +00:00
|
|
|
}
|
2015-09-16 21:45:21 +00:00
|
|
|
default:
|
|
|
|
// Wait for the next update
|
2015-09-18 17:03:23 +00:00
|
|
|
time.Sleep(updateWait)
|
2015-09-16 21:45:21 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2015-09-21 22:55:10 +00:00
|
|
|
// Monitor the next eval in the chain, if present
|
2015-09-16 21:45:21 +00:00
|
|
|
if eval.NextEval != "" {
|
2016-02-07 00:09:39 +00:00
|
|
|
if eval.Wait.Nanoseconds() != 0 {
|
|
|
|
m.ui.Info(fmt.Sprintf(
|
|
|
|
"Monitoring next evaluation %q in %s",
|
|
|
|
limit(eval.NextEval, m.length), eval.Wait))
|
2015-09-21 22:55:10 +00:00
|
|
|
|
2016-02-07 00:09:39 +00:00
|
|
|
// Skip some unnecessary polling
|
|
|
|
time.Sleep(eval.Wait)
|
|
|
|
}
|
2015-09-21 22:55:10 +00:00
|
|
|
|
2015-09-22 17:27:30 +00:00
|
|
|
// Reset the state and monitor the new eval
|
|
|
|
m.state = newEvalState()
|
2016-01-07 23:25:08 +00:00
|
|
|
return m.monitor(eval.NextEval, allowPrefix)
|
2015-09-16 21:45:21 +00:00
|
|
|
}
|
2015-09-16 23:20:19 +00:00
|
|
|
break
|
2015-09-16 20:58:33 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 19:19:34 +00:00
|
|
|
// Treat scheduling failures specially using a dedicated exit code.
|
|
|
|
// This makes it easier to detect failures from the CLI.
|
|
|
|
if schedFailure {
|
|
|
|
return 2
|
|
|
|
}
|
|
|
|
|
2015-09-16 20:58:33 +00:00
|
|
|
return 0
|
|
|
|
}
|
2015-09-21 19:31:06 +00:00
|
|
|
|
2016-05-31 21:51:23 +00:00
|
|
|
func formatAllocMetrics(metrics *api.AllocationMetric, scores bool, prefix string) string {
|
2015-09-21 23:20:50 +00:00
|
|
|
// Print a helpful message if we have an eligibility problem
|
2016-05-31 21:51:23 +00:00
|
|
|
var out string
|
2016-05-19 05:02:51 +00:00
|
|
|
if metrics.NodesEvaluated == 0 {
|
2016-05-31 21:51:23 +00:00
|
|
|
out += fmt.Sprintf("%s* No nodes were eligible for evaluation\n", prefix)
|
2015-09-21 23:20:50 +00:00
|
|
|
}
|
|
|
|
|
2016-01-04 22:23:06 +00:00
|
|
|
// Print a helpful message if the user has asked for a DC that has no
|
|
|
|
// available nodes.
|
2016-05-19 05:02:51 +00:00
|
|
|
for dc, available := range metrics.NodesAvailable {
|
2016-01-04 22:23:06 +00:00
|
|
|
if available == 0 {
|
2016-05-31 21:51:23 +00:00
|
|
|
out += fmt.Sprintf("%s* No nodes are available in datacenter %q\n", prefix, dc)
|
2016-01-04 22:23:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-21 22:55:10 +00:00
|
|
|
// Print filter info
|
2016-05-19 05:02:51 +00:00
|
|
|
for class, num := range metrics.ClassFiltered {
|
2016-05-31 21:51:23 +00:00
|
|
|
out += fmt.Sprintf("%s* Class %q filtered %d nodes\n", prefix, class, num)
|
2015-09-21 22:55:10 +00:00
|
|
|
}
|
2016-05-19 05:02:51 +00:00
|
|
|
for cs, num := range metrics.ConstraintFiltered {
|
2016-05-31 21:51:23 +00:00
|
|
|
out += fmt.Sprintf("%s* Constraint %q filtered %d nodes\n", prefix, cs, num)
|
2015-09-21 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 19:31:06 +00:00
|
|
|
// Print exhaustion info
|
2016-05-19 05:02:51 +00:00
|
|
|
if ne := metrics.NodesExhausted; ne > 0 {
|
2016-05-31 21:51:23 +00:00
|
|
|
out += fmt.Sprintf("%s* Resources exhausted on %d nodes\n", prefix, ne)
|
2015-09-21 19:31:06 +00:00
|
|
|
}
|
2016-05-19 05:02:51 +00:00
|
|
|
for class, num := range metrics.ClassExhausted {
|
2016-05-31 21:51:23 +00:00
|
|
|
out += fmt.Sprintf("%s* Class %q exhausted on %d nodes\n", prefix, class, num)
|
2015-09-21 19:31:06 +00:00
|
|
|
}
|
2016-05-19 05:02:51 +00:00
|
|
|
for dim, num := range metrics.DimensionExhausted {
|
2016-05-31 21:51:23 +00:00
|
|
|
out += fmt.Sprintf("%s* Dimension %q exhausted on %d nodes\n", prefix, dim, num)
|
2015-09-21 19:31:06 +00:00
|
|
|
}
|
2015-09-27 20:59:27 +00:00
|
|
|
|
2017-10-13 21:36:02 +00:00
|
|
|
// Print quota info
|
|
|
|
for _, dim := range metrics.QuotaExhausted {
|
|
|
|
out += fmt.Sprintf("%s* Quota limit hit %q\n", prefix, dim)
|
|
|
|
}
|
|
|
|
|
2015-09-27 20:59:27 +00:00
|
|
|
// Print scores
|
2016-05-19 05:02:51 +00:00
|
|
|
if scores {
|
2018-08-08 14:41:56 +00:00
|
|
|
if len(metrics.ScoreMetaData) > 0 {
|
2018-08-17 23:44:00 +00:00
|
|
|
scoreOutput := make([]string, len(metrics.ScoreMetaData)+1)
|
|
|
|
|
|
|
|
for i, scoreMeta := range metrics.ScoreMetaData {
|
|
|
|
// Add header as first row
|
|
|
|
if i == 0 {
|
|
|
|
scoreOutput[0] = "Node|"
|
2018-08-18 01:34:38 +00:00
|
|
|
for scorerName := range scoreMeta.Scores {
|
2018-08-17 23:44:00 +00:00
|
|
|
scoreOutput[0] += fmt.Sprintf("%v|", scorerName)
|
|
|
|
}
|
|
|
|
scoreOutput[0] += "Final Score"
|
|
|
|
}
|
|
|
|
scoreOutput[i+1] = fmt.Sprintf("%v|", scoreMeta.NodeID)
|
|
|
|
for _, scoreVal := range scoreMeta.Scores {
|
|
|
|
scoreOutput[i+1] += fmt.Sprintf("%v|", scoreVal)
|
2018-08-08 14:41:56 +00:00
|
|
|
}
|
2018-08-17 23:44:00 +00:00
|
|
|
scoreOutput[i+1] += fmt.Sprintf("%v", scoreMeta.NormScore)
|
2018-08-08 14:41:56 +00:00
|
|
|
}
|
2018-08-17 23:44:00 +00:00
|
|
|
out += formatList(scoreOutput)
|
2018-08-08 14:41:56 +00:00
|
|
|
} else {
|
|
|
|
// Backwards compatibility for old allocs
|
|
|
|
for name, score := range metrics.Scores {
|
|
|
|
out += fmt.Sprintf("%s* Score %q = %f\n", prefix, name, score)
|
|
|
|
}
|
2016-05-19 05:02:51 +00:00
|
|
|
}
|
2015-09-27 20:59:27 +00:00
|
|
|
}
|
2016-05-31 21:51:23 +00:00
|
|
|
|
|
|
|
out = strings.TrimSuffix(out, "\n")
|
|
|
|
return out
|
2015-09-21 19:31:06 +00:00
|
|
|
}
|