From 4dd64d8b58388dbb20595e33bd24c8b8ae02cae0 Mon Sep 17 00:00:00 2001 From: "Han-Ru Chen (Future-Outlier)" Date: Sat, 11 Jan 2025 08:22:13 +0800 Subject: [PATCH] Print K8s Resolver Event for Agent Grpc request debugging (#6146) * Print K8s Resolver Event for Agent Grpc request debugging Signed-off-by: Future-Outlier * update Signed-off-by: Future-Outlier --------- Signed-off-by: Future-Outlier --- flytestdlib/resolver/k8s_resolver.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/flytestdlib/resolver/k8s_resolver.go b/flytestdlib/resolver/k8s_resolver.go index e6c5f6f480..07e1883b77 100644 --- a/flytestdlib/resolver/k8s_resolver.go +++ b/flytestdlib/resolver/k8s_resolver.go @@ -10,6 +10,7 @@ import ( "google.golang.org/grpc/grpclog" "google.golang.org/grpc/resolver" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/kubernetes" @@ -154,9 +155,21 @@ func (k *kResolver) resolve(e *v1.Endpoints) { func (k *kResolver) run() { k.wg.Add(1) defer k.wg.Done() - logger.Infof(k.ctx, "Starting k8s resolver for target: %s", k.target) + + logger.Infof(k.ctx, "Starting k8s resolver for target: [%s], service namespace: [%s], service name: [%s]", k.target, k.target.serviceNamespace, k.target.serviceName) + watcher, err := k.k8sClient.CoreV1().Endpoints(k.target.serviceNamespace).Watch(k.ctx, metav1.ListOptions{FieldSelector: "metadata.name=" + k.target.serviceName}) if err != nil { + logger.Errorf( + k.ctx, + "k8s resolver: failed to create watcher for target [%s]: service namespace: [%s], service name: [%s], "+"error [%v]", + k.target, k.target.serviceNamespace, k.target.serviceName, err, + ) + if statusErr, ok := err.(*errors.StatusError); ok { + logger.Errorf(k.ctx, "k8s resolver: status error details: %v", statusErr.ErrStatus) + } + + logger.Infof(k.ctx, "k8s resolver: failed to create watcher: [%v]", err) grpclog.Errorf("k8s resolver: failed to create watcher: %v", err) return } @@ -166,6 +179,7 @@ func (k *kResolver) run() { case <-k.ctx.Done(): return case event, ok := <-watcher.ResultChan(): + logger.Info(k.ctx, "k8s resolver watcher event response: [%v]", event) if !ok { logger.Debugf(k.ctx, "k8s resolver: watcher closed") return