Skip to content

Commit

Permalink
k8sclusterreceiver: Standardize metric names (#1119)
Browse files Browse the repository at this point in the history
- Replace "/" with "." in metric names
- daemon_set -> daemonset, stateful_set -> statefulset, replica_set -> replicaset to match conventions
- k8s/container/<resource_type>/<request | limit> -> k8s.container.<resource_type>_<request | limit>
  • Loading branch information
asuresh4 committed Sep 28, 2020
1 parent 92f2dca commit cd5dacb
Show file tree
Hide file tree
Showing 24 changed files with 103 additions and 65 deletions.
2 changes: 1 addition & 1 deletion receiver/k8sclusterreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ with detailed sample configurations [here](./testdata/config.yaml).
### node_conditions_to_report

For example, with the config below the receiver will emit two metrics
`kubernetes/node/condition_ready` and `kubernetes/node/condition_memory_pressure`, one
`k8s.node.condition_ready` and `k8s.node.condition_memory_pressure`, one
for each condition in the config. The value will be `1` if the `ConditionStatus` for the
corresponding `Condition` is `True`, `0` if it is `False` and -1 if it is `Unknown`.

Expand Down
6 changes: 3 additions & 3 deletions receiver/k8sclusterreceiver/collection/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
)

var containerRestartMetric = &metricspb.MetricDescriptor{
Name: "k8s/container/restarts",
Name: "k8s.container.restarts",
Description: "How many times the container has restarted in the recent past. " +
"This value is pulled directly from the K8s API and the value can go indefinitely high" +
" and be reset to 0 at any time depending on how your kubelet is configured to prune" +
Expand All @@ -50,7 +50,7 @@ var containerRestartMetric = &metricspb.MetricDescriptor{
}

var containerReadyMetric = &metricspb.MetricDescriptor{
Name: "k8s/container/ready",
Name: "k8s.container.ready",
Description: "Whether a container has passed its readiness probe (0 for no, 1 for yes)",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
}
Expand Down Expand Up @@ -114,7 +114,7 @@ func getSpecMetricsForContainer(c corev1.Container) []*metricspb.Metric {
metrics = append(metrics,
&metricspb.Metric{
MetricDescriptor: &metricspb.MetricDescriptor{
Name: fmt.Sprintf("k8s/container/%s/%s", k, t.typ),
Name: fmt.Sprintf("k8s.container.%s_%s", k, t.typ),
Description: t.description,
Type: metricspb.MetricDescriptor_GAUGE_INT64,
},
Expand Down
2 changes: 1 addition & 1 deletion receiver/k8sclusterreceiver/collection/cronjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
)

var activeJobs = &metricspb.MetricDescriptor{
Name: "k8s/cronjob/active_jobs",
Name: "k8s.cronjob.active_jobs",
Description: "The number of actively running jobs for a cronjob",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
Expand Down
2 changes: 1 addition & 1 deletion receiver/k8sclusterreceiver/collection/cronjobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestCronJobMetrics(t *testing.T) {
},
)

testutils.AssertMetrics(t, actualResourceMetrics[0].metrics[0], "k8s/cronjob/active_jobs",
testutils.AssertMetrics(t, actualResourceMetrics[0].metrics[0], "k8s.cronjob.active_jobs",
metricspb.MetricDescriptor_GAUGE_INT64, 2)
}

Expand Down
8 changes: 4 additions & 4 deletions receiver/k8sclusterreceiver/collection/daemonsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ import (
)

var daemonSetCurrentScheduledMetric = &metricspb.MetricDescriptor{
Name: "k8s/daemon_set/current_scheduled_nodes",
Name: "k8s.daemonset.current_scheduled_nodes",
Description: "Number of nodes that are running at least 1 daemon pod and are supposed to run the daemon pod",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
}

var daemonSetDesiredScheduledMetric = &metricspb.MetricDescriptor{
Name: "k8s/daemon_set/desired_scheduled_nodes",
Name: "k8s.daemonset.desired_scheduled_nodes",
Description: "Number of nodes that should be running the daemon pod (including nodes currently running the daemon pod)",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
}

var daemonSetMisScheduledMetric = &metricspb.MetricDescriptor{
Name: "k8s/daemon_set/misscheduled_nodes",
Name: "k8s.daemonset.misscheduled_nodes",
Description: "Number of nodes that are running the daemon pod, but are not supposed to run the daemon pod",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
}

var daemonSetReadyMetric = &metricspb.MetricDescriptor{
Name: "k8s/daemon_set/ready_nodes",
Name: "k8s.daemonset.ready_nodes",
Description: "Number of nodes that should be running the daemon pod and have one or more of the daemon pod running and ready",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
Expand Down
8 changes: 4 additions & 4 deletions receiver/k8sclusterreceiver/collection/daemonsets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ func TestDaemonsetMetrics(t *testing.T) {
},
)

testutils.AssertMetrics(t, rm.metrics[0], "k8s/daemon_set/current_scheduled_nodes",
testutils.AssertMetrics(t, rm.metrics[0], "k8s.daemonset.current_scheduled_nodes",
metricspb.MetricDescriptor_GAUGE_INT64, 3)

testutils.AssertMetrics(t, rm.metrics[1], "k8s/daemon_set/desired_scheduled_nodes",
testutils.AssertMetrics(t, rm.metrics[1], "k8s.daemonset.desired_scheduled_nodes",
metricspb.MetricDescriptor_GAUGE_INT64, 5)

testutils.AssertMetrics(t, rm.metrics[2], "k8s/daemon_set/misscheduled_nodes",
testutils.AssertMetrics(t, rm.metrics[2], "k8s.daemonset.misscheduled_nodes",
metricspb.MetricDescriptor_GAUGE_INT64, 1)

testutils.AssertMetrics(t, rm.metrics[3], "k8s/daemon_set/ready_nodes",
testutils.AssertMetrics(t, rm.metrics[3], "k8s.daemonset.ready_nodes",
metricspb.MetricDescriptor_GAUGE_INT64, 2)
}

Expand Down
4 changes: 2 additions & 2 deletions receiver/k8sclusterreceiver/collection/deployments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ func TestDeploymentMetrics(t *testing.T) {
},
)

testutils.AssertMetrics(t, rm.metrics[0], "k8s/deployment/desired",
testutils.AssertMetrics(t, rm.metrics[0], "k8s.deployment.desired",
metricspb.MetricDescriptor_GAUGE_INT64, 10)

testutils.AssertMetrics(t, rm.metrics[1], "k8s/deployment/available",
testutils.AssertMetrics(t, rm.metrics[1], "k8s.deployment.available",
metricspb.MetricDescriptor_GAUGE_INT64, 3)
}

Expand Down
8 changes: 4 additions & 4 deletions receiver/k8sclusterreceiver/collection/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ import (
)

var hpaMaxReplicasMetric = &metricspb.MetricDescriptor{
Name: "k8s/hpa/max_replicas",
Name: "k8s.hpa.max_replicas",
Description: "Maximum number of replicas to which the autoscaler can scale up",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
}

var hpaMinReplicasMetric = &metricspb.MetricDescriptor{
Name: "k8s/hpa/min_replicas",
Name: "k8s.hpa.min_replicas",
Description: "Minimum number of replicas to which the autoscaler can scale down",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
}

var hpaCurrentReplicasMetric = &metricspb.MetricDescriptor{
Name: "k8s/hpa/current_replicas",
Name: "k8s.hpa.current_replicas",
Description: "Current number of pod replicas managed by this autoscaler",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
}

var hpaDesiredReplicasMetric = &metricspb.MetricDescriptor{
Name: "k8s/hpa/desired_replicas",
Name: "k8s.hpa.desired_replicas",
Description: "Desired number of pod replicas managed by this autoscaler",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
Expand Down
8 changes: 4 additions & 4 deletions receiver/k8sclusterreceiver/collection/hpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ func TestHPAMetrics(t *testing.T) {
},
)

testutils.AssertMetrics(t, rm.metrics[0], "k8s/hpa/max_replicas",
testutils.AssertMetrics(t, rm.metrics[0], "k8s.hpa.max_replicas",
metricspb.MetricDescriptor_GAUGE_INT64, 10)

testutils.AssertMetrics(t, rm.metrics[1], "k8s/hpa/min_replicas",
testutils.AssertMetrics(t, rm.metrics[1], "k8s.hpa.min_replicas",
metricspb.MetricDescriptor_GAUGE_INT64, 2)

testutils.AssertMetrics(t, rm.metrics[2], "k8s/hpa/current_replicas",
testutils.AssertMetrics(t, rm.metrics[2], "k8s.hpa.current_replicas",
metricspb.MetricDescriptor_GAUGE_INT64, 5)

testutils.AssertMetrics(t, rm.metrics[3], "k8s/hpa/desired_replicas",
testutils.AssertMetrics(t, rm.metrics[3], "k8s.hpa.desired_replicas",
metricspb.MetricDescriptor_GAUGE_INT64, 7)
}

Expand Down
10 changes: 5 additions & 5 deletions receiver/k8sclusterreceiver/collection/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,35 @@ import (
)

var podsActiveMetric = &metricspb.MetricDescriptor{
Name: "k8s/job/active_pods",
Name: "k8s.job.active_pods",
Description: "The number of actively running pods for a job",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
}

var podsDesiredCompletedMetric = &metricspb.MetricDescriptor{
Name: "k8s/job/desired_successful_pods",
Name: "k8s.job.desired_successful_pods",
Description: "The desired number of successfully finished pods the job should be run with",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
}

var podsFailedMetric = &metricspb.MetricDescriptor{
Name: "k8s/job/failed_pods",
Name: "k8s.job.failed_pods",
Description: "The number of pods which reached phase Failed for a job",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
}

var podsMaxParallelMetric = &metricspb.MetricDescriptor{
Name: "k8s/job/max_parallel_pods",
Name: "k8s.job.max_parallel_pods",
Description: "The max desired number of pods the job should run at any given time",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
}

var podsSuccessfulMetric = &metricspb.MetricDescriptor{
Name: "k8s/job/successful_pods",
Name: "k8s.job.successful_pods",
Description: "The number of pods which reached phase Succeeded for a job",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
Expand Down
10 changes: 5 additions & 5 deletions receiver/k8sclusterreceiver/collection/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ func TestJobMetrics(t *testing.T) {
},
)

testutils.AssertMetrics(t, actualResourceMetrics[0].metrics[0], "k8s/job/active_pods",
testutils.AssertMetrics(t, actualResourceMetrics[0].metrics[0], "k8s.job.active_pods",
metricspb.MetricDescriptor_GAUGE_INT64, 2)

testutils.AssertMetrics(t, actualResourceMetrics[0].metrics[1], "k8s/job/desired_successful_pods",
testutils.AssertMetrics(t, actualResourceMetrics[0].metrics[1], "k8s.job.desired_successful_pods",
metricspb.MetricDescriptor_GAUGE_INT64, 10)

testutils.AssertMetrics(t, actualResourceMetrics[0].metrics[2], "k8s/job/failed_pods",
testutils.AssertMetrics(t, actualResourceMetrics[0].metrics[2], "k8s.job.failed_pods",
metricspb.MetricDescriptor_GAUGE_INT64, 0)

testutils.AssertMetrics(t, actualResourceMetrics[0].metrics[3], "k8s/job/max_parallel_pods",
testutils.AssertMetrics(t, actualResourceMetrics[0].metrics[3], "k8s.job.max_parallel_pods",
metricspb.MetricDescriptor_GAUGE_INT64, 2)

testutils.AssertMetrics(t, actualResourceMetrics[0].metrics[4], "k8s/job/successful_pods",
testutils.AssertMetrics(t, actualResourceMetrics[0].metrics[4], "k8s.job.successful_pods",
metricspb.MetricDescriptor_GAUGE_INT64, 3)
}

Expand Down
2 changes: 1 addition & 1 deletion receiver/k8sclusterreceiver/collection/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func getMetricsForNamespace(ns *corev1.Namespace) []*resourceMetrics {
metrics := []*metricspb.Metric{
{
MetricDescriptor: &metricspb.MetricDescriptor{
Name: "k8s/namespace/phase",
Name: "k8s.namespace.phase",
Description: "The current phase of namespaces (1 for active and 0 for terminating)",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
},
Expand Down
2 changes: 1 addition & 1 deletion receiver/k8sclusterreceiver/collection/namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestNamespaceMetrics(t *testing.T) {
},
)

testutils.AssertMetrics(t, actualResourceMetrics[0].metrics[0], "k8s/namespace/phase",
testutils.AssertMetrics(t, actualResourceMetrics[0].metrics[0], "k8s.namespace.phase",
metricspb.MetricDescriptor_GAUGE_INT64, 0)
}

Expand Down
2 changes: 1 addition & 1 deletion receiver/k8sclusterreceiver/collection/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func getMetricsForNode(node *corev1.Node, nodeConditionTypesToReport []string) [
}

func getNodeConditionMetric(nodeConditionTypeValue string) string {
return fmt.Sprintf("k8s/node/condition_%s", strcase.ToSnake(nodeConditionTypeValue))
return fmt.Sprintf("k8s.node.condition_%s", strcase.ToSnake(nodeConditionTypeValue))
}

func getResourceForNode(node *corev1.Node) *resourcepb.Resource {
Expand Down
10 changes: 5 additions & 5 deletions receiver/k8sclusterreceiver/collection/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func TestNodeMetrics(t *testing.T) {
},
)

testutils.AssertMetrics(t, actualResourceMetrics[0].metrics[0], "k8s/node/condition_ready",
testutils.AssertMetrics(t, actualResourceMetrics[0].metrics[0], "k8s.node.condition_ready",
metricspb.MetricDescriptor_GAUGE_INT64, 1)

testutils.AssertMetrics(t, actualResourceMetrics[0].metrics[1], "k8s/node/condition_memory_pressure",
testutils.AssertMetrics(t, actualResourceMetrics[0].metrics[1], "k8s.node.condition_memory_pressure",
metricspb.MetricDescriptor_GAUGE_INT64, 0)
}

Expand Down Expand Up @@ -83,15 +83,15 @@ func TestGetNodeConditionMetric(t *testing.T) {
}{
{"Metric for Node condition Ready",
"Ready",
"k8s/node/condition_ready",
"k8s.node.condition_ready",
},
{"Metric for Node condition MemoryPressure",
"MemoryPressure",
"k8s/node/condition_memory_pressure",
"k8s.node.condition_memory_pressure",
},
{"Metric for Node condition DiskPressure",
"DiskPressure",
"k8s/node/condition_disk_pressure",
"k8s.node.condition_disk_pressure",
},
}

Expand Down
2 changes: 1 addition & 1 deletion receiver/k8sclusterreceiver/collection/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
)

var podPhaseMetric = &metricspb.MetricDescriptor{
Name: "k8s/pod/phase",
Name: "k8s.pod.phase",
Description: "Current phase of the pod (1 - Pending, 2 - Running, 3 - Succeeded, 4 - Failed, 5 - Unknown)",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
}
Expand Down
10 changes: 5 additions & 5 deletions receiver/k8sclusterreceiver/collection/pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestPodAndContainerMetrics(t *testing.T) {
},
)

testutils.AssertMetrics(t, rm.Metrics[0], "k8s/pod/phase",
testutils.AssertMetrics(t, rm.Metrics[0], "k8s.pod.phase",
metricspb.MetricDescriptor_GAUGE_INT64, 3)

rm = rms[1]
Expand All @@ -79,16 +79,16 @@ func TestPodAndContainerMetrics(t *testing.T) {
},
)

testutils.AssertMetrics(t, rm.Metrics[0], "k8s/container/restarts",
testutils.AssertMetrics(t, rm.Metrics[0], "k8s.container.restarts",
metricspb.MetricDescriptor_GAUGE_INT64, 3)

testutils.AssertMetrics(t, rm.Metrics[1], "k8s/container/ready",
testutils.AssertMetrics(t, rm.Metrics[1], "k8s.container.ready",
metricspb.MetricDescriptor_GAUGE_INT64, 1)

testutils.AssertMetrics(t, rm.Metrics[2], "k8s/container/cpu/request",
testutils.AssertMetrics(t, rm.Metrics[2], "k8s.container.cpu_request",
metricspb.MetricDescriptor_GAUGE_INT64, 10000)

testutils.AssertMetrics(t, rm.Metrics[3], "k8s/container/cpu/limit",
testutils.AssertMetrics(t, rm.Metrics[3], "k8s.container.cpu_limit",
metricspb.MetricDescriptor_GAUGE_INT64, 20000)
}

Expand Down
4 changes: 2 additions & 2 deletions receiver/k8sclusterreceiver/collection/replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func getReplicaMetrics(resource string, desired, available int32) []*metricspb.M
return []*metricspb.Metric{
{
MetricDescriptor: &metricspb.MetricDescriptor{
Name: fmt.Sprintf("k8s/%s/desired", resource),
Name: fmt.Sprintf("k8s.%s.desired", resource),
Description: fmt.Sprintf("Number of desired pods in this %s", resource),
Type: metricspb.MetricDescriptor_GAUGE_INT64,
Unit: "1",
Expand All @@ -35,7 +35,7 @@ func getReplicaMetrics(resource string, desired, available int32) []*metricspb.M
},
{
MetricDescriptor: &metricspb.MetricDescriptor{
Name: fmt.Sprintf("k8s/%s/available", resource),
Name: fmt.Sprintf("k8s.%s.available", resource),
Description: fmt.Sprintf("Total number of available pods (ready for at least minReadySeconds) targeted by this %s", resource),
Type: metricspb.MetricDescriptor_GAUGE_INT64,
Unit: "1",
Expand Down
2 changes: 1 addition & 1 deletion receiver/k8sclusterreceiver/collection/replicasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func getMetricsForReplicaSet(rs *appsv1.ReplicaSet) []*resourceMetrics {
{
resource: getResourceForReplicaSet(rs),
metrics: getReplicaMetrics(
"replica_set",
"replicaset",
*rs.Spec.Replicas,
rs.Status.AvailableReplicas,
),
Expand Down
Loading

0 comments on commit cd5dacb

Please sign in to comment.