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

Fix an issue when memory/bytes_used is not reported. #1822

Merged
merged 1 commit into from
Sep 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion metrics/sinks/stackdriver/stackdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,18 @@ func (sink *StackdriverSink) TranslateMetric(timestamp time.Time, labels map[str
return ts
case "memory/bytes_used":
point := sink.intPoint(timestamp, timestamp, value.IntValue)
return createTimeSeries(resourceLabels, memoryBytesUsedMD, point)
ts := createTimeSeries(resourceLabels, memoryBytesUsedMD, point)
ts.Metric.Labels = map[string]string{
"memory_type": "evictable",
}
return ts
case core.MetricMemoryWorkingSet.MetricDescriptor.Name:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own education - where does this name come from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

core.MetricMemoryWorkingSet is a metric that we fetch from kubelet. At the same time bytes_used (and minor_page_faults) are created manually in preprocessMemoryMetrics function.

point := sink.intPoint(timestamp, timestamp, value.IntValue)
ts := createTimeSeries(resourceLabels, memoryBytesUsedMD, point)
ts.Metric.Labels = map[string]string{
"memory_type": "non-evictable",
}
return ts
case "memory/minor_page_faults":
point := sink.intPoint(timestamp, createTime, value.IntValue)
ts := createTimeSeries(resourceLabels, memoryPageFaultsMD, point)
Expand Down
38 changes: 30 additions & 8 deletions metrics/sinks/stackdriver/stackdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,36 @@ func TestTranslateMemoryNodeAllocatable(t *testing.T) {
as.Equal(int64(2048), *value.Int64Value)
}

func TestTranslateMemoryUsedEvictable(t *testing.T) {
metricValue := generateIntMetric(100)
name := "memory/bytes_used"
timestamp := time.Now()
createTime := timestamp.Add(-time.Second)

ts := sink.TranslateMetric(timestamp, commonLabels, name, metricValue, createTime)

as := assert.New(t)
as.Equal(ts.Metric.Type, "container.googleapis.com/container/memory/bytes_used")
as.Equal(len(ts.Points), 1)
as.Equal(*ts.Points[0].Value.Int64Value, int64(100))
as.Equal(ts.Metric.Labels["memory_type"], "evictable")
}

func TestTranslateMemoryUsedNonEvictable(t *testing.T) {
metricValue := generateIntMetric(200)
name := core.MetricMemoryWorkingSet.MetricDescriptor.Name
timestamp := time.Now()
createTime := timestamp.Add(-time.Second)

ts := sink.TranslateMetric(timestamp, commonLabels, name, metricValue, createTime)

as := assert.New(t)
as.Equal(ts.Metric.Type, "container.googleapis.com/container/memory/bytes_used")
as.Equal(len(ts.Points), 1)
as.Equal(*ts.Points[0].Value.Int64Value, int64(200))
as.Equal(ts.Metric.Labels["memory_type"], "non-evictable")
}

func TestTranslateMemoryMajorPageFaults(t *testing.T) {
metricValue := generateIntMetric(20)
name := "memory/major_page_faults"
Expand Down Expand Up @@ -160,14 +190,6 @@ func TestTranslateMemoryMinorPageFaults(t *testing.T) {
as.Equal(ts.Metric.Labels["fault_type"], "minor")
}

func TestTranslateMemoryBytesUsed(t *testing.T) {
as := assert.New(t)
value := testTranslateMetric(as, 987, "memory/bytes_used", commonLabels,
"container.googleapis.com/container/memory/bytes_used")

as.Equal(int64(987), *value.Int64Value)
}

// Test TranslateLabeledMetric

func TestTranslateFilesystemUsage(t *testing.T) {
Expand Down