diff --git a/LICENSE-3rdparty.csv b/LICENSE-3rdparty.csv index 8b37283eb5549a..b9f2b6c9d67ca7 100644 --- a/LICENSE-3rdparty.csv +++ b/LICENSE-3rdparty.csv @@ -1685,7 +1685,6 @@ core,github.com/netsampler/goflow2/utils,BSD-3-Clause,"Copyright (c) 2021, NetSa core,github.com/nexus-rpc/sdk-go/nexus,MIT,Copyright (c) 2023 Temporal Technologies Inc. All Rights Reserved core,github.com/oklog/ulid,Apache-2.0,- Peter Bourgon (@peterbourgon) | - Tomás Senart (@tsenart) core,github.com/oklog/ulid/v2,Apache-2.0,- Peter Bourgon (@peterbourgon) | - Tomás Senart (@tsenart) -core,github.com/olekukonko/tablewriter,MIT,Copyright (C) 2014 by Oleku Konko core,github.com/oliveagle/jsonpath,MIT,Copyright (c) 2015 oliver core,github.com/open-policy-agent/opa/capabilities,Apache-2.0,Copyright 2016 The OPA Authors. All rights reserved. core,github.com/open-policy-agent/opa/internal/bundle,Apache-2.0,Copyright 2016 The OPA Authors. All rights reserved. diff --git a/deps/go.MODULE.bazel b/deps/go.MODULE.bazel index 33f60fed9efced..f44404e0c381c5 100644 --- a/deps/go.MODULE.bazel +++ b/deps/go.MODULE.bazel @@ -350,7 +350,6 @@ use_repo( "com_github_mohae_deepcopy", "com_github_netsampler_goflow2", "com_github_nvidia_go_nvml", - "com_github_olekukonko_tablewriter", "com_github_oliveagle_jsonpath", "com_github_open_policy_agent_opa", "com_github_open_telemetry_opentelemetry_collector_contrib_extension_healthcheckextension", diff --git a/go.mod b/go.mod index 959355fc854821..c78f242a98d0fd 100644 --- a/go.mod +++ b/go.mod @@ -288,7 +288,6 @@ require ( github.com/moby/sys/mountinfo v0.7.2 github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 github.com/netsampler/goflow2 v1.3.3 - github.com/olekukonko/tablewriter v0.0.5 github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852 github.com/open-policy-agent/opa v1.7.1 github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog v0.147.0 diff --git a/go.sum b/go.sum index b1b5ec01182776..10540637838561 100644 --- a/go.sum +++ b/go.sum @@ -1755,7 +1755,6 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-shellwords v1.0.2/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o= @@ -1926,8 +1925,6 @@ github.com/oklog/ulid/v2 v2.1.1/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNs github.com/okta/okta-sdk-golang/v5 v5.0.2 h1:eecvycE/XDX56IWTsOVhqfj5txCgqryTXzKy7wKEq78= github.com/okta/okta-sdk-golang/v5 v5.0.2/go.mod h1:T/vmECtJX33YPZSVD+sorebd8LLhe38Bi/VrFTjgVX0= github.com/olekukonko/tablewriter v0.0.0-20180130162743-b8a9be070da4/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= -github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= -github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852 h1:Yl0tPBa8QPjGmesFh1D0rDy+q1Twx6FyU7VWHi8wZbI= github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852/go.mod h1:eqOVx5Vwu4gd2mmMZvVZsgIqNSaW3xxRThUJ0k/TPk4= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= diff --git a/pkg/aggregator/demultiplexer_agent_printer.go b/pkg/aggregator/demultiplexer_agent_printer.go index 160053e0a2f77c..a26ef518ca1c2b 100644 --- a/pkg/aggregator/demultiplexer_agent_printer.go +++ b/pkg/aggregator/demultiplexer_agent_printer.go @@ -9,11 +9,12 @@ import ( "bytes" "encoding/json" "fmt" + "strings" + "text/tabwriter" "time" "github.com/DataDog/datadog-agent/pkg/collector/check/stats" "github.com/fatih/color" - "github.com/olekukonko/tablewriter" ) // AgentDemultiplexerPrinter is used to output series, sketches, service checks @@ -40,22 +41,7 @@ func (p AgentDemultiplexerPrinter) PrintMetrics(checkFileOutput *bytes.Buffer, f headers, data := series.MarshalStrings() var buffer bytes.Buffer - // plain table with no borders - table := tablewriter.NewWriter(&buffer) - table.SetHeader(headers) - table.SetAutoWrapText(false) - table.SetAutoFormatHeaders(true) - table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) - table.SetAlignment(tablewriter.ALIGN_LEFT) - table.SetCenterSeparator("") - table.SetColumnSeparator("") - table.SetRowSeparator("") - table.SetHeaderLine(false) - table.SetBorder(false) - table.SetTablePadding("\t") - - table.AppendBulk(data) - table.Render() + writeTable(&buffer, headers, data) fmt.Println(buffer.String()) checkFileOutput.WriteString(buffer.String() + "\n") } else { @@ -79,22 +65,7 @@ func (p AgentDemultiplexerPrinter) PrintMetrics(checkFileOutput *bytes.Buffer, f headers, data := serviceChecks.MarshalStrings() var buffer bytes.Buffer - // plain table with no borders - table := tablewriter.NewWriter(&buffer) - table.SetHeader(headers) - table.SetAutoWrapText(false) - table.SetAutoFormatHeaders(true) - table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) - table.SetAlignment(tablewriter.ALIGN_LEFT) - table.SetCenterSeparator("") - table.SetColumnSeparator("") - table.SetRowSeparator("") - table.SetHeaderLine(false) - table.SetBorder(false) - table.SetTablePadding("\t") - - table.AppendBulk(data) - table.Render() + writeTable(&buffer, headers, data) fmt.Println(buffer.String()) checkFileOutput.WriteString(buffer.String() + "\n") } else { @@ -127,6 +98,24 @@ func (p AgentDemultiplexerPrinter) PrintMetrics(checkFileOutput *bytes.Buffer, f } } +// writeTable writes a tab-separated table with headers to w using text/tabwriter. +// Cell values are sanitized to replace all characters that text/tabwriter treats +// specially (\t, \v, \f, \n, \r) with spaces, preventing corruption of column +// alignment or unexpected row splitting. +func writeTable(w *bytes.Buffer, headers []string, data [][]string) { + tw := tabwriter.NewWriter(w, 0, 0, 1, ' ', 0) + fmt.Fprintln(tw, strings.ToUpper(strings.Join(headers, "\t"))) + sanitizer := strings.NewReplacer("\t", " ", "\n", " ", "\r", " ", "\v", " ", "\f", " ") + for _, row := range data { + sanitized := make([]string, len(row)) + for i, cell := range row { + sanitized[i] = sanitizer.Replace(cell) + } + fmt.Fprintln(tw, strings.Join(sanitized, "\t")) + } + tw.Flush() +} + // toDebugEpEvents transforms the raw event platform messages to eventPlatformDebugEvents which are better for json formatting func (p AgentDemultiplexerPrinter) toDebugEpEvents() map[string][]eventPlatformDebugEvent { events := p.Aggregator().GetEventPlatformEvents() diff --git a/test/fakeintake/cmd/client/cmd/routestats.go b/test/fakeintake/cmd/client/cmd/routestats.go index 1931e406520345..5641b5f142de0d 100644 --- a/test/fakeintake/cmd/client/cmd/routestats.go +++ b/test/fakeintake/cmd/client/cmd/routestats.go @@ -6,11 +6,12 @@ package cmd import ( + "fmt" "log" "os" "strconv" + "text/tabwriter" - "github.com/olekukonko/tablewriter" "github.com/spf13/cobra" "github.com/DataDog/datadog-agent/test/fakeintake/client" @@ -27,12 +28,12 @@ func NewRouteStatsCommand(cl **client.Client) (cmd *cobra.Command) { log.Fatalln(err) } - table := tablewriter.NewWriter(os.Stdout) - table.SetHeader([]string{"Route", "Count"}) + tw := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0) + fmt.Fprintln(tw, "ROUTE\tCOUNT") for route, count := range stats { - table.Append([]string{route, strconv.Itoa(count)}) + fmt.Fprintf(tw, "%s\t%s\n", route, strconv.Itoa(count)) } - table.Render() + tw.Flush() }, } diff --git a/test/fakeintake/go.mod b/test/fakeintake/go.mod index e6d6c612d515e3..ac79bc92764d91 100644 --- a/test/fakeintake/go.mod +++ b/test/fakeintake/go.mod @@ -15,7 +15,6 @@ require ( github.com/cenkalti/backoff/v5 v5.0.3 github.com/google/uuid v1.6.0 github.com/kr/pretty v0.3.1 - github.com/olekukonko/tablewriter v0.0.5 github.com/prometheus/client_golang v1.23.2 github.com/samber/lo v1.52.0 github.com/spf13/cobra v1.10.2 @@ -34,13 +33,11 @@ require ( github.com/DataDog/zstd_0 v0.0.0-20210310093942-586c1286621f // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/clipperhouse/uax29/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/klauspost/compress v1.18.4 // indirect github.com/kr/text v0.2.0 // indirect - github.com/mattn/go-runewidth v0.0.19 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/philhofer/fwd v1.2.0 // indirect github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect diff --git a/test/fakeintake/go.sum b/test/fakeintake/go.sum index a6aafa04a78aa0..d4e68021ef50d3 100644 --- a/test/fakeintake/go.sum +++ b/test/fakeintake/go.sum @@ -14,8 +14,6 @@ github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1x github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/clipperhouse/uax29/v2 v2.2.0 h1:ChwIKnQN3kcZteTXMgb1wztSgaU+ZemkgWdohwgs8tY= -github.com/clipperhouse/uax29/v2 v2.2.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= @@ -42,13 +40,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= -github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw= -github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= -github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/philhofer/fwd v1.2.0 h1:e6DnBTl7vGY+Gz322/ASL4Gyp1FspeMvx1RNDoToZuM= github.com/philhofer/fwd v1.2.0/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=