Skip to content

Commit

Permalink
Fix: cpu monitoring persistor (#27)
Browse files Browse the repository at this point in the history
feat: add pod field and missing labels
feat: add new columns to persistor
  • Loading branch information
lterrac authored Nov 8, 2021
1 parent f088f68 commit 9d89e89
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions config/metric-db/002_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ CREATE TABLE IF NOT EXISTS resource
timestamp TIMESTAMP,
node VARCHAR(50),
function VARCHAR(50),
pod VARCHAR(50),
namespace VARCHAR(50),
cores BIGINT,
requests BIGINT,
Expand Down
8 changes: 5 additions & 3 deletions pkg/cpu-monitoring/pkg/persistor/persistor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ var (
"timestamp",
"node",
"function",
"pod",
"namespace",
"community",
"cores",
"requests",
"limits",
}
)

const (
// InsertMetricQuery is the prepare statement for inserting metrics.
InsertMetricQuery = "INSERT INTO resource (timestamp, node, function, namespace, community, cores, requests, limits) VALUES ($1, $2, $3, $4, $5, $6, $7, $8);"
batchSize = 10000
table = "resource"
batchSize = 10000
table = "resource"
)

type Persistor interface {
Expand Down
20 changes: 16 additions & 4 deletions pkg/cpu-monitoring/pkg/scraper/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,26 @@ func (s *defaultScraper) scrape() {
totalCores += c.Usage.Cpu().MilliValue()
}

namespace := p.Labels[ealabels.FunctionNamespaceLabel]
function := ""

if f, ok := p.Labels[ealabels.FunctionNameLabel]; ok {
function = f
}

community := ""

if c, ok := p.Labels[ealabels.CommunityLabel.WithNamespace(p.Namespace).String()]; ok {
community = c
}

// save to metrics database
s.resourceChan <- metrics.RawResourceData{
Timestamp: time.Now(),
Node: p.Spec.NodeName,
Function: p.Labels[ealabels.FunctionNameLabel],
Namespace: namespace,
Community: p.Labels[ealabels.CommunityLabel.WithNamespace(namespace).String()],
Function: function,
Pod: p.Name,
Namespace: p.Namespace,
Community: community,
Cores: totalCores,
Requests: totalRequests,
Limits: totalLimits,
Expand Down
5 changes: 2 additions & 3 deletions pkg/dispatcher/pkg/persistor/persistor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ var (

const (
// InsertMetricQuery is the prepare statement for inserting metrics.
InsertMetricQuery = "INSERT INTO metric (timestamp, source, destination, function, namespace, community, gpu, latency) VALUES ($1, $2, $3, $4, $5, $6, $7, $8);"
batchSize = 1000
table = "metric"
batchSize = 1000
table = "metric"
)

// MetricsPersistor receives metrics from the load balancer and persists them to a backend.
Expand Down
2 changes: 2 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type RawResourceData struct {
Timestamp time.Time
Node string
Function string
Pod string
Namespace string
Community string
Cores int64
Expand All @@ -53,6 +54,7 @@ func (r RawResourceData) AsCopy() []interface{} {
r.Timestamp,
r.Node,
r.Function,
r.Pod,
r.Namespace,
r.Community,
r.Cores,
Expand Down

0 comments on commit 9d89e89

Please sign in to comment.