Skip to content
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
1 change: 0 additions & 1 deletion LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion deps/go.MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 22 additions & 33 deletions pkg/aggregator/demultiplexer_agent_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
11 changes: 6 additions & 5 deletions test/fakeintake/cmd/client/cmd/routestats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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()
},
}

Expand Down
3 changes: 0 additions & 3 deletions test/fakeintake/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 0 additions & 7 deletions test/fakeintake/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading