Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1885 from kawych/more_new_metrics
Browse files Browse the repository at this point in the history
Fix few bugs in Heapster exporting metrics for new Stackdriver resource model
  • Loading branch information
piosz authored Nov 22, 2017
2 parents 1c27bc2 + 7e78bf8 commit df92080
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 54 deletions.
4 changes: 4 additions & 0 deletions metrics/core/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ var (
Key: "schedulable",
Description: "Node schedulable status.",
}
LabelVolumeName = LabelDescriptor{
Key: "volume_name",
Description: "The name of the volume.",
}
)

type LabelDescriptor struct {
Expand Down
22 changes: 0 additions & 22 deletions metrics/core/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,28 +685,6 @@ var MetricFilesystemAvailable = Metric{
},
}

var MetricVolumeTotal = Metric{
MetricDescriptor: MetricDescriptor{
Name: "volume/total_bytes",
Description: "Total bytes reserved for a volume",
Type: MetricGauge,
ValueType: ValueInt64,
Units: UnitsBytes,
Labels: metricLabels,
},
}

var MetricVolumeUsage = Metric{
MetricDescriptor: MetricDescriptor{
Name: "volume/used_bytes",
Description: "Usage bytes reserved for a volume",
Type: MetricGauge,
ValueType: ValueInt64,
Units: UnitsBytes,
Labels: metricLabels,
},
}

