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

chore: consolidate tailing aws logs to use the Go SDK #133

Open
edulop91 opened this issue Mar 1, 2022 · 0 comments
Open

chore: consolidate tailing aws logs to use the Go SDK #133

edulop91 opened this issue Mar 1, 2022 · 0 comments

Comments

@edulop91
Copy link
Contributor

edulop91 commented Mar 1, 2022

We should phase out shelling out to external dependencies and instead directly use Go clients + sdks. One particular example is we have 2 paths for tailing aws logs:

  • aws cli --
    func (s *Orchestrator) Logs(stackName string, service string, since string) error {
    // TODO get logs path from ECS instead of generating
    logPrefix := s.backend.Conf().LogGroupPrefix()
    logPath := fmt.Sprintf("%s/%s/%s", logPrefix, stackName, service)
    awsProfile := s.backend.Conf().AwsProfile()
    regionName := "us-west-2"
    awsArgs := []string{"aws", "--profile", awsProfile, "--region", regionName, "logs", "tail", "--since", since, "--follow", logPath}
    awsCmd, err := exec.LookPath("aws")
    if err != nil {
    return errors.Wrap(err, "failed to locate the AWS cli")
    }
    cmd := &exec.Cmd{
    Path: awsCmd,
    Args: awsArgs,
    Stderr: os.Stderr,
    Stdout: os.Stdout,
    }
    log.Println(cmd)
    if err := s.executor.Run(cmd); err != nil {
    return errors.Wrap(err, "failed to get logs from AWS")
    }
    return nil
    }
  • go sdk --
    package aws
    import (
    "context"
    cwlv2 "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs"
    )
    type GetLogsFunc func(*cwlv2.GetLogEventsOutput, error) error
    func (b *Backend) getLogs(
    ctx context.Context,
    input *cwlv2.GetLogEventsInput,
    f GetLogsFunc,
    ) error {
    paginator := cwlv2.NewGetLogEventsPaginator(
    b.cwlGetLogEventsAPIClient,
    input,
    )
    for paginator.HasMorePages() {
    err := f(paginator.NextPage(ctx))
    if isStop(err) {
    return nil
    }
    if err != nil {
    return err
    }
    }
    return nil
    }

We should get rid of the aws cli path and replace it with the Go SDK path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant