From f738a332c19a054eebe88951097c6724cf4b6c9a Mon Sep 17 00:00:00 2001 From: Lou Knauer Date: Tue, 15 Feb 2022 13:19:26 +0100 Subject: [PATCH] Support for memoryDomain scoped metrics --- graph/model/models.go | 28 ++++++++++++++++++++++++++ metricdata/cc-metric-store.go | 37 +++++++++++++++++++++++++++++++---- schema/metrics.go | 18 +++++++++-------- 3 files changed, 71 insertions(+), 12 deletions(-) diff --git a/graph/model/models.go b/graph/model/models.go index 1bbaf47..e67098e 100644 --- a/graph/model/models.go +++ b/graph/model/models.go @@ -79,6 +79,34 @@ func (topo *Topology) GetCoresFromHWThreads(hwthreads []int) (cores []int, exclu return cores, exclusive } +// Return a list of memory domain IDs given a list of hwthread IDs. +// Even if just one hwthread is in that memory domain, add it to the list. +// If no hwthreads other than those in the argument list are assigned to +// one of the memory domains in the first return value, return true as the second value. +// TODO: Optimize this, there must be a more efficient way/algorithm. +func (topo *Topology) GetMemoryDomainsFromHWThreads(hwthreads []int) (memDoms []int, exclusive bool) { + memDomsMap := map[int]int{} + for _, hwthread := range hwthreads { + for memDom, hwthreadsInmemDom := range topo.MemoryDomain { + for _, hwthreadInmemDom := range hwthreadsInmemDom { + if hwthread == hwthreadInmemDom { + memDomsMap[memDom] += 1 + } + } + } + } + + exclusive = true + hwthreadsPermemDom := len(topo.Node) / len(topo.MemoryDomain) + memDoms = make([]int, 0, len(memDomsMap)) + for memDom, count := range memDomsMap { + memDoms = append(memDoms, memDom) + exclusive = exclusive && count == hwthreadsPermemDom + } + + return memDoms, exclusive +} + func (topo *Topology) GetAcceleratorIDs() ([]int, error) { accels := make([]int, 0) for _, accel := range topo.Accelerators { diff --git a/metricdata/cc-metric-store.go b/metricdata/cc-metric-store.go index 0ccae91..d2904b5 100644 --- a/metricdata/cc-metric-store.go +++ b/metricdata/cc-metric-store.go @@ -203,10 +203,11 @@ func (ccms *CCMetricStore) LoadData(job *schema.Job, metrics []string, scopes [] } var ( - hwthreadString = string("cpu") // TODO/FIXME: inconsistency between cc-metric-collector and ClusterCockpit - coreString = string(schema.MetricScopeCore) - socketString = string(schema.MetricScopeSocket) - acceleratorString = string(schema.MetricScopeAccelerator) + hwthreadString = string("cpu") // TODO/FIXME: inconsistency between cc-metric-collector and ClusterCockpit + coreString = string(schema.MetricScopeCore) + memoryDomainString = string(schema.MetricScopeMemoryDomain) + socketString = string(schema.MetricScopeSocket) + acceleratorString = string(schema.MetricScopeAccelerator) ) func (ccms *CCMetricStore) buildQueries(job *schema.Job, metrics []string, scopes []schema.MetricScope) ([]ApiQuery, []schema.MetricScope, error) { @@ -359,6 +360,34 @@ func (ccms *CCMetricStore) buildQueries(job *schema.Job, metrics []string, scope continue } + // MemoryDomain -> MemoryDomain + if nativeScope == schema.MetricScopeMemoryDomain && scope == schema.MetricScopeMemoryDomain { + sockets, _ := topology.GetMemoryDomainsFromHWThreads(hwthreads) + queries = append(queries, ApiQuery{ + Metric: remoteName, + Hostname: host.Hostname, + Aggregate: false, + Type: &memoryDomainString, + TypeIds: sockets, + }) + assignedScope = append(assignedScope, scope) + continue + } + + // MemoryDoman -> Node + if nativeScope == schema.MetricScopeMemoryDomain && scope == schema.MetricScopeNode { + sockets, _ := topology.GetMemoryDomainsFromHWThreads(hwthreads) + queries = append(queries, ApiQuery{ + Metric: remoteName, + Hostname: host.Hostname, + Aggregate: true, + Type: &memoryDomainString, + TypeIds: sockets, + }) + assignedScope = append(assignedScope, scope) + continue + } + // Socket -> Socket if nativeScope == schema.MetricScopeSocket && scope == schema.MetricScopeSocket { sockets, _ := topology.GetSocketsFromHWThreads(hwthreads) diff --git a/schema/metrics.go b/schema/metrics.go index 320d821..beac92a 100644 --- a/schema/metrics.go +++ b/schema/metrics.go @@ -43,19 +43,21 @@ type MetricScope string const ( MetricScopeInvalid MetricScope = "invalid_scope" - MetricScopeNode MetricScope = "node" - MetricScopeSocket MetricScope = "socket" - MetricScopeCore MetricScope = "core" - MetricScopeHWThread MetricScope = "hwthread" + MetricScopeNode MetricScope = "node" + MetricScopeSocket MetricScope = "socket" + MetricScopeMemoryDomain MetricScope = "memoryDomain" + MetricScopeCore MetricScope = "core" + MetricScopeHWThread MetricScope = "hwthread" MetricScopeAccelerator MetricScope = "accelerator" ) var metricScopeGranularity map[MetricScope]int = map[MetricScope]int{ - MetricScopeNode: 10, - MetricScopeSocket: 5, - MetricScopeCore: 2, - MetricScopeHWThread: 1, + MetricScopeNode: 10, + MetricScopeSocket: 5, + MetricScopeMemoryDomain: 3, + MetricScopeCore: 2, + MetricScopeHWThread: 1, MetricScopeAccelerator: 5, // Special/Randomly choosen