mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-06-20 04:04:21 -04:00
cdbg: make endpoint deployment failure more transparent (#1883)
* add retry + timeout + intercept grpc logs * LogStateChanges inside grplog pkg * remove retry and tj/assert * rename nit * Update debugd/internal/cdbg/cmd/deploy.go Co-authored-by: Paul Meyer <49727155+katexochen@users.noreply.github.com> * Update debugd/internal/cdbg/cmd/deploy.go Co-authored-by: Paul Meyer <49727155+katexochen@users.noreply.github.com> * paul feedback * return waitFn instead of WaitGroup * Revert "return waitFn instead of WaitGroup" This reverts commit 45700f30e341ce3af509b687febbc0125f7ddb38. * log routine inside debugd constructor * test doubles names * Update debugd/internal/cdbg/cmd/deploy.go Co-authored-by: Paul Meyer <49727155+katexochen@users.noreply.github.com> * fix newDebugClient closeFn --------- Co-authored-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
parent
167052d443
commit
e738f15f0f
8 changed files with 221 additions and 53 deletions
53
internal/grpc/grpclog/grpclog.go
Normal file
53
internal/grpc/grpclog/grpclog.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
// grpclog provides a logging utilities for gRPC.
|
||||
package grpclog
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"google.golang.org/grpc/connectivity"
|
||||
"google.golang.org/grpc/peer"
|
||||
)
|
||||
|
||||
// PeerAddrFromContext returns a peer's address from context, or "unknown" if not found.
|
||||
func PeerAddrFromContext(ctx context.Context) string {
|
||||
p, ok := peer.FromContext(ctx)
|
||||
if !ok {
|
||||
return "unknown"
|
||||
}
|
||||
return p.Addr.String()
|
||||
}
|
||||
|
||||
// LogStateChangesUntilReady logs the state changes of a gRPC connection.
|
||||
func LogStateChangesUntilReady(ctx context.Context, conn getStater, log debugLog, wg *sync.WaitGroup, isReadyCallback func()) {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
state := conn.GetState()
|
||||
log.Debugf("Connection state started as %s", state)
|
||||
for ; state != connectivity.Ready && conn.WaitForStateChange(ctx, state); state = conn.GetState() {
|
||||
log.Debugf("Connection state changed to %s", state)
|
||||
}
|
||||
if state == connectivity.Ready {
|
||||
log.Debugf("Connection ready")
|
||||
isReadyCallback()
|
||||
} else {
|
||||
log.Debugf("Connection state ended with %s", state)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
type getStater interface {
|
||||
GetState() connectivity.State
|
||||
WaitForStateChange(context.Context, connectivity.State) bool
|
||||
}
|
||||
|
||||
type debugLog interface {
|
||||
Debugf(format string, args ...any)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue