Make case insensitive container status comparison (#5954)

This commit is contained in:
Daniel Nelson 2019-06-05 03:00:59 -07:00 committed by GitHub
parent ba0b0c02f7
commit 8bc768b239
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 8 deletions

View File

@ -28,7 +28,9 @@ present in the metadata/stats endpoints.
# container_name_exclude = [] # container_name_exclude = []
## Container states to include and exclude. Globs accepted. ## Container states to include and exclude. Globs accepted.
## When empty only containers in the "running" state will be captured. ## When empty only containers in the "RUNNING" state will be captured.
## Possible values are "NONE", "PULLED", "CREATED", "RUNNING",
## "RESOURCES_PROVISIONED", "STOPPED".
# container_status_include = [] # container_status_include = []
# container_status_exclude = [] # container_status_exclude = []
@ -37,8 +39,8 @@ present in the metadata/stats endpoints.
ecs_label_include = [ "com.amazonaws.ecs.*" ] ecs_label_include = [ "com.amazonaws.ecs.*" ]
ecs_label_exclude = [] ecs_label_exclude = []
## Timeout for docker list, info, and stats commands ## Timeout for queries.
timeout = "5s" # timeout = "5s"
``` ```
### Metrics ### Metrics

View File

@ -2,6 +2,7 @@ package ecs
import ( import (
"net/url" "net/url"
"strings"
"time" "time"
"github.com/influxdata/telegraf" "github.com/influxdata/telegraf"
@ -51,7 +52,9 @@ var sampleConfig = `
# container_name_exclude = [] # container_name_exclude = []
## Container states to include and exclude. Globs accepted. ## Container states to include and exclude. Globs accepted.
## When empty only containers in the "running" state will be captured. ## When empty only containers in the "RUNNING" state will be captured.
## Possible values are "NONE", "PULLED", "CREATED", "RUNNING",
## "RESOURCES_PROVISIONED", "STOPPED".
# container_status_include = [] # container_status_include = []
# container_status_exclude = [] # container_status_exclude = []
@ -60,8 +63,8 @@ var sampleConfig = `
ecs_label_include = [ "com.amazonaws.ecs.*" ] ecs_label_include = [ "com.amazonaws.ecs.*" ]
ecs_label_exclude = [] ecs_label_exclude = []
## Timeout for docker list, info, and stats commands ## Timeout for queries.
timeout = "5s" # timeout = "5s"
` `
// Description describes ECS plugin // Description describes ECS plugin
@ -157,7 +160,7 @@ func (ecs *Ecs) accContainers(task *Task, taskTags map[string]string, acc telegr
continue continue
} }
if !ecs.statusFilter.Match(c.KnownStatus) { if !ecs.statusFilter.Match(strings.ToUpper(c.KnownStatus)) {
continue continue
} }
@ -215,8 +218,17 @@ func (ecs *Ecs) createLabelFilters() error {
func (ecs *Ecs) createContainerStatusFilters() error { func (ecs *Ecs) createContainerStatusFilters() error {
if len(ecs.ContainerStatusInclude) == 0 && len(ecs.ContainerStatusExclude) == 0 { if len(ecs.ContainerStatusInclude) == 0 && len(ecs.ContainerStatusExclude) == 0 {
ecs.ContainerStatusInclude = []string{"running"} ecs.ContainerStatusInclude = []string{"RUNNING"}
} }
// ECS uses uppercase status names, normalizing for comparison.
for i, include := range ecs.ContainerStatusInclude {
ecs.ContainerStatusInclude[i] = strings.ToUpper(include)
}
for i, exclude := range ecs.ContainerStatusExclude {
ecs.ContainerStatusExclude[i] = strings.ToUpper(exclude)
}
filter, err := filter.NewIncludeExcludeFilter(ecs.ContainerStatusInclude, ecs.ContainerStatusExclude) filter, err := filter.NewIncludeExcludeFilter(ecs.ContainerStatusInclude, ecs.ContainerStatusExclude)
if err != nil { if err != nil {
return err return err