mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-08-07 22:42:22 -04:00
cli: log grpc connection state for init call (#1324)
This is a measure to detect cases where an aTLS handshake is performed but the long running call is interrupted, leading to a retry of the init call. Whenever the grpc connection state reaches ready, we know that the aTLS handshake has succeeded: > READY: The channel has successfully established a connection all the way through TLS handshake (or equivalent) and protocol-level (HTTP/2, etc) handshaking, and all subsequent attempt to communicate have succeeded (or are pending without any known failure).
This commit is contained in:
parent
f0db5d0395
commit
8ad04f7dbb
1 changed files with 27 additions and 0 deletions
|
@ -15,6 +15,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"sync"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -40,6 +41,7 @@ import (
|
||||||
"github.com/spf13/afero"
|
"github.com/spf13/afero"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/connectivity"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||||
|
@ -232,6 +234,15 @@ func (d *initDoer) Do(ctx context.Context) error {
|
||||||
return fmt.Errorf("dialing init server: %w", err)
|
return fmt.Errorf("dialing init server: %w", err)
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
defer wg.Wait()
|
||||||
|
|
||||||
|
grpcStateLogCtx, grpcStateLogCancel := context.WithCancel(ctx)
|
||||||
|
defer grpcStateLogCancel()
|
||||||
|
wg.Add(1)
|
||||||
|
d.logGRPCStateChanges(grpcStateLogCtx, &wg, conn)
|
||||||
|
|
||||||
protoClient := initproto.NewAPIClient(conn)
|
protoClient := initproto.NewAPIClient(conn)
|
||||||
d.log.Debugf("Created protoClient")
|
d.log.Debugf("Created protoClient")
|
||||||
resp, err := protoClient.Init(ctx, d.req)
|
resp, err := protoClient.Init(ctx, d.req)
|
||||||
|
@ -242,6 +253,22 @@ func (d *initDoer) Do(ctx context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *initDoer) logGRPCStateChanges(ctx context.Context, wg *sync.WaitGroup, conn *grpc.ClientConn) {
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
state := conn.GetState()
|
||||||
|
d.log.Debugf("Connection state started as %s", state)
|
||||||
|
for ; state != connectivity.Ready && conn.WaitForStateChange(ctx, state); state = conn.GetState() {
|
||||||
|
d.log.Debugf("Connection state changed to %s", state)
|
||||||
|
}
|
||||||
|
if state == connectivity.Ready {
|
||||||
|
d.log.Debugf("Connection ready")
|
||||||
|
} else {
|
||||||
|
d.log.Debugf("Connection state ended with %s", state)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
func (i *initCmd) writeOutput(
|
func (i *initCmd) writeOutput(
|
||||||
idFile clusterid.File, resp *initproto.InitResponse, mergeConfig bool, wr io.Writer, fileHandler file.Handler,
|
idFile clusterid.File, resp *initproto.InitResponse, mergeConfig bool, wr io.Writer, fileHandler file.Handler,
|
||||||
) error {
|
) error {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue