Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.
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
8 changes: 6 additions & 2 deletions cmd/kubeless/function/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,13 @@ func printTop(w io.Writer, metrics []*utils.Metric, cli kubernetes.Interface, ou
table := uitable.New()
table.MaxColWidth = 50
table.Wrap = true
table.AddRow("NAME", "NAMESPACE", "METHOD", "TOTAL_CALLS", "TOTAL_FAILURES", "TOTAL_DURATION_SECONDS", "AVG_DURATION_SECONDS")
table.AddRow("NAME", "NAMESPACE", "METHOD", "TOTAL_CALLS", "TOTAL_FAILURES", "TOTAL_DURATION_SECONDS", "AVG_DURATION_SECONDS", "MESSAGE")
for _, f := range metrics {
table.AddRow(f.FunctionName, f.Namespace, f.Method, f.TotalCalls, f.TotalFailures, f.TotalDurationSeconds, f.AvgDurationSeconds)
if f.Message != "" {
table.AddRow(f.FunctionName, f.Namespace, "", "", "", "", "", f.Message)
} else {
table.AddRow(f.FunctionName, f.Namespace, f.Method, f.TotalCalls, f.TotalFailures, f.TotalDurationSeconds, f.AvgDurationSeconds, "")
}
}
fmt.Fprintln(w, table)
} else {
Expand Down
1 change: 1 addition & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ get-dotnetcore:

get-dotnetcore-verify:
kubeless function call get-dotnetcore |egrep hello.world
kubeless function top --function get-dotnetcore --out yaml |egrep "Function does not expose metrics"

get-dotnetcore-dependency:
kubeless function deploy get-dotnetcore-dependency --runtime dotnetcore2.0 --handler module.handler --from-file dotnetcore/dependency-yaml.cs --dependencies dotnetcore/dependency-yaml.csproj
Expand Down
17 changes: 15 additions & 2 deletions pkg/utils/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Metric struct {
FunctionName string `json:"function,omitempty"`
Namespace string `json:"namespace,omitempty"`
Method string `json:"method,omitempty"`
Message string `json:"message,omitempty"`
TotalCalls float64 `json:"total_calls,omitempty"`
TotalFailures float64 `json:"total_failures,omitempty"`
TotalDurationSeconds float64 `json:"total_duration_seconds,omitempty"`
Expand Down Expand Up @@ -116,12 +117,24 @@ func GetFunctionMetrics(apiV1Client kubernetes.Interface, h MetricsRetriever, na

res, err := h.GetRawMetrics(apiV1Client, namespace, functionName)
if err != nil {
return []*Metric{}
return []*Metric{
{
FunctionName: functionName,
Namespace: namespace,
Message: "Function does not expose metrics",
},
}
}

metrics, err := parseMetrics(namespace, functionName, res)
if err != nil {
return []*Metric{}
return []*Metric{
{
FunctionName: functionName,
Namespace: namespace,
Message: "Unable to get function metrics",
},
}
}
return metrics
}