Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: filter out container name if empty #3238

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/COVERAGE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15.32
15.31
4 changes: 4 additions & 0 deletions cli/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions shared/backend/aws/k8s_compute_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
Loading