@@ -81,10 +81,10 @@ type containerHandler struct {
8181 // The IP address of the container
8282 ipAddress string
8383
84- includedMetrics container.MetricSet
84+ metrics container.MetricSet
8585
8686 // the devicemapper poolname
87- poolName string
87+ thinPoolName string
8888
8989 // zfsParent is the parent for docker zfs
9090 zfsParent string
@@ -127,7 +127,7 @@ func newContainerHandler(
127127 inHostNamespace bool ,
128128 metadataEnvAllowList []string ,
129129 dockerVersion []int ,
130- includedMetrics container.MetricSet ,
130+ metrics container.MetricSet ,
131131 thinPoolName string ,
132132 thinPoolWatcher * devicemapper.ThinPoolWatcher ,
133133 zfsWatcher * zfs.ZfsWatcher ,
@@ -187,19 +187,18 @@ func newContainerHandler(
187187 }
188188
189189 // Do not report network metrics for containers that share netns with another container.
190- metrics := common .RemoveNetMetrics (includedMetrics , ctnr .HostConfig .NetworkMode .IsContainer ())
190+ includedMetrics := common .RemoveNetMetrics (metrics , ctnr .HostConfig .NetworkMode .IsContainer ())
191191
192- // TODO: extract object mother method
193192 handler := & containerHandler {
194193 machineInfoFactory : machineInfoFactory ,
195194 cgroupPaths : cgroupPaths ,
196- fsInfo : fsInfo ,
197195 storageDriver : storageDriver ,
198- poolName : thinPoolName ,
196+ fsInfo : fsInfo ,
199197 rootfsStorageDir : rootfsStorageDir ,
200198 envs : make (map [string ]string ),
201199 labels : ctnr .Config .Labels ,
202- includedMetrics : metrics ,
200+ metrics : includedMetrics ,
201+ thinPoolName : thinPoolName ,
203202 zfsParent : zfsParent ,
204203 }
205204 // Health status may be nil if no health check is configured
@@ -209,7 +208,6 @@ func newContainerHandler(
209208 // Timestamp returned by Docker is in time.RFC3339Nano format.
210209 handler .creationTime , err = time .Parse (time .RFC3339Nano , ctnr .Created )
211210 if err != nil {
212- // This should not happen, report the error just in case
213211 return nil , fmt .Errorf ("failed to parse the create timestamp %q for container %q: %v" , ctnr .Created , id , err )
214212 }
215213 handler .libcontainerHandler = containerlibcontainer .NewHandler (cgroupManager , rootFs , ctnr .State .Pid , metrics )
@@ -222,7 +220,7 @@ func newContainerHandler(
222220 Namespace : DockerNamespace ,
223221 }
224222 handler .image = ctnr .Config .Image
225- // Only adds restartcount label if it's greater than 0
223+
226224 if ctnr .RestartCount > 0 {
227225 handler .labels ["restartcount" ] = strconv .Itoa (ctnr .RestartCount )
228226 }
@@ -236,11 +234,10 @@ func newContainerHandler(
236234 containerID := strings .TrimPrefix (networkMode , "container:" )
237235 c , err := client .ContainerInspect (context .Background (), containerID )
238236 if err != nil {
239- return nil , fmt .Errorf ("failed to inspect container %q: %v" , id , err )
237+ return nil , fmt .Errorf ("failed to inspect container %q: %v" , containerID , err )
240238 }
241239 ipAddress = c .NetworkSettings .IPAddress
242240 }
243-
244241 handler .ipAddress = ipAddress
245242
246243 if includedMetrics .Has (container .DiskUsageMetrics ) {
@@ -253,7 +250,7 @@ func newContainerHandler(
253250 }
254251 }
255252
256- // split env vars to get metadata map.
253+ // Split env vars to get metadata map.
257254 for _ , exposedEnv := range metadataEnvAllowList {
258255 if exposedEnv == "" {
259256 // if no dockerEnvWhitelist provided, len(metadataEnvAllowList) == 1, metadataEnvAllowList[0] == ""
@@ -296,25 +293,13 @@ func DetermineDeviceStorage(storageDriver StorageDriver, storageDir string, rwLa
296293 return
297294}
298295
299- func (h * containerHandler ) Start () {
300- if h .fsHandler != nil {
301- h .fsHandler .Start ()
302- }
303- }
304-
305- func (h * containerHandler ) Cleanup () {
306- if h .fsHandler != nil {
307- h .fsHandler .Stop ()
308- }
309- }
310-
311296func (h * containerHandler ) ContainerReference () (info.ContainerReference , error ) {
312297 return h .reference , nil
313298}
314299
315300func (h * containerHandler ) GetSpec () (info.ContainerSpec , error ) {
316- hasFilesystem := h .includedMetrics .Has (container .DiskUsageMetrics )
317- hasNetwork := h .includedMetrics .Has (container .NetworkUsageMetrics )
301+ hasFilesystem := h .metrics .Has (container .DiskUsageMetrics )
302+ hasNetwork := h .metrics .Has (container .NetworkUsageMetrics )
318303 spec , err := common .GetSpec (h .cgroupPaths , h .machineInfoFactory , hasNetwork , hasFilesystem )
319304 if err != nil {
320305 return info.ContainerSpec {}, err
@@ -337,20 +322,23 @@ func (h *containerHandler) GetStats() (*info.ContainerStats, error) {
337322 stats .Health .Status = h .healthStatus
338323
339324 // Get filesystem stats.
340- err = FsStats (stats , h .machineInfoFactory , h .includedMetrics , h .storageDriver ,
341- h .fsHandler , h .fsInfo , h .poolName , h .rootfsStorageDir , h .zfsParent )
325+ err = FsStats (stats , h .machineInfoFactory , h .metrics , h .storageDriver ,
326+ h .fsHandler , h .fsInfo , h .thinPoolName , h .rootfsStorageDir , h .zfsParent )
342327 if err != nil {
343328 return stats , err
344329 }
345330
346331 return stats , nil
347332}
348333
349- func (h * containerHandler ) ListContainers (listType container.ListType ) ([]info.ContainerReference , error ) {
350- // No-op for Docker driver.
334+ func (h * containerHandler ) ListContainers (container.ListType ) ([]info.ContainerReference , error ) {
351335 return []info.ContainerReference {}, nil
352336}
353337
338+ func (h * containerHandler ) ListProcesses (container.ListType ) ([]int , error ) {
339+ return h .libcontainerHandler .GetProcesses ()
340+ }
341+
354342func (h * containerHandler ) GetCgroupPath (resource string ) (string , error ) {
355343 var res string
356344 if ! cgroups .IsCgroup2UnifiedMode () {
@@ -371,14 +359,22 @@ func (h *containerHandler) GetContainerIPAddress() string {
371359 return h .ipAddress
372360}
373361
374- func (h * containerHandler ) ListProcesses (listType container.ListType ) ([]int , error ) {
375- return h .libcontainerHandler .GetProcesses ()
376- }
377-
378362func (h * containerHandler ) Exists () bool {
379363 return common .CgroupExists (h .cgroupPaths )
380364}
381365
366+ func (h * containerHandler ) Cleanup () {
367+ if h .fsHandler != nil {
368+ h .fsHandler .Stop ()
369+ }
370+ }
371+
372+ func (h * containerHandler ) Start () {
373+ if h .fsHandler != nil {
374+ h .fsHandler .Start ()
375+ }
376+ }
377+
382378func (h * containerHandler ) Type () container.ContainerType {
383379 return container .ContainerTypeDocker
384380}
0 commit comments