Add HTTP method to Top display in the CLI and Web UI (#1709)

* Add Method column to Top tables in Web UI

* Add method to CLI top table
This commit is contained in:
Risha Mars 2018-09-25 11:15:11 -07:00 committed by GitHub
parent 6def3e22e9
commit 427078844d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 9 deletions

View File

@ -51,6 +51,7 @@ func (id topRequestID) String() string {
type tableRow struct {
by string
method string
source string
destination string
count int
@ -64,8 +65,8 @@ type tableRow struct {
const headerHeight = 3
var (
columnNames = []string{"Source", "Destination", "Path", "Count", "Best", "Worst", "Last", "Success Rate"}
columnWidths = []int{23, 23, 55, 6, 6, 6, 6, 3}
columnNames = []string{"Source", "Destination", "Method", "Path", "Count", "Best", "Worst", "Last", "Success Rate"}
columnWidths = []int{23, 23, 10, 37, 6, 6, 6, 6, 3}
)
func newTopOptions() *topOptions {
@ -259,6 +260,7 @@ func renderTable(requestCh <-chan topRequest, done <-chan struct{}, withSource b
func tableInsert(table *[]tableRow, req topRequest, withSource bool) {
by := req.reqInit.GetPath()
method := req.reqInit.GetMethod().GetRegistered().String()
source := stripPort(addr.PublicAddressToString(req.event.GetSource()))
if pod := req.event.SourceMeta.Labels["pod"]; pod != "" {
source = pod
@ -286,7 +288,7 @@ func tableInsert(table *[]tableRow, req topRequest, withSource bool) {
found := false
for i, row := range *table {
if row.by == by && row.destination == destination && (row.source == source || !withSource) {
if row.by == by && row.method == method && row.destination == destination && (row.source == source || !withSource) {
(*table)[i].count++
if latency.Nanoseconds() < row.best.Nanoseconds() {
(*table)[i].best = latency
@ -314,6 +316,7 @@ func tableInsert(table *[]tableRow, req topRequest, withSource bool) {
}
row := tableRow{
by: by,
method: method,
source: source,
destination: destination,
count: 1,
@ -357,16 +360,18 @@ func renderTableBody(table *[]tableRow, withSource bool) {
}
tbprint(x, i+headerHeight, row.destination)
x += columnWidths[1] + 1
tbprint(x, i+headerHeight, row.by)
tbprint(x, i+headerHeight, row.method)
x += columnWidths[2] + 1
tbprint(x, i+headerHeight, strconv.Itoa(row.count))
tbprint(x, i+headerHeight, row.by)
x += columnWidths[3] + 1
tbprint(x, i+headerHeight, formatDuration(row.best))
tbprint(x, i+headerHeight, strconv.Itoa(row.count))
x += columnWidths[4] + 1
tbprint(x, i+headerHeight, formatDuration(row.worst))
tbprint(x, i+headerHeight, formatDuration(row.best))
x += columnWidths[5] + 1
tbprint(x, i+headerHeight, formatDuration(row.last))
tbprint(x, i+headerHeight, formatDuration(row.worst))
x += columnWidths[6] + 1
tbprint(x, i+headerHeight, formatDuration(row.last))
x += columnWidths[7] + 1
successRate := fmt.Sprintf("%.2f%%", 100.0*float32(row.successes)/float32(row.successes+row.failures))
tbprint(x, i+headerHeight, successRate)
}

View File

@ -21,6 +21,12 @@ const topColumns = (resourceType, ResourceLink, PrefixedLink) => [
width: "180px",
render: d => srcDstColumn(d, resourceType, ResourceLink)
},
{
title: "Method",
dataIndex: "httpMethod",
width: "95px",
sorter: (a, b) => a.httpMethod.localeCompare(b.httpMethod),
},
{
title: "Path",
dataIndex: "path",

View File

@ -130,7 +130,7 @@ class TopModule extends React.Component {
let sourceKey = event.source.owner || event.source.pod || event.source.str;
let dstKey = event.destination.owner || event.destination.pod || event.destination.str;
return [sourceKey, dstKey, event.http.requestInit.path].join("_");
return [sourceKey, dstKey, _.get(event, "http.requestInit.method.registered"), event.http.requestInit.path].join("_");
}
initialTopResult(d, eventKey) {
@ -168,6 +168,7 @@ class TopModule extends React.Component {
destination: d.requestInit.destination,
destinationLabels: d.requestInit.destinationMeta.labels,
destinationDisplay,
httpMethod: _.get(d, "requestInit.http.requestInit.method.registered"),
path: d.requestInit.http.requestInit.path,
key: eventKey,
lastUpdated: Date.now()