@@ -27,6 +27,11 @@ import (
27
27
"github.com/signalfx/signalfx-agent/pkg/utils/filter"
28
28
)
29
29
30
+ const (
31
+ ctrNameDim = "container_name"
32
+ ctrIDDim = "container_id"
33
+ )
34
+
30
35
var logger = log .WithFields (log.Fields {"monitorType" : monitorType })
31
36
32
37
func init () {
@@ -53,8 +58,12 @@ type Config struct {
53
58
// A list of filters of images to exclude. Supports literals, globs, and
54
59
// regex.
55
60
ExcludedImages []string `yaml:"excludedImages"`
61
+ // The dimension to update with `known_status` property syncing. Supported options are "container_name" (default) and "container_id".
62
+ DimensionToUpdate string `yaml:"dimensionToUpdate" default:"container_name"`
56
63
}
57
64
65
+ type dimensionValueFn func (ctr ecs.Container ) (string , string )
66
+
58
67
// Monitor for ECS Metadata
59
68
type Monitor struct {
60
69
Output types.FilteringOutput
@@ -68,9 +77,10 @@ type Monitor struct {
68
77
// shouldIgnore - key : container docker id, tells if stats for the container should be ignored.
69
78
// Usually the container was filtered out by excludedImages
70
79
// or container metadata is not received.
71
- shouldIgnore map [string ]bool
72
- imageFilter filter.StringFilter
73
- logger log.FieldLogger
80
+ shouldIgnore map [string ]bool
81
+ imageFilter filter.StringFilter
82
+ logger log.FieldLogger
83
+ dimensionToUpdate dimensionValueFn
74
84
}
75
85
76
86
// Configure the monitor and kick off volume metric syncing
@@ -82,6 +92,14 @@ func (m *Monitor) Configure(conf *Config) error {
82
92
return fmt .Errorf ("could not load excluded image filter: %w" , err )
83
93
}
84
94
95
+ if conf .DimensionToUpdate == ctrNameDim {
96
+ m .dimensionToUpdate = func (ctr ecs.Container ) (string , string ) { return ctrNameDim , ctr .Name }
97
+ } else if conf .DimensionToUpdate == ctrIDDim {
98
+ m .dimensionToUpdate = func (ctr ecs.Container ) (string , string ) { return ctrIDDim , ctr .DockerID }
99
+ } else {
100
+ return fmt .Errorf ("unsupported `dimensionToUpdate` %q. Must be one of %q or %q" , conf .DimensionToUpdate , ctrNameDim , ctrIDDim )
101
+ }
102
+
85
103
m .conf = conf
86
104
m .timeout = time .Duration (conf .TimeoutSeconds ) * time .Second
87
105
m .client = & http.Client {
@@ -202,9 +220,10 @@ func (m *Monitor) fetchStatsForAll(enhancedMetricsConfig dmonitor.EnhancedMetric
202
220
203
221
m .Output .SendDatapoints (dps ... )
204
222
223
+ name , value := m .dimensionToUpdate (container )
205
224
containerProps := & types.Dimension {
206
- Name : "container_name" ,
207
- Value : container . Name ,
225
+ Name : name ,
226
+ Value : value ,
208
227
Properties : map [string ]string {"known_status" : container .KnownStatus },
209
228
Tags : nil ,
210
229
}
@@ -301,10 +320,10 @@ func getTaskLimitMetrics(container ecs.Container, enhancedMetricsConfig dmonitor
301
320
cpuDp .Dimensions = map [string ]string {}
302
321
cpuDp .Dimensions ["plugin" ] = "ecs"
303
322
name := strings .TrimPrefix (container .Name , "/" )
304
- cpuDp .Dimensions ["container_name" ] = name
323
+ cpuDp .Dimensions [ctrNameDim ] = name
305
324
cpuDp .Dimensions ["plugin_instance" ] = name
306
325
cpuDp .Dimensions ["container_image" ] = container .Image
307
- cpuDp .Dimensions ["container_id" ] = container .DockerID
326
+ cpuDp .Dimensions [ctrNameDim ] = container .DockerID
308
327
cpuDp .Dimensions ["container_hostname" ] = container .Networks [0 ].IPAddresses [0 ]
309
328
310
329
taskLimitDps = append (taskLimitDps , cpuDp )
0 commit comments