flowcontrol

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ControlPointsCmd = &cobra.Command{
	Use:           "control-points",
	Short:         "List Flow Control control points",
	Long:          `List Flow Control control points`,
	SilenceErrors: true,
	Example:       `aperturectl flow-control control-points --kube`,
	RunE: func(_ *cobra.Command, _ []string) error {
		client, err := controller.Client()
		if err != nil {
			return err
		}

		resp, err := client.ListFlowControlPoints(
			context.Background(),
			&cmdv1.ListFlowControlPointsRequest{},
		)
		if err != nil {
			return err
		}

		if resp.ErrorsCount != 0 {
			fmt.Fprintf(os.Stderr, "Could not get answer from %d agents", resp.ErrorsCount)
		}

		slices.SortFunc(resp.GlobalFlowControlPoints, func(a, b *cmdv1.GlobalFlowControlPoint) bool {
			if a.AgentGroup != b.AgentGroup {
				return a.AgentGroup < b.AgentGroup
			}
			if a.FlowControlPoint.Service != b.FlowControlPoint.Service {
				return a.FlowControlPoint.Service < b.FlowControlPoint.Service
			}
			return a.FlowControlPoint.ControlPoint < b.FlowControlPoint.ControlPoint
		})

		tabwriter := tabwriter.NewWriter(os.Stdout, 5, 0, 3, ' ', 0)
		fmt.Fprintln(tabwriter, "AGENT GROUP\tSERVICE\tNAME\tTYPE")
		for _, cp := range resp.GlobalFlowControlPoints {
			fmt.Fprintf(tabwriter, "%s\t%s\t%s\t%s\n",
				cp.AgentGroup,
				cp.FlowControlPoint.Service,
				cp.FlowControlPoint.ControlPoint,
				cp.FlowControlPoint.Type)
		}
		tabwriter.Flush()

		return nil
	},
}

ControlPointsCmd is the command to list control points.

View Source
var FlowControlCmd = &cobra.Command{
	Use:               "flow-control",
	Short:             "Flow Control integrations",
	Long:              `Use this command to query information about active Flow Control integrations`,
	SilenceErrors:     true,
	PersistentPreRunE: controller.PreRunE,
	PersistentPostRun: controller.PostRun,
}

FlowControlCmd is the command to observe Flow Control control points.

View Source
var PreviewCmd = &cobra.Command{
	Use:           "preview [--http] SERVICE CONTROL_POINT",
	Short:         "Preview control points",
	Long:          `Preview samples of flow labels or HTTP requests on control points`,
	SilenceErrors: true,
	Args:          cobra.ExactArgs(2),
	RunE: func(_ *cobra.Command, args []string) error {
		client, err := controller.Client()
		if err != nil {
			return err
		}

		previewReq := &previewv1.PreviewRequest{
			Samples:      int64(numSamples),
			Service:      args[0],
			ControlPoint: args[1],
		}

		if isHTTPPreview {
			resp, err := client.PreviewHTTPRequests(
				context.Background(),
				&cmdv1.PreviewHTTPRequestsRequest{
					AgentGroup: agentGroup,
					Request:    previewReq,
				},
			)
			if err != nil {
				return err
			}
			samplesJSON, err := protojson.MarshalOptions{Multiline: true}.Marshal(resp.Response)
			if err != nil {
				return err
			}
			os.Stdout.Write(samplesJSON)
		} else {
			resp, err := client.PreviewFlowLabels(
				context.Background(),
				&cmdv1.PreviewFlowLabelsRequest{
					AgentGroup: agentGroup,
					Request:    previewReq,
				},
			)
			if err != nil {
				return err
			}
			samplesJSON, err := protojson.MarshalOptions{Multiline: true}.Marshal(resp.Response)
			if err != nil {
				return err
			}
			os.Stdout.Write(samplesJSON)
		}

		return nil
	},
}

PreviewCmd is the command to preview control points.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL