Skip to content

Commit

Permalink
chore: handle metric deprication of terminated_reason
Browse files Browse the repository at this point in the history
  • Loading branch information
rawkode committed Jun 16, 2020
1 parent 0a19601 commit 41302b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions plugins/inputs/kube_inventory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ avoid cardinality issues:
# tls_key = "/path/to/keyfile"
## Use TLS but skip chain & host verification
# insecure_skip_verify = false

## Uncomment to remove deprecated metrics.
# fielddrop = ["terminated_reason"]
```

#### Kubernetes Permissions
Expand Down Expand Up @@ -212,6 +215,7 @@ subjects:
- restarts_total
- state_code
- state_reason
- terminated_reason (string, deprecated in 1.15: use `state_reason` instead)
- resource_requests_cpu_units
- resource_requests_memory_bytes
- resource_limits_cpu_units
Expand Down
11 changes: 7 additions & 4 deletions plugins/inputs/kube_inventory/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,28 @@ func gatherPodContainer(nodeName string, p v1.Pod, cs v1.ContainerStatus, c v1.C
stateReason = cs.State.Waiting.GetReason()
}

ready := "unready"
readiness := "unready"
if cs.GetReady() {
ready = "ready"
readiness = "ready"
}

fields := map[string]interface{}{
"restarts_total": cs.GetRestartCount(),
"state_code": stateCode,
"state_reason": stateReason,
"terminated_reason": cs.State.Terminated.GetReason(),
}

if stateReason != "" {
fields["state_reason"] = stateReason
}

tags := map[string]string{
"container_name": *c.Name,
"namespace": *p.Metadata.Namespace,
"node_name": *p.Spec.NodeName,
"pod_name": *p.Metadata.Name,
"state": state,
"ready": ready,
"readiness": readiness,
}

req := c.Resources.Requests
Expand Down

0 comments on commit 41302b1

Please sign in to comment.