Kubernetes input: Handle null startTime for stopped pods (#2335)

This commit is contained in:
James Gregory 2017-02-02 01:41:04 +11:00 committed by Cameron Sparr
parent c528c53e5b
commit eafd1dcc7c
2 changed files with 43 additions and 1 deletions

View File

@ -45,7 +45,7 @@ type CPUMetrics struct {
// PodMetrics contains metric data on a given pod // PodMetrics contains metric data on a given pod
type PodMetrics struct { type PodMetrics struct {
PodRef PodReference `json:"podRef"` PodRef PodReference `json:"podRef"`
StartTime time.Time `json:"startTime"` StartTime *time.Time `json:"startTime"`
Containers []ContainerMetrics `json:"containers"` Containers []ContainerMetrics `json:"containers"`
Network NetworkMetrics `json:"network"` Network NetworkMetrics `json:"network"`
Volumes []VolumeMetrics `json:"volume"` Volumes []VolumeMetrics `json:"volume"`

View File

@ -92,6 +92,29 @@ func TestKubernetesStats(t *testing.T) {
} }
acc.AssertContainsTaggedFields(t, "kubernetes_pod_container", fields, tags) acc.AssertContainsTaggedFields(t, "kubernetes_pod_container", fields, tags)
fields = map[string]interface{}{
"cpu_usage_nanocores": int64(846503),
"cpu_usage_core_nanoseconds": int64(56507553554),
"memory_usage_bytes": int64(0),
"memory_working_set_bytes": int64(0),
"memory_rss_bytes": int64(0),
"memory_page_faults": int64(0),
"memory_major_page_faults": int64(0),
"rootfs_available_bytes": int64(0),
"rootfs_capacity_bytes": int64(0),
"rootfs_used_bytes": int64(0),
"logsfs_avaialble_bytes": int64(0),
"logsfs_capacity_bytes": int64(0),
"logsfs_used_bytes": int64(0),
}
tags = map[string]string{
"node_name": "node1",
"container_name": "stopped-container",
"namespace": "foons",
"pod_name": "stopped-pod",
}
acc.AssertContainsTaggedFields(t, "kubernetes_pod_container", fields, tags)
fields = map[string]interface{}{ fields = map[string]interface{}{
"available_bytes": int64(7903948800), "available_bytes": int64(7903948800),
"capacity_bytes": int64(7903961088), "capacity_bytes": int64(7903961088),
@ -284,6 +307,25 @@ var response = `
"name": "volume4" "name": "volume4"
} }
] ]
},
{
"podRef": {
"name": "stopped-pod",
"namespace": "foons",
"uid": "da7c1865-d67d-4688-b679-c485ed44b2aa"
},
"startTime": null,
"containers": [
{
"name": "stopped-container",
"startTime": "2016-09-26T18:46:43Z",
"cpu": {
"time": "2016-09-27T16:57:32Z",
"usageNanoCores": 846503,
"usageCoreNanoSeconds": 56507553554
}
}
]
} }
] ]
}` }`