mirror of
https://github.com/weaveworks/scope.git
synced 2026-02-14 10:00:13 +00:00
do not truncate tables
Limiting env vars, docker&k8s labels, and weave net connection entries to 20 is problematic because - the truncation is arbitrary - there is a good chance that if you care about a specific entry it won't be there - the truncation is not consistent - different entries get truncated at different times - some of the rendering logic depends on specific labels, for example namespace filtering of containers depends on the `io.kubernetes.pod.namespace` label. In practice, there should never be a huge number of labels, or Weave Net connection entries. So there is no need to truncate them. That leaves env vars. These are of limited use, so we now omit them by default. If they are included they are included in full, so they are actually useful. Fixes #3127
This commit is contained in:
@@ -281,7 +281,7 @@ func setupFlags(flags *flags) {
|
||||
flag.StringVar(&flags.probe.pluginsRoot, "probe.plugins.root", "/var/run/scope/plugins", "Root directory to search for plugins")
|
||||
flag.BoolVar(&flags.probe.noControls, "probe.no-controls", false, "Disable controls (e.g. start/stop containers, terminals, logs ...)")
|
||||
flag.BoolVar(&flags.probe.noCommandLineArguments, "probe.omit.cmd-args", false, "Disable collection of command-line arguments")
|
||||
flag.BoolVar(&flags.probe.noEnvironmentVariables, "probe.omit.env-vars", false, "Disable collection of environment variables")
|
||||
flag.BoolVar(&flags.probe.noEnvironmentVariables, "probe.omit.env-vars", true, "Disable collection of environment variables")
|
||||
|
||||
flag.BoolVar(&flags.probe.insecure, "probe.insecure", false, "(SSL) explicitly allow \"insecure\" SSL connections and transfers")
|
||||
flag.StringVar(&flags.probe.resolver, "probe.resolver", "", "IP address & port of resolver to use. Default is to use system resolver.")
|
||||
|
||||
@@ -10,55 +10,33 @@ import (
|
||||
"github.com/weaveworks/common/mtime"
|
||||
)
|
||||
|
||||
// MaxTableRows sets the limit on the table size to render
|
||||
// TODO: this won't be needed once we send reports incrementally
|
||||
const (
|
||||
MaxTableRows = 20
|
||||
TableEntryKeySeparator = "___"
|
||||
TruncationCountPrefix = "table_truncation_count_"
|
||||
MulticolumnTableType = "multicolumn-table"
|
||||
PropertyListType = "property-list"
|
||||
)
|
||||
|
||||
// withTableTruncationInformation appends table truncation info to the node, returning the new node.
|
||||
func (node Node) withTableTruncationInformation(prefix string, totalRowsCount int, now time.Time) Node {
|
||||
if totalRowsCount > MaxTableRows {
|
||||
truncationCount := fmt.Sprintf("%d", totalRowsCount-MaxTableRows)
|
||||
node = node.WithLatest(TruncationCountPrefix+prefix, now, truncationCount)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// AddPrefixMulticolumnTable appends arbitrary rows to the Node, returning a new node.
|
||||
func (node Node) AddPrefixMulticolumnTable(prefix string, rows []Row) Node {
|
||||
now := mtime.Now()
|
||||
addedRowsCount := 0
|
||||
for _, row := range rows {
|
||||
if addedRowsCount >= MaxTableRows {
|
||||
break
|
||||
}
|
||||
// Add all the row values as separate entries
|
||||
for columnID, value := range row.Entries {
|
||||
key := strings.Join([]string{row.ID, columnID}, TableEntryKeySeparator)
|
||||
node = node.WithLatest(prefix+key, now, value)
|
||||
}
|
||||
addedRowsCount++
|
||||
}
|
||||
return node.withTableTruncationInformation(prefix, len(rows), now)
|
||||
return node
|
||||
}
|
||||
|
||||
// AddPrefixPropertyList appends arbitrary key-value pairs to the Node, returning a new node.
|
||||
func (node Node) AddPrefixPropertyList(prefix string, propertyList map[string]string) Node {
|
||||
now := mtime.Now()
|
||||
addedPropertiesCount := 0
|
||||
for label, value := range propertyList {
|
||||
if addedPropertiesCount >= MaxTableRows {
|
||||
break
|
||||
}
|
||||
node = node.WithLatest(prefix+label, now, value)
|
||||
addedPropertiesCount++
|
||||
}
|
||||
return node.withTableTruncationInformation(prefix, len(propertyList), now)
|
||||
return node
|
||||
}
|
||||
|
||||
// WithoutPrefix returns the string with trimmed prefix and a
|
||||
@@ -137,7 +115,12 @@ func (node Node) ExtractPropertyList(template TableTemplate) (rows []Row) {
|
||||
return rows
|
||||
}
|
||||
|
||||
// ExtractTable returns the rows to build either a property list or a generic table from this node
|
||||
// ExtractTable returns the rows to build either a property list or a
|
||||
// generic table from this node. It also returns the number of rows,
|
||||
// if any, that were truncated. The probes used to limit the number of
|
||||
// labels, env vars and Weave Net connections they report, but this
|
||||
// logic has since been removed. So the code here dealing with
|
||||
// truncation is only retained in order to handle legacy reports.
|
||||
func (node Node) ExtractTable(template TableTemplate) (rows []Row, truncationCount int) {
|
||||
switch template.Type {
|
||||
case MulticolumnTableType:
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package report_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
@@ -132,70 +131,6 @@ func TestFixedPropertyLists(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPropertyListTruncation(t *testing.T) {
|
||||
wantTruncationCount := 1
|
||||
propertyList := map[string]string{}
|
||||
for i := 0; i < report.MaxTableRows+wantTruncationCount; i++ {
|
||||
key := fmt.Sprintf("key%d", i)
|
||||
value := fmt.Sprintf("value%d", i)
|
||||
propertyList[key] = value
|
||||
}
|
||||
|
||||
nmd := report.MakeNode("foo1")
|
||||
nmd = nmd.AddPrefixPropertyList("foo_", propertyList)
|
||||
|
||||
template := report.TableTemplate{
|
||||
Type: report.PropertyListType,
|
||||
Prefix: "foo_",
|
||||
}
|
||||
|
||||
_, truncationCount := nmd.ExtractTable(template)
|
||||
|
||||
if truncationCount != wantTruncationCount {
|
||||
t.Error(
|
||||
"Property list should had been truncated by",
|
||||
wantTruncationCount,
|
||||
"and not",
|
||||
truncationCount,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMulticolumnTableTruncation(t *testing.T) {
|
||||
wantTruncationCount := 1
|
||||
rows := []report.Row{}
|
||||
for i := 0; i < report.MaxTableRows+wantTruncationCount; i++ {
|
||||
rowID := fmt.Sprintf("row%d", i)
|
||||
colID := fmt.Sprintf("col%d", i)
|
||||
value := fmt.Sprintf("value%d", i)
|
||||
rows = append(rows, report.Row{
|
||||
ID: rowID,
|
||||
Entries: map[string]string{
|
||||
colID: value,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
nmd := report.MakeNode("foo1")
|
||||
nmd = nmd.AddPrefixMulticolumnTable("foo_", rows)
|
||||
|
||||
template := report.TableTemplate{
|
||||
Type: report.MulticolumnTableType,
|
||||
Prefix: "foo_",
|
||||
}
|
||||
|
||||
_, truncationCount := nmd.ExtractTable(template)
|
||||
|
||||
if truncationCount != wantTruncationCount {
|
||||
t.Error(
|
||||
"Property list should had been truncated by",
|
||||
wantTruncationCount,
|
||||
"and not",
|
||||
truncationCount,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTables(t *testing.T) {
|
||||
want := []report.Table{
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user