Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove target address option #253

Merged
merged 1 commit into from
Jul 14, 2023
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
22 changes: 14 additions & 8 deletions pkg/disruptors/cmd_builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import (
"github.com/grafana/xk6-disruptor/pkg/utils"
)

func buildGrpcFaultCmd(fault GrpcFault, duration time.Duration, options GrpcDisruptionOptions) []string {
func buildGrpcFaultCmd(
targetAddress string,
fault GrpcFault,
duration time.Duration,
options GrpcDisruptionOptions,
) []string {
cmd := []string{
"xk6-disruptor-agent",
"grpc",
Expand Down Expand Up @@ -51,14 +56,17 @@ func buildGrpcFaultCmd(fault GrpcFault, duration time.Duration, options GrpcDisr
cmd = append(cmd, "-p", fmt.Sprint(options.ProxyPort))
}

if options.TargetAddress != "" {
cmd = append(cmd, "--upstream-host", options.TargetAddress)
}
cmd = append(cmd, "--upstream-host", targetAddress)

return cmd
}

func buildHTTPFaultCmd(fault HTTPFault, duration time.Duration, options HTTPDisruptionOptions) []string {
func buildHTTPFaultCmd(
targetAddress string,
fault HTTPFault,
duration time.Duration,
options HTTPDisruptionOptions,
) []string {
cmd := []string{
"xk6-disruptor-agent",
"http",
Expand Down Expand Up @@ -101,9 +109,7 @@ func buildHTTPFaultCmd(fault HTTPFault, duration time.Duration, options HTTPDisr
cmd = append(cmd, "-p", fmt.Sprint(options.ProxyPort))
}

if options.TargetAddress != "" {
cmd = append(cmd, "--upstream-host", options.TargetAddress)
}
cmd = append(cmd, "--upstream-host", targetAddress)

return cmd
}
10 changes: 4 additions & 6 deletions pkg/disruptors/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,12 @@ func (d *podDisruptor) InjectHTTPFaults(
return nil, fmt.Errorf("pod %q does not expose port %d", pod.Name, fault.Port)
}

var err error
options.TargetAddress, err = utils.PodIP(pod)
targetAddress, err := utils.PodIP(pod)
if err != nil {
return nil, err
}

cmd := buildHTTPFaultCmd(fault, duration, options)
cmd := buildHTTPFaultCmd(targetAddress, fault, duration, options)

return cmd, nil
})
Expand All @@ -148,13 +147,12 @@ func (d *podDisruptor) InjectGrpcFaults(
return nil, fmt.Errorf("pod %q does not expose port %d", pod.Name, fault.Port)
}

var err error
options.TargetAddress, err = utils.PodIP(pod)
targetAddress, err := utils.PodIP(pod)
if err != nil {
return nil, err
}

cmd := buildGrpcFaultCmd(fault, duration, options)
cmd := buildGrpcFaultCmd(targetAddress, fault, duration, options)
return cmd, nil
})
}
6 changes: 0 additions & 6 deletions pkg/disruptors/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,12 @@ type ProtocolFaultInjector interface {

// HTTPDisruptionOptions defines options for the injection of HTTP faults in a target pod
type HTTPDisruptionOptions struct {
// IP address where the proxy will send requests.
// This is typically the pod IP. It must not be `localhost`.
TargetAddress string
// Port used by the agent for listening
ProxyPort uint `js:"proxyPort"`
}

// GrpcDisruptionOptions defines options for the injection of grpc faults in a target pod
type GrpcDisruptionOptions struct {
// IP address where the proxy will send requests.
// This is typically the pod IP. It must not be `localhost`.
TargetAddress string
// Port used by the agent for listening
ProxyPort uint `js:"proxyPort"`
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/disruptors/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ func (d *serviceDisruptor) InjectHTTPFaults(
podFault := fault
podFault.Port = port

options.TargetAddress, err = utils.PodIP(pod)
targetAddress, err := utils.PodIP(pod)
if err != nil {
return nil, err
}

cmd := buildHTTPFaultCmd(fault, duration, options)
cmd := buildHTTPFaultCmd(targetAddress, fault, duration, options)
return cmd, nil
})
}
Expand All @@ -127,12 +127,12 @@ func (d *serviceDisruptor) InjectGrpcFaults(
podFault := fault
podFault.Port = port

options.TargetAddress, err = utils.PodIP(pod)
targetAddress, err := utils.PodIP(pod)
if err != nil {
return nil, err
}

cmd := buildGrpcFaultCmd(fault, duration, options)
cmd := buildGrpcFaultCmd(targetAddress, fault, duration, options)
return cmd, nil
})
}
Expand Down
Loading