Skip to content

Commit

Permalink
remove kubernetes.pod.terminating metric (#483)
Browse files Browse the repository at this point in the history
Co-authored-by: Yuqi Jin <[email protected]>
Co-authored-by: Priya Selvaganesan <[email protected]>
  • Loading branch information
Jyuqi and priyaselvaganesan authored Nov 29, 2023
1 parent 252c341 commit d487bc0
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 63 deletions.
29 changes: 0 additions & 29 deletions collector/plugins/sources/kstate/non_running_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ func pointsForNonRunningPods(workloadCache util.WorkloadCache) func(item interfa
now := time.Now().Unix()

points := buildPodPhaseMetrics(pod, transforms, sharedTags, now)
if pod.DeletionTimestamp != nil {
points = append(points, buildPodTerminatingMetrics(pod, sharedTags, transforms, now)...)
}

points = append(points, buildContainerStatusMetrics(pod, sharedTags, transforms, now)...)

Expand Down Expand Up @@ -155,32 +152,6 @@ func buildPodPhaseMetrics(pod *v1.Pod, transforms configuration.Transforms, shar
return points
}

func buildPodTerminatingMetrics(pod *v1.Pod, sharedTags map[string]string, transforms configuration.Transforms, now int64) []wf.Metric {
tags := buildTags("pod_name", pod.Name, pod.Namespace, transforms.Tags)
tags[metrics.LabelMetricSetType.Key] = metrics.MetricSetTypePod
tags[metrics.LabelPodId.Key] = string(pod.UID)
tags["DeletionTimestamp"] = pod.DeletionTimestamp.Format(time.RFC3339)
tags["reason"] = "Terminating"

for _, condition := range pod.Status.Conditions {
// TODO: remove terminating logic from non_running_pods and put them under pod_based_enricher
if condition.Type == v1.PodScheduled && condition.Status == "False" {
tags[metrics.LabelNodename.Key] = "none"
}
}

nodeName := pod.Spec.NodeName
if len(nodeName) > 0 {
sharedTags[metrics.LabelNodename.Key] = nodeName
}

copyTags(sharedTags, tags)
points := []wf.Metric{
metricPoint(transforms.Prefix, "pod.terminating", 1, now, transforms.Source, tags),
}
return points
}

func buildContainerStatusMetrics(pod *v1.Pod, sharedTags map[string]string, transforms configuration.Transforms, now int64) []wf.Metric {
statuses := pod.Status.ContainerStatuses
if len(statuses) == 0 {
Expand Down
33 changes: 0 additions & 33 deletions collector/plugins/sources/kstate/non_running_pods_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package kstate

import (
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -240,38 +239,6 @@ func TestPointsForNonRunningPods(t *testing.T) {
assert.Equal(t, "some-workload-name", point.Tags()[workloadNameTag])
})

t.Run("test for terminating pod without nodename", func(t *testing.T) {
deletionTime := "2023-06-08T18:35:37Z"
testPod := setupTerminatingPod(t, deletionTime, "")
workloadCache := fakeWorkloadCache()
actualWFPoints := pointsForNonRunningPods(workloadCache)(testPod, testTransform)
assert.Equal(t, 2, len(actualWFPoints))
point := actualWFPoints[1].(*wf.Point)
assert.Equal(t, fmt.Sprintf("%spod.terminating", testTransform.Prefix), point.Metric)
assert.Equal(t, float64(util.POD_PHASE_PENDING), point.Value)
assert.Equal(t, deletionTime, point.Tags()["DeletionTimestamp"])
assert.Equal(t, "pod1", point.Tags()["pod_name"])
assert.Equal(t, "testLabelName", point.Tags()["label.name"])
assert.Equal(t, "none", point.Tags()["nodename"])
assert.Equal(t, "Terminating", point.Tags()["reason"])
})

t.Run("test for terminating pod with nodename", func(t *testing.T) {
deletionTime := "2023-06-08T18:35:37Z"
testPod := setupTerminatingPod(t, deletionTime, "some-node")
workloadCache := fakeWorkloadCache()
actualWFPoints := pointsForNonRunningPods(workloadCache)(testPod, testTransform)
assert.Equal(t, 2, len(actualWFPoints))
point := actualWFPoints[1].(*wf.Point)
assert.Equal(t, fmt.Sprintf("%spod.terminating", testTransform.Prefix), point.Metric)
assert.Equal(t, float64(util.POD_PHASE_PENDING), point.Value)
assert.Equal(t, deletionTime, point.Tags()["DeletionTimestamp"])
assert.Equal(t, "pod1", point.Tags()["pod_name"])
assert.Equal(t, "testLabelName", point.Tags()["label.name"])
assert.Equal(t, "some-node", point.Tags()["nodename"])
assert.Equal(t, "Terminating", point.Tags()["reason"])
})

t.Run("test for completed pod", func(t *testing.T) {
testPod := setupCompletedPod()
workloadCache := fakeWorkloadCache()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
{
"name": "B",
"query": "count(ts(\"kubernetes.pod.terminating\", cluster=\"K8S_CLUSTER_NAME\"), sources, cluster, cluster_uuid, namespace_name, workload_name, workload_kind, pod_name, reason, DeletionTimestamp, type, metrics)",
"query": "count(ts(\"kubernetes.pod_container.status\", cluster=\"K8S_CLUSTER_NAME\" AND status=\"terminated\"), sources, cluster, cluster_uuid, namespace_name, workload_name, workload_kind, pod_name, reason, type, metrics)",
"queryType": "WQL",
"alertSourceType": ["VARIABLE"],
"hidden": true
Expand Down

0 comments on commit d487bc0

Please sign in to comment.