var MetricFilesystemInodes = Metric{
MetricDescriptor: MetricDescriptor{
Name: "filesystem/inodes",
Expand Down
24 changes: 12 additions & 12 deletions metrics/sinks/stackdriver/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (
cpuRequestedCoresMD = &metricMetadata{
MetricKind: "GAUGE",
ValueType: "DOUBLE",
Name: "kubernetes.io/container/cpu/requested_cores",
Name: "kubernetes.io/container/cpu/request_cores",
}

cpuLimitCoresMD = &metricMetadata{
Expand All @@ -52,7 +52,7 @@ var (
memoryRequestedBytesMD = &metricMetadata{
MetricKind: "GAUGE",
ValueType: "INT64",
Name: "kubernetes.io/container/memory/requested_bytes",
Name: "kubernetes.io/container/memory/request_bytes",
}

memoryLimitBytesMD = &metricMetadata{
Expand All @@ -75,22 +75,22 @@ var (
Name: "kubernetes.io/pod/volume/used_bytes",
}

volumeRequestedBytesMD = &metricMetadata{
volumeTotalBytesMD = &metricMetadata{
MetricKind: "GAUGE",
ValueType: "INT64",
Name: "kubernetes.io/pod/volume/requested_bytes",
Name: "kubernetes.io/pod/volume/total_bytes",
}

networkPodRxMD = &metricMetadata{
networkPodReceivedBytesMD = &metricMetadata{
MetricKind: "CUMULATIVE",
ValueType: "INT64",
Name: "kubernetes.io/pod/network/bytes_rx",
Name: "kubernetes.io/pod/network/received_bytes_count",
}

networkPodTxMD = &metricMetadata{
networkPodSentBytesMD = &metricMetadata{
MetricKind: "CUMULATIVE",
ValueType: "INT64",
Name: "kubernetes.io/pod/network/bytes_tx",
Name: "kubernetes.io/pod/network/sent_bytes_count",
}

// Node metrics
Expand Down Expand Up @@ -131,16 +131,16 @@ var (
Name: "kubernetes.io/node/memory/allocatable_bytes",
}

networkNodeRxMD = &metricMetadata{
networkNodeReceivedBytesMD = &metricMetadata{
MetricKind: "CUMULATIVE",
ValueType: "INT64",
Name: "kubernetes.io/node/network/bytes_rx",
Name: "kubernetes.io/node/network/received_bytes_count",
}

networkNodeTxMD = &metricMetadata{
networkNodeSentBytesMD = &metricMetadata{
MetricKind: "CUMULATIVE",
ValueType: "INT64",
Name: "kubernetes.io/node/network/bytes_tx",
Name: "kubernetes.io/node/network/sent_bytes_count",
}

cpuNodeDaemonCoreUsageTimeMD = &metricMetadata{
Expand Down
28 changes: 17 additions & 11 deletions metrics/sinks/stackdriver/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
sd_api "google.golang.org/api/monitoring/v3"
gce_util "k8s.io/heapster/common/gce"
"k8s.io/heapster/metrics/core"
"strings"
)

const (
Expand Down Expand Up @@ -310,7 +311,6 @@ func (sink *StackdriverSink) sendOneRequest(req *sd_api.CreateTimeSeriesRequest)
WithLabelValues(strconv.Itoa(responseCode)).
Add(float64(len(req.TimeSeries)))
requestLatency.Observe(time.Since(startTime).Seconds() / time.Millisecond.Seconds())

}

func CreateStackdriverSink(uri *url.URL) (core.DataSink, error) {
Expand Down Expand Up @@ -531,18 +531,18 @@ func (sink *StackdriverSink) TranslateLabeledMetric(timestamp time.Time, labels
case core.MetricSetTypePod:
podLabels := sink.getPodResourceLabels(labels)
switch metric.Name {
case core.MetricVolumeUsage.MetricDescriptor.Name:
case core.MetricFilesystemUsage.MetricDescriptor.Name:
point := sink.intPoint(timestamp, timestamp, metric.MetricValue.IntValue)
ts := createTimeSeries("k8s_pod", podLabels, volumeUsedBytesMD, point)
ts.Metric.Labels = map[string]string{
"name": metric.Labels[core.LabelResourceID.Key],
core.LabelVolumeName.Key: strings.TrimPrefix(metric.Labels[core.LabelResourceID.Key], "Volume:"),
}
return ts
case core.MetricVolumeTotal.MetricDescriptor.Name:
case core.MetricFilesystemLimit.MetricDescriptor.Name:
point := sink.intPoint(timestamp, timestamp, metric.MetricValue.IntValue)
ts := createTimeSeries("k8s_pod", podLabels, volumeRequestedBytesMD, point)
ts := createTimeSeries("k8s_pod", podLabels, volumeTotalBytesMD, point)
ts.Metric.Labels = map[string]string{
"name": metric.Labels[core.LabelResourceID.Key],
core.LabelVolumeName.Key: strings.TrimPrefix(metric.Labels[core.LabelResourceID.Key], "Volume:"),
}
return ts
}
Expand Down Expand Up @@ -601,10 +601,10 @@ func (sink *StackdriverSink) TranslateMetric(timestamp time.Time, labels map[str
switch name {
case core.MetricNetworkRx.MetricDescriptor.Name:
point := sink.intPoint(timestamp, createTime, value.IntValue)
return createTimeSeries("k8s_pod", podLabels, networkPodRxMD, point)
return createTimeSeries("k8s_pod", podLabels, networkPodReceivedBytesMD, point)
case core.MetricNetworkTx.MetricDescriptor.Name:
point := sink.intPoint(timestamp, createTime, value.IntValue)
return createTimeSeries("k8s_pod", podLabels, networkPodTxMD, point)
return createTimeSeries("k8s_pod", podLabels, networkPodSentBytesMD, point)
}
case core.MetricSetTypeNode:
nodeLabels := sink.getNodeResourceLabels(labels)
Expand Down Expand Up @@ -640,10 +640,10 @@ func (sink *StackdriverSink) TranslateMetric(timestamp time.Time, labels map[str
return ts
case core.MetricNetworkRx.MetricDescriptor.Name:
point := sink.intPoint(timestamp, createTime, value.IntValue)
return createTimeSeries("k8s_node", nodeLabels, networkNodeRxMD, point)
return createTimeSeries("k8s_node", nodeLabels, networkNodeReceivedBytesMD, point)
case core.MetricNetworkTx.MetricDescriptor.Name:
point := sink.intPoint(timestamp, createTime, value.IntValue)
return createTimeSeries("k8s_node", nodeLabels, networkNodeTxMD, point)
return createTimeSeries("k8s_node", nodeLabels, networkNodeSentBytesMD, point)
}
case core.MetricSetTypeSystemContainer:
nodeLabels := sink.getNodeResourceLabels(labels)
Expand All @@ -652,19 +652,25 @@ func (sink *StackdriverSink) TranslateMetric(timestamp time.Time, labels map[str
point := sink.intPoint(timestamp, timestamp, value.IntValue)
ts := createTimeSeries("k8s_node", nodeLabels, memoryNodeDaemonUsedBytesMD, point)
ts.Metric.Labels = map[string]string{
"component": labels[core.LabelContainerName.Key],
"memory_type": "evictable",
}
return ts
case core.MetricMemoryWorkingSet.MetricDescriptor.Name:
point := sink.intPoint(timestamp, timestamp, value.IntValue)
ts := createTimeSeries("k8s_node", nodeLabels, memoryNodeDaemonUsedBytesMD, point)
ts.Metric.Labels = map[string]string{
"component": labels[core.LabelContainerName.Key],
"memory_type": "non-evictable",
}
return ts
case core.MetricCpuUsage.MetricDescriptor.Name:
point := sink.doublePoint(timestamp, createTime, float64(value.IntValue)/float64(time.Second/time.Nanosecond))
return createTimeSeries("k8s_node", nodeLabels, cpuNodeDaemonCoreUsageTimeMD, point)
ts := createTimeSeries("k8s_node", nodeLabels, cpuNodeDaemonCoreUsageTimeMD, point)
ts.Metric.Labels = map[string]string{
"component": labels[core.LabelContainerName.Key],
}
return ts
}
}
return nil
Expand Down
18 changes: 9 additions & 9 deletions metrics/sinks/stackdriver/stackdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var (
containerLabels = map[string]string{"type": "pod_container"}
podLabels = map[string]string{"type": "pod"}
nodeLabels = map[string]string{"type": "node"}
nodeDaemonLabels = map[string]string{"type": "sys_container"}
nodeDaemonLabels = map[string]string{"type": "sys_container", "container_name": "kubelet"}
)

func generateIntMetric(value int64) core.MetricValue {
Expand Down Expand Up @@ -291,24 +291,24 @@ func TestTranslateMetricSet(t *testing.T) {

containerUptime := testTranslateMetric(as, generateIntMetric(1000), containerLabels, "uptime", "kubernetes.io/container/uptime")
containerCpuUsage := testTranslateMetric(as, generateIntMetric(2000000000), containerLabels, "cpu/usage", "kubernetes.io/container/cpu/core_usage_time")
containerCpuRequest := testTranslateMetric(as, generateIntMetric(3000), containerLabels, "cpu/request", "kubernetes.io/container/cpu/requested_cores")
containerCpuRequest := testTranslateMetric(as, generateIntMetric(3000), containerLabels, "cpu/request", "kubernetes.io/container/cpu/request_cores")
containerCpuLimit := testTranslateMetric(as, generateIntMetric(4000), containerLabels, "cpu/limit", "kubernetes.io/container/cpu/limit_cores")
containerMemoryUsage := testTranslateMetric(as, generateIntMetric(5), containerLabels, "memory/bytes_used", "kubernetes.io/container/memory/used_bytes")
containerMemoryRequest := testTranslateMetric(as, generateIntMetric(6), containerLabels, "memory/request", "kubernetes.io/container/memory/requested_bytes")
containerMemoryRequest := testTranslateMetric(as, generateIntMetric(6), containerLabels, "memory/request", "kubernetes.io/container/memory/request_bytes")
containerMemoryLimit := testTranslateMetric(as, generateIntMetric(7), containerLabels, "memory/limit", "kubernetes.io/container/memory/limit_bytes")
containerRestartCount := testTranslateMetric(as, generateIntMetric(8), containerLabels, "restart_count", "kubernetes.io/container/restart_count")
podNetworkBytesRx := testTranslateMetric(as, generateIntMetric(9), podLabels, "network/rx", "kubernetes.io/pod/network/bytes_rx")
podNetworkBytesTx := testTranslateMetric(as, generateIntMetric(10), podLabels, "network/tx", "kubernetes.io/pod/network/bytes_tx")
podVolumeTotal := testTranslateLabeledMetric(as, podLabels, generateLabeledIntMetric(11, map[string]string{}, "volume/total_bytes"), "kubernetes.io/pod/volume/requested_bytes")
podVolumeUsed := testTranslateLabeledMetric(as, podLabels, generateLabeledIntMetric(12, map[string]string{}, "volume/used_bytes"), "kubernetes.io/pod/volume/used_bytes")
podNetworkBytesRx := testTranslateMetric(as, generateIntMetric(9), podLabels, "network/rx", "kubernetes.io/pod/network/received_bytes_count")
podNetworkBytesTx := testTranslateMetric(as, generateIntMetric(10), podLabels, "network/tx", "kubernetes.io/pod/network/sent_bytes_count")
podVolumeTotal := testTranslateLabeledMetric(as, podLabels, generateLabeledIntMetric(11, map[string]string{}, "filesystem/limit"), "kubernetes.io/pod/volume/total_bytes")
podVolumeUsed := testTranslateLabeledMetric(as, podLabels, generateLabeledIntMetric(12, map[string]string{}, "filesystem/usage"), "kubernetes.io/pod/volume/used_bytes")
nodeCpuUsage := testTranslateMetric(as, generateIntMetric(13000000000), nodeLabels, "cpu/usage", "kubernetes.io/node/cpu/core_usage_time")
nodeCpuTotal := testTranslateMetric(as, generateFloatMetric(14), nodeLabels, "cpu/node_capacity", "kubernetes.io/node/cpu/total_cores")
nodeCpuAllocatable := testTranslateMetric(as, generateFloatMetric(15), nodeLabels, "cpu/node_allocatable", "kubernetes.io/node/cpu/allocatable_cores")
nodeMemoryUsage := testTranslateMetric(as, generateIntMetric(16), nodeLabels, "memory/bytes_used", "kubernetes.io/node/memory/used_bytes")
nodeMemoryTotal := testTranslateMetric(as, generateIntMetric(17), nodeLabels, "memory/node_capacity", "kubernetes.io/node/memory/total_bytes")
nodeMemoryAllocatable := testTranslateMetric(as, generateIntMetric(18), nodeLabels, "memory/node_allocatable", "kubernetes.io/node/memory/allocatable_bytes")
nodeNetworkBytesRx := testTranslateMetric(as, generateIntMetric(19), nodeLabels, "network/rx", "kubernetes.io/node/network/bytes_rx")
nodeNetworkBytesTx := testTranslateMetric(as, generateIntMetric(20), nodeLabels, "network/tx", "kubernetes.io/node/network/bytes_tx")
nodeNetworkBytesRx := testTranslateMetric(as, generateIntMetric(19), nodeLabels, "network/rx", "kubernetes.io/node/network/received_bytes_count")
nodeNetworkBytesTx := testTranslateMetric(as, generateIntMetric(20), nodeLabels, "network/tx", "kubernetes.io/node/network/sent_bytes_count")
nodeDaemonCpuUsage := testTranslateMetric(as, generateIntMetric(21000000000), nodeDaemonLabels, "cpu/usage", "kubernetes.io/node_daemon/cpu/core_usage_time")
nodeDaemonMemoryUsage := testTranslateMetric(as, generateIntMetric(22), nodeDaemonLabels, "memory/bytes_used", "kubernetes.io/node_daemon/memory/used_bytes")

Expand Down

0 comments on commit df92080

Please sign in to comment.