Skip to content
This repository has been archived by the owner on Feb 22, 2021. It is now read-only.

Commit

Permalink
Make MaxStreams configurable: (#28)
Browse files Browse the repository at this point in the history
- Add a `--max-streams, -m` flag to list and fetch.  Note that for
  fetch's which do not use a `-t`/prefix flag, we can't control the maximum.
  • Loading branch information
dfuentes committed Jan 12, 2018
1 parent b216ff0 commit 5bec34d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var (
until string
verbose bool
raw bool
maxStreams int
)

// Error messages
Expand All @@ -65,6 +66,7 @@ func init() {
fetchCmd.Flags().StringVarP(&until, "until", "u", "now", "Fetch logs until timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)")
fetchCmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Verbose log output (includes log context in data fields)")
fetchCmd.Flags().BoolVarP(&raw, "raw", "r", false, "Raw JSON output")
fetchCmd.Flags().IntVarP(&maxStreams, "max-streams", "m", 100, "Maximum number of streams to fetch from (for prefix search)")
}

func fetch(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -92,6 +94,8 @@ func fetch(cmd *cobra.Command, args []string) error {
}
}

lib.SetMaxStreams(maxStreams)

logReader, err := lib.NewCloudwatchLogsReader(args[0], task, start, end)
if err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func init() {
listCmd.Flags().StringVarP(&task, "task", "t", "", "")
listCmd.Flags().StringVarP(&since, "since", "s", "1h", "Show logs streams with activity since timestamp (e.g. 2013-01-02T13:23:37), relative (e.g. 42m for 42 minutes), or all for all logs")
listCmd.Flags().StringVarP(&until, "until", "u", "now", "Show log streams until timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)")
listCmd.Flags().IntVarP(&maxStreams, "max-streams", "m", 100, "Maximum number of streams to list")
}

func list(cmd *cobra.Command, args []string) error {
Expand All @@ -46,6 +47,8 @@ func list(cmd *cobra.Command, args []string) error {
}
}

lib.SetMaxStreams(maxStreams)

logReader, err := lib.NewCloudwatchLogsReader(args[0], task, start, end)
if err != nil {
return err
Expand Down
8 changes: 8 additions & 0 deletions lib/cwreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (
const (
// MaxEventsPerCall is the maximum number events from a filter call
MaxEventsPerCall = 10000
)

var (
// MaxStreams is the maximum number of streams you can give to a filter call
MaxStreams = 100
)
Expand All @@ -32,6 +35,11 @@ type CloudwatchLogsReader struct {
streamPrefix string
}

// Set the maximum number of streams for describe/filter calls
func SetMaxStreams(max int) {
MaxStreams = max
}

// NewCloudwatchLogsReader takes a group and optionally a stream prefix, start and
// end time, and returns a reader for any logs that match those parameters.
func NewCloudwatchLogsReader(group string, streamPrefix string, start time.Time, end time.Time) (*CloudwatchLogsReader, error) {
Expand Down

0 comments on commit 5bec34d

Please sign in to comment.