Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Handle requests for ephemeral_storage metrics #51

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 5 additions & 3 deletions pkg/api/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ func getRows(db *sql.DB, table string, metricName string, selector ResourceSelec
orderBy := []string{"name", "time"}
if metricName == "cpu" {
query = "select sum(cpu), name, uid, time from %s "
} else {
//default to metricName == "memory/usage"
// metricName = "memory"
} else if metricName == "memory" {
query = "select sum(memory), name, uid, time from %s "
} else if metricName == "ephemeral_storage" {

Choose a reason for hiding this comment

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

It seems to me that the metricName would be more appropriate - "storage"

Copy link
Author

@afbjorklund afbjorklund Aug 19, 2022

Choose a reason for hiding this comment

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

That is a different metric

    stmt, err := tx.Prepare("insert into nodes(uid, name, cpu, memory, storage, time) values(?, ?, ?, ?, ?, datetime('now'))")

            _, err = stmt.Exec(v.UID, v.Name, v.Usage.Cpu().MilliValue(), v.Usage.Memory().MilliValue()/1000, v.Usage.StorageEphemeral().MilliValue()/1000)

The database column could be renamed, but I don't think anyone cares.

Choose a reason for hiding this comment

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

You are right, in my comment relied just on the title of the column

Copy link
Author

@afbjorklund afbjorklund Aug 19, 2022

Choose a reason for hiding this comment

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

as far as I know, Storage is only used for persistent volumes - not for nodes and pods

https://github.com/kubernetes-retired/heapster/blob/master/docs/storage-schema.md

query = "select sum(storage), name, uid, time from %s "
} else { // unknown metric
query = "select NULL, name, uid, time from %s "
}

if table == "pods" {
Expand Down
31 changes: 21 additions & 10 deletions pkg/database/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ func nodeMetrics() v1beta1.NodeMetricsList {
tmp := v1beta1.NodeMetrics{}
tmp.SetName("testing")
tmp.Usage = v1.ResourceList{
v1.ResourceCPU: resource.MustParse("1"),
v1.ResourceMemory: resource.MustParse("100"),
v1.ResourceCPU: resource.MustParse("1"),
v1.ResourceMemory: resource.MustParse("100"),
v1.ResourceEphemeralStorage: resource.MustParse("1000"),
}

nm := v1beta1.NodeMetricsList{
Expand All @@ -41,8 +42,9 @@ func podMetrics() v1beta1.PodMetricsList {
tmp2 := v1beta1.ContainerMetrics{}
tmp2.Name = "container_test"
tmp2.Usage = v1.ResourceList{
v1.ResourceCPU: resource.MustParse("1"),
v1.ResourceMemory: resource.MustParse("100"),
v1.ResourceCPU: resource.MustParse("1"),
v1.ResourceMemory: resource.MustParse("100"),
v1.ResourceEphemeralStorage: resource.MustParse("1000"),
}

tmp := v1beta1.PodMetrics{}
Expand Down Expand Up @@ -121,7 +123,7 @@ var _ = ginkgo.Describe("Database functions", func() {
panic(err.Error())
}

rows, err := db.Query("select name, cpu, memory from nodes")
rows, err := db.Query("select name, cpu, memory, storage from nodes")
if err != nil {
log.Fatal(err)
}
Expand All @@ -130,19 +132,22 @@ var _ = ginkgo.Describe("Database functions", func() {
var name string
var cpu int64
var memory int64
err = rows.Scan(&name, &cpu, &memory)
var storage int64
err = rows.Scan(&name, &cpu, &memory, &storage)
if err != nil {
log.Fatal(err)
}
testCpu := resource.MustParse("1")
testMemory := resource.MustParse("100")
testStorage := resource.MustParse("1000")
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(name).To(gomega.Equal("testing"))
gomega.Expect(cpu).To(gomega.Equal(testCpu.MilliValue()))
gomega.Expect(memory).To(gomega.Equal(testMemory.MilliValue() / 1000))
gomega.Expect(storage).To(gomega.Equal(testStorage.MilliValue() / 1000))
}

rows, err = db.Query("select name, container, cpu, memory from pods")
rows, err = db.Query("select name, container, cpu, memory, storage from pods")
if err != nil {
log.Fatal(err)
}
Expand All @@ -152,17 +157,20 @@ var _ = ginkgo.Describe("Database functions", func() {
var container string
var cpu int64
var memory int64
err = rows.Scan(&name, &container, &cpu, &memory)
var storage int64
err = rows.Scan(&name, &container, &cpu, &memory, &storage)
if err != nil {
log.Fatal(err)
}
testCpu := resource.MustParse("1")
testMemory := resource.MustParse("100")
testStorage := resource.MustParse("1000")
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(name).To(gomega.Equal("testing"))
gomega.Expect(container).To(gomega.Equal("container_test"))
gomega.Expect(cpu).To(gomega.Equal(testCpu.MilliValue()))
gomega.Expect(memory).To(gomega.Equal(testMemory.MilliValue() / 1000))
gomega.Expect(storage).To(gomega.Equal(testStorage.MilliValue() / 1000))
}
})
ginkgo.It("should cull the database based on a window.", func() {
Expand Down Expand Up @@ -201,7 +209,7 @@ var _ = ginkgo.Describe("Database functions", func() {
panic(err.Error())
}

rows, err := db.Query("select name, cpu, memory from nodes")
rows, err := db.Query("select name, cpu, memory, storage from nodes")
if err != nil {
log.Fatal(err)
}
Expand All @@ -210,16 +218,19 @@ var _ = ginkgo.Describe("Database functions", func() {
var name string
var cpu int64
var memory int64
err = rows.Scan(&name, &cpu, &memory)
var storage int64
err = rows.Scan(&name, &cpu, &memory, &storage)
if err != nil {
log.Fatal(err)
}
testCpu := resource.MustParse("1")
testMemory := resource.MustParse("100")
testStorage := resource.MustParse("1000")
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(name).To(gomega.Equal("testing"))
gomega.Expect(cpu).To(gomega.Equal(testCpu.MilliValue()))
gomega.Expect(memory).To(gomega.Equal(testMemory.MilliValue() / 1000))
gomega.Expect(storage).To(gomega.Equal(testStorage.MilliValue() / 1000))
}

})
Expand Down