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

Add trafficsplit metrics to CLI #3176

Merged
merged 21 commits into from
Aug 14, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Getting outbound Prometheus stats and adding CLI output
Carol Scott committed Aug 14, 2019
commit 68dd03480381dda79e1fcb937874231a35244ce3
47 changes: 0 additions & 47 deletions authors-clone.yml

This file was deleted.

11 changes: 0 additions & 11 deletions books-split.yml

This file was deleted.

1 change: 1 addition & 0 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
@@ -152,6 +152,7 @@ func renderStats(buffer bytes.Buffer, options *statOptionsBase) string {
out = string(buffer.Bytes()[padding:])
out = strings.Replace(out, "\n"+strings.Repeat(" ", padding), "\n", -1)
}

return out
}

43 changes: 15 additions & 28 deletions cli/cmd/stat.go
Original file line number Diff line number Diff line change
@@ -242,14 +242,14 @@ var (
weightHeader = "WEIGHT"
)

func writeStatsToBuffer(rows []*pb.StatTable_PodGroup_Row, w *tabwriter.Writer, options *statOptions) { // i think we should write a different function for TrafficSplit stats since the table is different.
func writeStatsToBuffer(rows []*pb.StatTable_PodGroup_Row, w *tabwriter.Writer, options *statOptions) {
maxNameLength := len(nameHeader)
maxNamespaceLength := len(namespaceHeader)
statTables := make(map[string]map[string]*row)

maxApexLength := len(apexHeader)
maxLeafLength := len(leafHeader)
maxWeightLength := len(weightHeader)
statTables := make(map[string]map[string]*row) // making new empty statTables map
//isTrafficSplit := false

prefixTypes := make(map[string]bool)
for _, r := range rows {
@@ -273,7 +273,7 @@ func writeStatsToBuffer(rows []*pb.StatTable_PodGroup_Row, w *tabwriter.Writer,
apex := ""
weight := ""

var key = ""
var key string
if resourceType == "trafficsplit" {
leaf = r.TsStats.Leaf
apex = r.TsStats.Apex
@@ -285,7 +285,7 @@ func writeStatsToBuffer(rows []*pb.StatTable_PodGroup_Row, w *tabwriter.Writer,
resourceKey := r.Resource.Type

if _, ok := statTables[resourceKey]; !ok {
statTables[resourceKey] = make(map[string]*row) // if the statTables doesn't already have the specific resourceType you are looking at... add it.
statTables[resourceKey] = make(map[string]*row)
}

if len(nameWithPrefix) > maxNameLength {
@@ -341,7 +341,7 @@ func writeStatsToBuffer(rows []*pb.StatTable_PodGroup_Row, w *tabwriter.Writer,
switch options.outputFormat {
case tableOutput, wideOutput:
if len(statTables) == 0 {
if isTrafficSplit == false {
if !isTrafficSplit {
fmt.Fprintln(os.Stderr, "No traffic found.")
} else {
fmt.Fprintln(os.Stderr, "No trafficsplits found.")
@@ -405,14 +405,9 @@ func printSingleStatTable(stats map[string]*row, resourceTypeLabel, resourceType
weightTemplate := fmt.Sprintf("%%-%ds", maxWeightLength)

headers = append(headers,

fmt.Sprintf(apexTemplate, "APEX"),
fmt.Sprintf(leafTemplate, "LEAF"),
fmt.Sprintf(weightTemplate, "WEIGHT"))

//apexHeader+strings.Repeat(" ", maxApexLength-len(apexHeader)),
//leafHeader+strings.Repeat(" ", maxLeafLength-len(leafHeader)),
//weightHeader+strings.Repeat(" ", maxWeightLength-len(weightHeader)))
}

if resourceType != k8s.TrafficSplit {
@@ -445,7 +440,6 @@ func printSingleStatTable(stats map[string]*row, resourceTypeLabel, resourceType
values := make([]interface{}, 0)
templateString := "%s\t%s\t%.2f%%\t%.1frps\t%dms\t%dms\t%dms\t"
templateStringEmpty := "%s\t%s\t-\t-\t-\t-\t-\t-\t"

if resourceType == k8s.Pod {
templateString = "%s\t" + templateString
templateStringEmpty = "%s\t" + templateStringEmpty
@@ -497,12 +491,6 @@ func printSingleStatTable(stats map[string]*row, resourceTypeLabel, resourceType
leafPadding = maxLeafLength - len(stats[key].tsStats.leaf)
}
}
/*
weightPadding := 0
if maxWeightLength > len(stats[key].tsStats.weight) {
weightPadding = maxWeightLength - len(stats[key].tsStats.weight)
}
//*/
values = append(values, name+strings.Repeat(" ", padding))
if resourceType == k8s.Pod {
values = append(values, stats[key].status)
@@ -517,17 +505,9 @@ func printSingleStatTable(stats map[string]*row, resourceTypeLabel, resourceType
values = append(values,
stats[key].tsStats.apex+strings.Repeat(" ", apexPadding),
stats[key].tsStats.leaf+strings.Repeat(" ", leafPadding),
stats[key].tsStats.weight, //+strings.Repeat(" ", weightPadding),
)
}

/*
values = append(values,
stats[key].tsStats.apex,
stats[key].tsStats.leaf,
stats[key].tsStats.weight,
)
//*/
}

if stats[key].rowStats != nil {
values = append(values, []interface{}{
@@ -577,6 +557,9 @@ type jsonStats struct {
TCPConnections *uint64 `json:"tcp_open_connections"`
TCPReadBytes *float64 `json:"tcp_read_bytes_rate"`
TCPWriteBytes *float64 `json:"tcp_write_bytes_rate"`
Apex string `json:"apex"`
Leaf string `json:"leaf"`
Weight string `json:"weight"`
}

func printStatJSON(statTables map[string]map[string]*row, w *tabwriter.Writer) {
@@ -606,7 +589,11 @@ func printStatJSON(statTables map[string]map[string]*row, w *tabwriter.Writer) {
entry.TCPWriteBytes = &stats[key].tcpWriteBytes
}
}

if stats[key].tsStats != nil {
entry.Apex = stats[key].apex
entry.Leaf = stats[key].leaf
entry.Weight = stats[key].weight
}
entries = append(entries, entry)
}
}
2 changes: 1 addition & 1 deletion controller/api/public/prometheus.go
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ func promDstGroupByLabelNames(resource *pb.Resource) model.LabelNames {
func promQueryLabels(resource *pb.Resource) model.LabelSet {
set := model.LabelSet{}
if resource != nil {
if resource.Name != "" && resource.GetType() != k8s.Service {
if resource.Name != "" && resource.GetType() != k8s.Service && resource.GetType() != k8s.TrafficSplit {
scottcarol marked this conversation as resolved.
Show resolved Hide resolved
set[promResourceType(resource)] = model.LabelValue(resource.Name)
}
if shouldAddNamespaceLabel(resource) {
Loading
Oops, something went wrong.