Skip to content

Commit

Permalink
[#3564] Do not fetch metrics if services don't have any process
Browse files Browse the repository at this point in the history
`ProcessList` will return an "empty" slice.

Changed the `cloudwatchMetrics` function to return a message for empty metrics queries.
  • Loading branch information
Twsouza committed Aug 17, 2022
1 parent f86baea commit 28bb6b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions provider/aws/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ var (
)

func (p *Provider) cloudwatchMetrics(mdqs []metricDataQuerier, opts structs.MetricsOptions) (structs.Metrics, error) {
if len(mdqs) == 0 {
return nil, fmt.Errorf("can't fetch metrics with empty query")
}

period := ci(opts.Period, 3600)

req := &cloudwatch.GetMetricDataInput{
Expand Down
3 changes: 3 additions & 0 deletions provider/aws/processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ func (p *Provider) ProcessList(app string, opts structs.ProcessListOptions) (str
}

mdqs := p.servicesMetricQueries(serviceNames)
if len(mdqs) == 0 {
return ps, nil
}

ms, err := p.cloudwatchMetrics(mdqs, structs.MetricsOptions{
Start: aws.Time(time.Now().Add(-5 * time.Minute)),
Expand Down

0 comments on commit 28bb6b3

Please sign in to comment.