From 79145333c931230d69f9ee6d0d4271675a5788ab Mon Sep 17 00:00:00 2001 From: Jake Heath <76011913+jakeyheath@users.noreply.github.com> Date: Wed, 17 Apr 2024 12:55:39 -0700 Subject: [PATCH] fix: filter out container name if empty (#3238) --- cli/COVERAGE | 2 +- cli/cmd/logs.go | 4 ++++ shared/backend/aws/k8s_compute_backend.go | 7 +++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cli/COVERAGE b/cli/COVERAGE index ee84c1ddec..784d6f443d 100644 --- a/cli/COVERAGE +++ b/cli/COVERAGE @@ -1 +1 @@ -15.32 \ No newline at end of file +15.31 \ No newline at end of file diff --git a/cli/cmd/logs.go b/cli/cmd/logs.go index 5971e30530..43b9577473 100644 --- a/cli/cmd/logs.go +++ b/cli/cmd/logs.go @@ -11,6 +11,7 @@ import ( "github.com/chanzuckerberg/happy/shared/util" "github.com/chanzuckerberg/happy/shared/workspace_repo" "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -101,6 +102,9 @@ func runLogs(cmd *cobra.Command, args []string) error { opts = append(opts, util.WithSince(util.GetStartTime(ctx).Add(-duration).UnixMilli())) } + if containerName == "" { + logrus.Info("You're missing the container name, use the --container flag to filter the logs further.") + } return b.PrintLogs( util.NewLogGroupContext(ctx, happyClient.HappyConfig.GetLogGroupPrefix()), stackName, diff --git a/shared/backend/aws/k8s_compute_backend.go b/shared/backend/aws/k8s_compute_backend.go index d2d62377e3..3eeba8a913 100644 --- a/shared/backend/aws/k8s_compute_backend.go +++ b/shared/backend/aws/k8s_compute_backend.go @@ -167,8 +167,11 @@ func (k8s *K8SComputeBackend) PrintLogs(ctx context.Context, stackName, serviceN | sort @timestamp desc | limit 20 | filter kubernetes.namespace_name = "%s" -| filter kubernetes.pod_name like "%s-%s" -| filter kubernetes.container_name = "%s"`, k8s.KubeConfig.Namespace, stackName, serviceName, containerName) +| filter kubernetes.pod_name like "%s-%s"`, k8s.KubeConfig.Namespace, stackName, serviceName) + + if containerName != "" { + expression = fmt.Sprintf(`%s\n| filter kubernetes.container_name = "%s"`, expression, containerName) + } logGroup := fmt.Sprintf("/aws/eks/%s/aws-fluentbit-logs", k8s.KubeConfig.ClusterID) if groupPrefix := util.LogGroupFromContext(ctx); groupPrefix != "" {