mirror of
https://github.com/openziti/zrok.git
synced 2025-06-20 01:37:52 +02:00
better loop/run wiring; status every
This commit is contained in:
parent
055167b644
commit
9e4a5f47d9
@ -25,9 +25,10 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type run struct {
|
type run struct {
|
||||||
cmd *cobra.Command
|
cmd *cobra.Command
|
||||||
loopers int
|
loopers int
|
||||||
iterations int
|
iterations int
|
||||||
|
statusEvery int
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRun() *run {
|
func newRun() *run {
|
||||||
@ -40,13 +41,14 @@ func newRun() *run {
|
|||||||
cmd.Run = r.run
|
cmd.Run = r.run
|
||||||
cmd.Flags().IntVarP(&r.loopers, "loopers", "l", 1, "Number of current loopers to start")
|
cmd.Flags().IntVarP(&r.loopers, "loopers", "l", 1, "Number of current loopers to start")
|
||||||
cmd.Flags().IntVarP(&r.iterations, "iterations", "i", 1, "Number of iterations per looper")
|
cmd.Flags().IntVarP(&r.iterations, "iterations", "i", 1, "Number of iterations per looper")
|
||||||
|
cmd.Flags().IntVarP(&r.statusEvery, "status-every", "e", 100, "Show status every # iterations")
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *run) run(_ *cobra.Command, _ []string) {
|
func (r *run) run(_ *cobra.Command, _ []string) {
|
||||||
var loopers []*looper
|
var loopers []*looper
|
||||||
for i := 0; i < r.loopers; i++ {
|
for i := 0; i < r.loopers; i++ {
|
||||||
l := newLooper(i, r.iterations)
|
l := newLooper(i, r)
|
||||||
loopers = append(loopers, l)
|
loopers = append(loopers, l)
|
||||||
go l.run()
|
go l.run()
|
||||||
}
|
}
|
||||||
@ -56,17 +58,17 @@ func (r *run) run(_ *cobra.Command, _ []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type looper struct {
|
type looper struct {
|
||||||
id int
|
id int
|
||||||
iterations int
|
runi *run
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
listener edge.Listener
|
listener edge.Listener
|
||||||
}
|
}
|
||||||
|
|
||||||
func newLooper(id, iterations int) *looper {
|
func newLooper(id int, runi *run) *looper {
|
||||||
return &looper{
|
return &looper{
|
||||||
id: id,
|
id: id,
|
||||||
iterations: iterations,
|
runi: runi,
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,13 +101,13 @@ func (l *looper) run() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Infof("service: %v, frontend: %v", tunnelResp.Payload.Service, tunnelResp.Payload.ProxyEndpoint)
|
logrus.Infof("looper #%d, service: %v, frontend: %v", l.id, tunnelResp.Payload.Service, tunnelResp.Payload.ProxyEndpoint)
|
||||||
go l.serviceListener(zif, tunnelResp.Payload.Service)
|
go l.serviceListener(zif, tunnelResp.Payload.Service)
|
||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
for i := 0; i < l.iterations; i++ {
|
for i := 0; i < l.runi.iterations; i++ {
|
||||||
if i > 0 && i%10 == 0 {
|
if i > 0 && i%l.runi.statusEvery == 0 {
|
||||||
logrus.Infof("looper #%d: iteration #%d", l.id, i)
|
logrus.Infof("looper #%d: iteration #%d", l.id, i)
|
||||||
}
|
}
|
||||||
outpayload := make([]byte, 10240)
|
outpayload := make([]byte, 10240)
|
||||||
@ -118,22 +120,22 @@ func (l *looper) run() {
|
|||||||
io.Copy(inpayload, resp.Body)
|
io.Copy(inpayload, resp.Body)
|
||||||
inbase64 := inpayload.String()
|
inbase64 := inpayload.String()
|
||||||
if inbase64 != outbase64 {
|
if inbase64 != outbase64 {
|
||||||
logrus.Errorf("payload mismatch!")
|
logrus.Errorf("looper #%d payload mismatch!", l.id)
|
||||||
} else {
|
} else {
|
||||||
logrus.Debugf("payload match")
|
logrus.Debugf("looper #%d payload match", l.id)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logrus.Errorf("error: %v", err)
|
logrus.Errorf("looper #%d error: %v", l.id, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logrus.Errorf("error creating request: %v", err)
|
logrus.Errorf("looper #%d error creating request: %v", l.id, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logrus.Infof("looper #%d: complete", l.id)
|
logrus.Infof("looper #%d: complete", l.id)
|
||||||
|
|
||||||
if l.listener != nil {
|
if l.listener != nil {
|
||||||
if err := l.listener.Close(); err != nil {
|
if err := l.listener.Close(); err != nil {
|
||||||
logrus.Errorf("error closing listener: %v", err)
|
logrus.Errorf("looper #%d error closing listener: %v", l.id, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,10 +161,10 @@ func (l *looper) serviceListener(zitiIdPath string, svcId string) {
|
|||||||
}
|
}
|
||||||
if l.listener, err = ziti.NewContextWithConfig(zcfg).ListenWithOptions(svcId, &opts); err == nil {
|
if l.listener, err = ziti.NewContextWithConfig(zcfg).ListenWithOptions(svcId, &opts); err == nil {
|
||||||
if err := http.Serve(l.listener, l); err != nil {
|
if err := http.Serve(l.listener, l); err != nil {
|
||||||
logrus.Errorf("error serving: %v", err)
|
logrus.Errorf("looper #%d, error serving: %v", l.id, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logrus.Errorf("error listening: %v", err)
|
logrus.Errorf("looper #%d, error listening: %v", l.id, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user