Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue parsing kubernetes json #2287

Closed
lpic10 opened this issue Jan 18, 2017 · 0 comments
Closed

Issue parsing kubernetes json #2287

lpic10 opened this issue Jan 18, 2017 · 0 comments
Labels
bug unexpected problem or unintended behavior
Milestone

Comments

@lpic10
Copy link
Contributor

lpic10 commented Jan 18, 2017

Bug report

Using latest telegraf (built from master), kubernetes v1.2

Explanation: when a pod is stopped, the k8s API returns a null startTime for the podRef, as below:

{
			"podRef" : {
				"name" : "mypod-kxgfd",
				"namespace" : "default",
				"uid" : "2533197d-d110-11e6-b4b8-005056835c46"
			},
			"startTime" : null,
			"containers" : [{
					"name" : "mycontainer",
					"startTime" : "2017-01-02T17:24:14Z",
					"cpu" : {
						"time" : "2017-01-18T12:53:19Z",
						"usageNanoCores" : 0,
						"usageCoreNanoSeconds" : 0
					},
					"memory" : {
						"time" : "2017-01-18T12:53:19Z",
						"usageBytes" : 0,
						"workingSetBytes" : 0,
						"pageFaults" : 0,
						"majorPageFaults" : 0
					},
					"rootfs" : {
						"availableBytes" : 85094039552,
						"capacityBytes" : 107151884288
					},
					"logs" : {
						"availableBytes" : 2861916160,
						"capacityBytes" : 3103539200
					},
					"userDefinedMetrics" : null
				}
			]
		}

That causes the following error message in Telegraf:

2017-01-18T13:57:30Z E! ERROR in input [inputs.kubernetes]: Errors encountered: [Error parsing response: parsing time "null" as ""2006-01-02T15:04:05Z07:00"": cannot parse "null" as """]

That causes the whole kubernetes metrics to not be collected correctly if there is a single pod stopped.
The modification below has fixed it for me, but I'm not sure it is the best way of doing this:

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

@sparrc sparrc added the bug unexpected problem or unintended behavior label Jan 21, 2017
@sparrc sparrc added this to the 1.3.0 milestone Jan 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants