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
18 changes: 5 additions & 13 deletions cli/cmd/network_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,13 @@ pods, processes, and DNS queries. Reports must be enabled with 'replicated netwo
Output formats:
- Default: Full event details in JSON format
- --summary: Aggregated statistics with top domains and destinations
- --watch: Continuous stream of new events in JSON Lines format

Filtering:
- --show-external-only: Show only external network traffic (default: true)
Set to false to include internal cluster traffic`,
- --watch: Continuous stream of new events in JSON Lines format`,
Example: `# Get full network traffic report (external traffic only)
replicated network report <network-id>

# Get aggregated summary with statistics. Only available for networks that have been terminated.
replicated network report <network-id> --summary

# Include internal cluster traffic in the report
replicated network report <network-id> --show-external-only=false

# Watch for new network events in real-time
replicated network report <network-id> --watch`,
RunE: r.getNetworkReport,
Expand All @@ -54,7 +47,6 @@ replicated network report <network-id> --watch`,

cmd.Flags().BoolVarP(&r.args.networkReportWatch, "watch", "w", false, "Watch for new network events in real-time (polls every 2 seconds)")
cmd.Flags().BoolVar(&r.args.networkReportSummary, "summary", false, "Get aggregated report summary with statistics instead of individual events")
cmd.Flags().BoolVar(&r.args.networkReportShowExternalOnly, "show-external-only", true, "Show only external network traffic")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if we want to leave this flag added but hidden, so if vendors have this in their CI scripts it won't fail. optionally we can display a deprecated warning as well if the hidden flag is supplied


return cmd
}
Expand Down Expand Up @@ -85,7 +77,7 @@ func (r *runners) getNetworkReport(cmd *cobra.Command, args []string) error {
}

func (r *runners) getNetworkReportEvents() error {
report, err := r.kotsAPI.GetNetworkReport(r.args.networkReportID, r.args.networkReportShowExternalOnly)
report, err := r.kotsAPI.GetNetworkReport(r.args.networkReportID)
if errors.Cause(err) == platformclient.ErrForbidden {
return ErrCompatibilityMatrixTermsNotAccepted
} else if err != nil {
Expand Down Expand Up @@ -119,9 +111,9 @@ func (r *runners) getNetworkReportEvents() error {
for range time.Tick(2 * time.Second) {
var newReport *types.NetworkReport
if lastEventTime != nil {
newReport, err = r.kotsAPI.GetNetworkReportAfter(r.args.networkReportID, lastEventTime, r.args.networkReportShowExternalOnly)
newReport, err = r.kotsAPI.GetNetworkReportAfter(r.args.networkReportID, lastEventTime)
} else {
newReport, err = r.kotsAPI.GetNetworkReport(r.args.networkReportID, r.args.networkReportShowExternalOnly)
newReport, err = r.kotsAPI.GetNetworkReport(r.args.networkReportID)
}

if err != nil {
Expand Down Expand Up @@ -152,7 +144,7 @@ func (r *runners) getNetworkReportSummary(ctx context.Context) error {
return fmt.Errorf("cannot use watch and summary flags together")
}

summary, err := r.kotsAPI.GetNetworkReportSummary(ctx, r.args.networkReportID, r.args.networkReportShowExternalOnly)
summary, err := r.kotsAPI.GetNetworkReportSummary(ctx, r.args.networkReportID)
if errors.Cause(err) == platformclient.ErrForbidden {
return ErrCompatibilityMatrixTermsNotAccepted
} else if errors.Cause(err) == platformclient.ErrNotFound {
Expand Down
7 changes: 3 additions & 4 deletions cli/cmd/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,9 @@ type runnerArgs struct {
lsNetworkEndTime string
lsNetworkWatch bool

networkReportID string
networkReportWatch bool
networkReportSummary bool
networkReportShowExternalOnly bool
networkReportID string
networkReportWatch bool
networkReportSummary bool

updateNetworkPolicy string
updateNetworkCollectReport bool
Expand Down
15 changes: 5 additions & 10 deletions pkg/kotsclient/network_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ import (
"github.com/replicatedhq/replicated/pkg/types"
)

func (c *VendorV3Client) GetNetworkReport(id string, showExternalOnly bool) (*types.NetworkReport, error) {
return c.GetNetworkReportAfter(id, nil, showExternalOnly)
func (c *VendorV3Client) GetNetworkReport(id string) (*types.NetworkReport, error) {
return c.GetNetworkReportAfter(id, nil)
}

func (c *VendorV3Client) GetNetworkReportAfter(id string, after *time.Time, showExternalOnly bool) (*types.NetworkReport, error) {
func (c *VendorV3Client) GetNetworkReportAfter(id string, after *time.Time) (*types.NetworkReport, error) {
urlPath := fmt.Sprintf("/v3/network/%s/report", id)
v := url.Values{}
if after != nil {
v.Set("after", after.Format(time.RFC3339Nano))
}
v.Set("show-external-only", fmt.Sprintf("%t", showExternalOnly))
if len(v) > 0 {
urlPath = fmt.Sprintf("%s?%s", urlPath, v.Encode())
}
Expand Down Expand Up @@ -60,13 +59,9 @@ func (c *VendorV3Client) GetNetworkReportAfter(id string, after *time.Time, show
return &types.NetworkReport{Events: events}, nil
}

func (c *VendorV3Client) GetNetworkReportSummary(ctx context.Context, id string, showExternalOnly bool) (*types.NetworkReportSummary, error) {
func (c *VendorV3Client) GetNetworkReportSummary(ctx context.Context, id string) (*types.NetworkReportSummary, error) {
urlPath := fmt.Sprintf("/v3/network/%s/report/summary", id)
v := url.Values{}
v.Set("show-external-only", fmt.Sprintf("%t", showExternalOnly))
if len(v) > 0 {
urlPath = fmt.Sprintf("%s?%s", urlPath, v.Encode())
}

type summaryResp struct {
*types.NetworkReportSummary
Error string `json:"error,omitempty"`
Expand Down
Loading