Skip to content

[DONT REVIEW] try to reproduce restart issue #1269

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ docker.push: docker

.PHONY: e2e
e2e:
./test/e2e/run_test.sh
./test/e2e/run_test.sh --skip-cleanup-apps

.PHONY: e2e-ipv6
e2e-ipv6:
./test/e2e/run_test.sh --ipv6
./test/e2e/run_test.sh --ipv6 --skip-cleanup-apps

.PHONY: format
format:
Expand Down
1 change: 0 additions & 1 deletion bpf/include/bpf_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ volatile __u32 bpf_log_level = BPF_LOG_INFO;

#define BPF_LOG(l, t, f, ...) \
do { \
BPF_LOG_U("bpf log level %u %u", BPF_LOG_##l, bpf_log_level); \
if ((int)(BPF_LOG_##l) <= bpf_log_level) { \
static const char fmt[] = "[" #t "] " #l ": " f ""; \
if (!KERNEL_VERSION_HIGHER_5_13_0) \
Expand Down
2 changes: 1 addition & 1 deletion bpf/kmesh/workload/xdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static inline void shutdown_tuple(struct xdp_info *info)
{
info->tcph->fin = 0;
info->tcph->syn = 0;
info->tcph->rst = 1;
info->tcph->rst = 0;
info->tcph->psh = 0;
info->tcph->ack = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (r *Rbac) doRbac(conn *rbacConnection) bool {
// If no workload found, deny
if dstWorkload == nil {
log.Debugf("denied for connection: %v because destination workload not found", conn)
return false
return true
}

// TODO: maybe cache them for performance issue
Expand Down
24 changes: 10 additions & 14 deletions pkg/bpf/bpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,20 +294,16 @@

// Kmesh reboot updates only the nodeIP and pod sub gateway
if restart.GetStartType() == restart.Normal {
if err := l.NodeIP.Set(nodeIP); err != nil {
log.Error("set NodeIP failed ", err)
return
}
if err := l.PodGateway.Set(gateway); err != nil {
log.Error("set PodGateway failed ", err)
return
}
if err := l.AuthzOffload.Set(constants.ENABLED); err != nil {
log.Error("set AuthzOffload failed ", err)
return
}
if err := l.EnableMonitoring.Set(constants.ENABLED); err != nil {
log.Error("set EnableMonitoring failed ", err)
// Kmesh is create first time. So init kmeshConfigMap.
// valueOfKmeshBpfConfig.BpfLogLevel = constants.BPF_LOG_INFO
valueOfKmeshBpfConfig.BpfLogLevel = constants.BPF_LOG_DEBUG

Check failure on line 299 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / build (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 299 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / build (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 299 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / build (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 299 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 299 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 299 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 299 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 299 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 299 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: valueOfKmeshBpfConfig
valueOfKmeshBpfConfig.NodeIP = nodeIP

Check failure on line 300 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / build (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 300 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / build (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 300 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / build (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 300 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 300 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 300 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 300 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 300 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 300 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: valueOfKmeshBpfConfig
valueOfKmeshBpfConfig.PodGateway = gateway

Check failure on line 301 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / build (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 301 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / build (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 301 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 301 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 301 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 301 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 301 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 301 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: valueOfKmeshBpfConfig
valueOfKmeshBpfConfig.AuthzOffload = constants.DISABLED

Check failure on line 302 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / build (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 302 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / build (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 302 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 302 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 302 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 302 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 302 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 302 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: valueOfKmeshBpfConfig
valueOfKmeshBpfConfig.EnableMonitoring = constants.ENABLED

Check failure on line 303 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / build (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 303 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / build (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 303 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 303 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 303 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 303 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 303 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 303 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: valueOfKmeshBpfConfig

if err := UpdateKmeshConfigMap(l.kmeshConfig, valueOfKmeshBpfConfig); err != nil {

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / build (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / build (1.23)

l.kmeshConfig undefined (type *BpfLoader has no field or method kmeshConfig)

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / build (1.23)

undefined: UpdateKmeshConfigMap

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / build (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / build (1.23)

l.kmeshConfig undefined (type *BpfLoader has no field or method kmeshConfig)

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / build (1.23)

undefined: UpdateKmeshConfigMap

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

l.kmeshConfig undefined (type *BpfLoader has no field or method kmeshConfig)

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: UpdateKmeshConfigMap

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

l.kmeshConfig undefined (type *BpfLoader has no field or method kmeshConfig)

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: UpdateKmeshConfigMap

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

l.kmeshConfig undefined (type *BpfLoader has no field or method kmeshConfig)

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: UpdateKmeshConfigMap

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

l.kmeshConfig undefined (type *BpfLoader has no field or method kmeshConfig)

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: UpdateKmeshConfigMap

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

l.kmeshConfig undefined (type *BpfLoader has no field or method kmeshConfig)

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E Test (1.23)

undefined: UpdateKmeshConfigMap

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: valueOfKmeshBpfConfig

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

l.kmeshConfig undefined (type *BpfLoader has no field or method kmeshConfig)

Check failure on line 305 in pkg/bpf/bpf.go

View workflow job for this annotation

GitHub Actions / E2E IPv6 Test (1.23)

undefined: UpdateKmeshConfigMap
log.Errorf("update kmeshConfig map failed: %v", err)
return
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ var (
defaultLogger = initDefaultLogger()
fileOnlyLogger = initFileLogger()

defaultLogLevel = logrus.InfoLevel
// defaultLogLevel = logrus.InfoLevel
defaultLogLevel = logrus.DebugLevel
defaultLogFile = "/var/run/kmesh/daemon.log"

defaultLogFormat = &logrus.TextFormatter{
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"runtime"
"testing"
Expand Down Expand Up @@ -319,6 +320,18 @@ func newWaypointProxy(ctx resource.Context, ns namespace.Instance, name string,
return nil, err
}
pod := pods[0]

// adjust log level of waypoint to trace.
cmd := exec.Command("istioctl", "pc", "log", fmt.Sprintf("%s.%s", pod.Name, pod.Namespace), "--level", "trace")

output, err := cmd.Output()
if err != nil {
fmt.Printf("execute istioctl command failed: %v", err)
return nil, err
}

fmt.Printf(string(output))

inbound, err := cls.NewPortForwarder(pod.Name, pod.Namespace, "", 0, 15008)
if err != nil {
return nil, err
Expand Down
194 changes: 188 additions & 6 deletions test/e2e/restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
package kmesh

import (
"bytes"
"context"
"fmt"
"testing"
"time"

"github.com/hashicorp/go-multierror"
"istio.io/istio/pkg/test"
"istio.io/istio/pkg/test/framework"
"istio.io/istio/pkg/test/framework/components/echo"
"istio.io/istio/pkg/test/framework/components/echo/util/traffic"
"istio.io/istio/pkg/test/framework/components/echo/check"
kubetest "istio.io/istio/pkg/test/kube"
"istio.io/istio/pkg/test/util/retry"
appsv1 "k8s.io/api/apps/v1"
Expand All @@ -45,7 +48,7 @@ func TestKmeshRestart(t *testing.T) {
dst := apps.ServiceWithWaypointAtServiceGranularity
options := echo.CallOptions{
To: dst,
Count: 1,
Count: 10,
// Determine whether it is managed by Kmesh by passing through Waypoint.
Check: httpValidator,
Port: echo.Port{
Expand All @@ -54,13 +57,22 @@ func TestKmeshRestart(t *testing.T) {
Retry: echo.Retry{NoRetry: true},
}

g := traffic.NewGenerator(t, traffic.Config{
g := NewGenerator(t, Config{
Source: src,
Options: options,
Interval: 50 * time.Millisecond,
}).Start()
Interval: 5 * time.Millisecond,
})
g.Start()

restartKmesh(t)
for i := 0; i < 1; i++ {
select {
case <-g.stopIter:
fmt.Printf("-- break restart iterator\n")
break
default:
}
restartKmesh(t)
}

g.Stop().CheckSuccessRate(t, 1)
})
Expand Down Expand Up @@ -105,3 +117,173 @@ func restartKmesh(t framework.TestContext) {
func daemonsetsetComplete(ds *appsv1.DaemonSet) bool {
return ds.Status.UpdatedNumberScheduled == ds.Status.DesiredNumberScheduled && ds.Status.NumberReady == ds.Status.DesiredNumberScheduled && ds.Status.ObservedGeneration >= ds.Generation
}

const (
defaultInterval = 1 * time.Second
defaultTimeout = 15 * time.Second
)

// Config for a traffic Generator.
type Config struct {
// Source of the traffic.
Source echo.Caller

// Options for generating traffic from the Source to the target.
Options echo.CallOptions

// Interval between successive call operations. If not set, defaults to 1 second.
Interval time.Duration

// Maximum time to wait for traffic to complete after stopping. If not set, defaults to 15 seconds.
StopTimeout time.Duration
}

// Generator of traffic between echo instances. Every time interval
// (as defined by Config.Interval), a grpc request is sent to the source pod,
// causing it to send a request to the destination echo server. Results are
// captured for each request for later processing.
type Generator interface {
// Start sending traffic.
Start() Generator

// Stop sending traffic and wait for any in-flight requests to complete.
// Returns the Result
Stop() Result
}

// NewGenerator returns a new Generator with the given configuration.
func NewGenerator(t test.Failer, cfg Config) *generator {
fillInDefaults(&cfg)
return &generator{
Config: cfg,
t: t,
stop: make(chan struct{}),
stopped: make(chan struct{}),
stopIter: make(chan struct{}),
}
}

var _ Generator = &generator{}

type generator struct {
Config
t test.Failer
result Result
stop chan struct{}
stopped chan struct{}

stopIter chan struct{}
}

func (g *generator) Start() Generator {
go func() {
t := time.NewTimer(g.Interval)
for {
select {
case <-g.stop:
t.Stop()
close(g.stopped)
return
case <-t.C:
result, err := g.Source.Call(g.Options)
g.result.add(result, err)
if err != nil {
g.t.Logf("-- %v encounter error", time.Now())
close(g.stopIter)
break
}
t.Reset(g.Interval)
}
}

for {
<-g.stop
t.Stop()
close(g.stopped)
return
}
}()
return g
}

func (g *generator) Stop() Result {
// Trigger the generator to stop.
close(g.stop)

// Wait for the generator to exit.
t := time.NewTimer(g.StopTimeout)
select {
case <-g.stopped:
t.Stop()
if g.result.TotalRequests == 0 {
g.t.Fatal("no requests completed before stopping the traffic generator")
}
return g.result
case <-t.C:
g.t.Fatal("timed out waiting for result")
}
// Can never happen, but the compiler doesn't know that Fatal terminates
return Result{}
}

func fillInDefaults(cfg *Config) {
if cfg.Interval == 0 {
cfg.Interval = defaultInterval
}
if cfg.StopTimeout == 0 {
cfg.StopTimeout = defaultTimeout
}
if cfg.Options.Check == nil {
cfg.Options.Check = check.OK()
}
}

// Result of a traffic generation operation.
type Result struct {
TotalRequests int
SuccessfulRequests int
Error error
}

func (r Result) String() string {
buf := &bytes.Buffer{}

_, _ = fmt.Fprintf(buf, "TotalRequests: %d\n", r.TotalRequests)
_, _ = fmt.Fprintf(buf, "SuccessfulRequests: %d\n", r.SuccessfulRequests)
_, _ = fmt.Fprintf(buf, "PercentSuccess: %f\n", r.PercentSuccess())
_, _ = fmt.Fprintf(buf, "Errors: %v\n", r.Error)

return buf.String()
}

func (r *Result) add(result echo.CallResult, err error) {
count := result.Responses.Len()
if count == 0 {
count = 1
}

r.TotalRequests += count
if err != nil {
r.Error = multierror.Append(r.Error, fmt.Errorf("request %d: %v", r.TotalRequests, err))
} else {
r.SuccessfulRequests += count
}
}

func (r Result) PercentSuccess() float64 {
return float64(r.SuccessfulRequests) / float64(r.TotalRequests)
}

// CheckSuccessRate asserts that a minimum success threshold was met.
func (r Result) CheckSuccessRate(t test.Failer, minimumPercent float64) {
t.Helper()
if r.PercentSuccess() < minimumPercent {
t.Fatalf("Minimum success threshold, %f, was not met. %d/%d (%f) requests failed: %v",
minimumPercent, r.SuccessfulRequests, r.TotalRequests, r.PercentSuccess(), r.Error)
}
if r.SuccessfulRequests == r.TotalRequests {
t.Logf("traffic checker succeeded with all successful requests (%d/%d)", r.SuccessfulRequests, r.TotalRequests)
} else {
t.Logf("traffic checker met minimum threshold, with %d/%d successes, but encountered some failures: %v", r.SuccessfulRequests, r.TotalRequests, r.Error)
}
}
Loading
Loading