-
Notifications
You must be signed in to change notification settings - Fork 95
/
advisor.go
583 lines (493 loc) · 21.2 KB
/
advisor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
/*
Copyright 2022 The Katalyst Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cpu
import (
"context"
"fmt"
"strconv"
"sync"
"time"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/klog/v2"
"github.com/kubewharf/katalyst-api/pkg/consts"
"github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state"
"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache"
"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/headroomassembler"
"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/assembler/provisionassembler"
"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/isolation"
"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region"
"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/headroompolicy"
"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/qosaware/resource/cpu/region/provisionpolicy"
"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/types"
"github.com/kubewharf/katalyst-core/pkg/config"
"github.com/kubewharf/katalyst-core/pkg/metaserver"
"github.com/kubewharf/katalyst-core/pkg/metrics"
"github.com/kubewharf/katalyst-core/pkg/util/general"
"github.com/kubewharf/katalyst-core/pkg/util/machine"
)
// todo:
// 1. Support dedicated without and with numa binding but non numa exclusive containers
// metric names for cpu advisor
const (
metricCPUAdvisorPoolSize = "cpu_advisor_pool_size"
metricCPUAdvisorUpdateLag = "cpu_advisor_update_lag"
metricCPUAdvisorUpdateDuration = "cpu_advisor_update_duration"
metricRegionStatus = "region_status"
metricRegionIndicatorTargetPrefix = "region_indicator_target_"
metricRegionIndicatorCurrentPrefix = "region_indicator_current_"
metricRegionIndicatorErrorPrefix = "region_indicator_error_"
cpuAdvisorHealthCheckName = "cpu_advisor_update"
healthCheckTolerationDuration = 30 * time.Second
)
var (
errIsolationSafetyCheckFailed = fmt.Errorf("isolation safety check failed")
)
func init() {
provisionpolicy.RegisterInitializer(types.CPUProvisionPolicyNone, provisionpolicy.NewPolicyNone)
provisionpolicy.RegisterInitializer(types.CPUProvisionPolicyCanonical, provisionpolicy.NewPolicyCanonical)
provisionpolicy.RegisterInitializer(types.CPUProvisionPolicyRama, provisionpolicy.NewPolicyRama)
headroompolicy.RegisterInitializer(types.CPUHeadroomPolicyNone, headroompolicy.NewPolicyNone)
headroompolicy.RegisterInitializer(types.CPUHeadroomPolicyCanonical, headroompolicy.NewPolicyCanonical)
headroompolicy.RegisterInitializer(types.CPUHeadroomPolicyNUMAExclusive, headroompolicy.NewPolicyNUMAExclusive)
provisionassembler.RegisterInitializer(types.CPUProvisionAssemblerCommon, provisionassembler.NewProvisionAssemblerCommon)
headroomassembler.RegisterInitializer(types.CPUHeadroomAssemblerCommon, headroomassembler.NewHeadroomAssemblerCommon)
headroomassembler.RegisterInitializer(types.CPUHeadroomAssemblerDedicated, headroomassembler.NewHeadroomAssemblerDedicated)
}
// cpuResourceAdvisor is the entrance of updating cpu resource provision advice for
// all qos regions, and merging them into cpu provision result to notify cpu server.
// Smart algorithms and calculators could be adopted to give accurate realtime resource
// provision hint for each region.
type cpuResourceAdvisor struct {
conf *config.Configuration
extraConf interface{}
period time.Duration
recvCh chan types.TriggerInfo
sendCh chan types.InternalCPUCalculationResult
startTime time.Time
advisorUpdated bool
regionMap map[string]region.QoSRegion // map[regionName]region
reservedForReclaim map[int]int // map[numaID]reservedForReclaim
numaAvailable map[int]int // map[numaID]availableResource
numRegionsPerNuma map[int]int // map[numaID]regionQuantity
nonBindingNumas machine.CPUSet // numas without numa binding pods
provisionAssembler provisionassembler.ProvisionAssembler
headroomAssembler headroomassembler.HeadroomAssembler
isolator isolation.Isolator
isolationSafety bool
mutex sync.RWMutex
metaCache metacache.MetaCache
metaServer *metaserver.MetaServer
emitter metrics.MetricEmitter
doOnce sync.Once
}
// NewCPUResourceAdvisor returns a cpuResourceAdvisor instance
func NewCPUResourceAdvisor(conf *config.Configuration, extraConf interface{}, metaCache metacache.MetaCache,
metaServer *metaserver.MetaServer, emitter metrics.MetricEmitter) *cpuResourceAdvisor {
cra := &cpuResourceAdvisor{
conf: conf,
extraConf: extraConf,
period: conf.QoSAwarePluginConfiguration.SyncPeriod,
recvCh: make(chan types.TriggerInfo, 1),
sendCh: make(chan types.InternalCPUCalculationResult, 1),
startTime: time.Now(),
advisorUpdated: false,
regionMap: make(map[string]region.QoSRegion),
reservedForReclaim: make(map[int]int),
numaAvailable: make(map[int]int),
numRegionsPerNuma: make(map[int]int),
nonBindingNumas: machine.NewCPUSet(),
isolator: isolation.NewLoadIsolator(conf, extraConf, emitter, metaCache, metaServer),
metaCache: metaCache,
metaServer: metaServer,
emitter: emitter,
}
coreNumReservedForReclaim := conf.DynamicAgentConfiguration.GetDynamicConfiguration().MinReclaimedResourceForAllocate[v1.ResourceCPU]
cra.reservedForReclaim = machine.GetCoreNumReservedForReclaim(int(coreNumReservedForReclaim.Value()), metaServer.KatalystMachineInfo.NumNUMANodes)
if err := cra.initializeProvisionAssembler(); err != nil {
klog.Errorf("[qosaware-cpu] initialize provision assembler failed: %v", err)
}
if err := cra.initializeHeadroomAssembler(); err != nil {
klog.Errorf("[qosaware-cpu] initialize headroom assembler failed: %v", err)
}
return cra
}
func (cra *cpuResourceAdvisor) Run(ctx context.Context) {
for {
select {
case v := <-cra.recvCh:
cra.doOnce.Do(func() {
general.RegisterReportCheck(cpuAdvisorHealthCheckName, healthCheckTolerationDuration)
})
lag := time.Since(v.TimeStamp)
klog.Infof("[qosaware-cpu] receive update trigger, checkpoint at %v", v.TimeStamp)
cra.emitter.StoreFloat64(metricCPUAdvisorUpdateLag, float64(lag/time.Millisecond), metrics.MetricTypeNameRaw)
if lag.Seconds() > cra.period.Seconds() {
// do not update if checkpoint is outdated
klog.Errorf("[qosaware-cpu] skip update: checkpoint is outdated, lag %v", lag)
continue
}
err := cra.update()
_ = general.UpdateHealthzStateByError(cpuAdvisorHealthCheckName, err)
if err != nil {
klog.Errorf("[qosaware-cpu] failed to do update: %q", err)
continue
}
case <-ctx.Done():
return
}
}
}
func (cra *cpuResourceAdvisor) GetChannels() (interface{}, interface{}) {
return cra.recvCh, cra.sendCh
}
func (cra *cpuResourceAdvisor) GetHeadroom() (resource.Quantity, error) {
klog.Infof("[qosaware-cpu] receive get headroom request")
cra.mutex.RLock()
defer cra.mutex.RUnlock()
if !cra.advisorUpdated {
klog.Infof("[qosaware-cpu] skip getting headroom: advisor not updated")
return resource.Quantity{}, fmt.Errorf("advisor not updated")
}
if cra.headroomAssembler == nil {
klog.Errorf("[qosaware-cpu] get headroom failed: no legal assembler")
return resource.Quantity{}, fmt.Errorf("no legal assembler")
}
headroom, err := cra.headroomAssembler.GetHeadroom()
if err != nil {
klog.Errorf("[qosaware-cpu] get headroom failed: %v", err)
} else {
klog.Infof("[qosaware-cpu] get headroom: %v", headroom)
}
return headroom, err
}
// update works in a monolithic way to maintain lifecycle and triggers update actions for all regions;
// todo: re-consider whether it's efficient or we should make start individual goroutine for each region
func (cra *cpuResourceAdvisor) update() (err error) {
cra.mutex.Lock()
defer cra.mutex.Unlock()
if err = cra.updateWithIsolationGuardian(true); err != nil {
if err == errIsolationSafetyCheckFailed {
klog.Warningf("[qosaware-cpu] failed to updateWithIsolationGuardian(true): %q", err)
return cra.updateWithIsolationGuardian(false)
}
return err
}
return nil
}
// updateWithIsolationGuardian returns true if the process works as expected,
// otherwise, we should retry with the isolation disabled
// todo: we should re-design the mechanism of isolation instead of disabling this functionality
func (cra *cpuResourceAdvisor) updateWithIsolationGuardian(tryIsolation bool) error {
startTime := time.Now()
defer func(t time.Time) {
elapsed := time.Since(t)
_ = cra.emitter.StoreFloat64(metricCPUAdvisorUpdateDuration, float64(elapsed/time.Millisecond), metrics.MetricTypeNameRaw)
klog.Infof("[qosaware-cpu] update duration %v", elapsed)
}(startTime)
// skip updating during startup
if startTime.Before(cra.startTime.Add(types.StartUpPeriod)) {
klog.Infof("[qosaware-cpu] skip updating: starting up")
return nil
}
// sanity check: if reserve pool exists
reservePoolInfo, ok := cra.metaCache.GetPoolInfo(state.PoolNameReserve)
if !ok || reservePoolInfo == nil {
klog.Errorf("[qosaware-cpu] skip update: reserve pool does not exist")
return nil
}
cra.updateNumasAvailableResource()
isolationExists := cra.setIsolatedContainers(tryIsolation)
// assign containers to regions
if err := cra.assignContainersToRegions(); err != nil {
klog.Errorf("[qosaware-cpu] assign containers to regions failed: %q", err)
return fmt.Errorf("failed to assign containers to regions: %q", err)
}
cra.gcRegionMap()
cra.updateAdvisorEssentials()
if tryIsolation && isolationExists && !cra.checkIsolationSafety() {
klog.Errorf("[qosaware-cpu] failed to check isolation")
return errIsolationSafetyCheckFailed
}
// run an episode of provision and headroom policy update for each region
for _, r := range cra.regionMap {
r.SetEssentials(types.ResourceEssentials{
EnableReclaim: cra.conf.GetDynamicConfiguration().EnableReclaim,
ResourceUpperBound: cra.getRegionMaxRequirement(r),
ResourceLowerBound: cra.getRegionMinRequirement(r),
ReservedForReclaim: cra.getRegionReservedForReclaim(r),
ReservedForAllocate: cra.getRegionReservedForAllocate(r),
})
r.TryUpdateProvision()
r.TryUpdateHeadroom()
}
cra.updateRegionEntries()
cra.advisorUpdated = true
klog.Infof("[qosaware-cpu] region map: %v", general.ToString(cra.regionMap))
// assemble provision result from each region
calculationResult, err := cra.assembleProvision()
if err != nil {
klog.Errorf("[qosaware-cpu] assemble provision failed: %q", err)
return fmt.Errorf("failed to assemble provisioner: %q", err)
}
cra.updateRegionStatus()
cra.emitMetrics(calculationResult)
// notify cpu server
select {
case cra.sendCh <- calculationResult:
klog.Infof("[qosaware-cpu] notify cpu server: %+v", calculationResult)
return nil
default:
klog.Errorf("[qosaware-cpu] channel is full")
return fmt.Errorf("calculation result channel is full")
}
}
// setIsolatedContainers get isolation status from isolator and update into containers
func (cra *cpuResourceAdvisor) setIsolatedContainers(enableIsolated bool) bool {
isolatedPods := sets.NewString()
if enableIsolated {
isolatedPods = sets.NewString(cra.isolator.GetIsolatedPods()...)
}
if len(isolatedPods) > 0 {
klog.Infof("[qosaware-cpu] current isolated pod: %v", isolatedPods.List())
}
_ = cra.metaCache.RangeAndUpdateContainer(func(podUID string, _ string, ci *types.ContainerInfo) bool {
ci.Isolated = false
if isolatedPods.Has(podUID) {
ci.Isolated = true
}
return true
})
return len(isolatedPods) > 0
}
// checkIsolationSafety returns true iff the isolated-limit-sum and share-pool-size exceed total capacity
// todo: this logic contains a lot of assumptions and should be refined in the future
func (cra *cpuResourceAdvisor) checkIsolationSafety() bool {
shareAndIsolationPoolSize := 0
nonBindingNumas := cra.metaServer.CPUDetails.NUMANodes()
for _, r := range cra.regionMap {
if r.Type() == types.QoSRegionTypeShare {
controlKnob, err := r.GetProvision()
if err != nil {
klog.Errorf("[qosaware-cpu] get controlKnob for %v err: %v", r.Name(), err)
return false
}
shareAndIsolationPoolSize += int(controlKnob[types.ControlKnobNonReclaimedCPUSize].Value)
} else if r.Type() == types.QoSRegionTypeIsolation {
pods := r.GetPods()
cra.metaCache.RangeContainer(func(podUID string, _ string, containerInfo *types.ContainerInfo) bool {
if _, ok := pods[podUID]; ok {
shareAndIsolationPoolSize += int(containerInfo.CPULimit)
}
return true
})
} else if r.Type() == types.QoSRegionTypeDedicatedNumaExclusive {
nonBindingNumas = nonBindingNumas.Difference(r.GetBindingNumas())
}
}
nonBindingSize := cra.metaServer.CPUsPerNuma() * nonBindingNumas.Size()
klog.Infof("[qosaware-cpu] shareAndIsolationPoolSize %v, nonBindingSize %v", shareAndIsolationPoolSize, nonBindingSize)
if shareAndIsolationPoolSize > nonBindingSize {
return false
}
return true
}
// assignContainersToRegions re-construct regions every time (instead of an incremental way),
// and this requires metaCache to ensure data integrity
func (cra *cpuResourceAdvisor) assignContainersToRegions() error {
var errList []error
// clear containers for all regions
for _, r := range cra.regionMap {
r.Clear()
}
// sync containers
f := func(podUID string, containerName string, ci *types.ContainerInfo) bool {
regions, err := cra.assignToRegions(ci)
if err != nil {
errList = append(errList, err)
}
if regions == nil {
return true
}
// update region pod set and region map
for _, r := range regions {
if err := r.AddContainer(ci); err != nil {
errList = append(errList, err)
return true
}
// region may be set in regionMap for multiple times, and it is reentrant
cra.regionMap[r.Name()] = r
}
// update container info
cra.setContainerRegions(ci, regions)
// update pool info
if ci.OwnerPoolName == state.PoolNameDedicated {
// dedicated pool should not exist in metaCache.poolEntries
return true
} else if ci.Isolated || cra.conf.IsolationForceEnablePools.Has(ci.OriginOwnerPoolName) {
// isolated pool should not exist in metaCache.poolEntries
return true
} else {
// todo currently, we may call setPoolRegions multiple time, and we
// depend on the reentrant of it, need to refine
if err := cra.setPoolRegions(ci.OriginOwnerPoolName, regions); err != nil {
errList = append(errList, err)
return true
}
}
return true
}
_ = cra.metaCache.RangeAndUpdateContainer(f)
return errors.NewAggregate(errList)
}
// assignToRegions returns the region list for the given container;
// may need to construct region structures if they don't exist.
func (cra *cpuResourceAdvisor) assignToRegions(ci *types.ContainerInfo) ([]region.QoSRegion, error) {
if ci == nil {
return nil, fmt.Errorf("container info is nil")
}
if ci.QoSLevel == consts.PodAnnotationQoSLevelSharedCores {
// do not assign shared container to region when ramping up because its owner pool name is empty
if ci.RampUp {
return nil, nil
}
// return error if container owner pool name is empty
if !ci.RampUp && ci.OwnerPoolName == "" {
return nil, fmt.Errorf("empty owner pool name, %v/%v", ci.PodUID, ci.ContainerName)
}
// assign isolated container
if ci.Isolated || cra.conf.IsolationForceEnablePools.Has(ci.OriginOwnerPoolName) {
regionName := ""
if cra.conf.IsolationNonExclusivePools.Has(ci.OriginOwnerPoolName) {
// use origin owner pool name as region name, because all the container in this pool
// share only one region which is non-exclusive
regionName = ci.OriginOwnerPoolName
// if there already exists a non-exclusive isolation region for this pod, just reuse it
regions := cra.getPoolRegions(regionName)
if len(regions) > 0 {
return regions, nil
}
// if there already exists a region with same name as this region, just reuse it
regions = cra.getRegionsByRegionNames(sets.NewString(regionName))
if len(regions) > 0 {
return regions, nil
}
} else {
// if there already exists an isolation region for this pod, just reuse it
regions, err := cra.getContainerRegions(ci, types.QoSRegionTypeIsolation)
if err != nil {
return nil, err
} else if len(regions) > 0 {
return regions, nil
}
}
r := region.NewQoSRegionIsolation(ci, regionName, cra.conf, cra.extraConf, cra.metaCache, cra.metaServer, cra.emitter)
klog.Infof("create a new isolation region (%s/%s) for container %s/%s", r.OwnerPoolName(), r.Name(), ci.PodUID, ci.ContainerName)
return []region.QoSRegion{r}, nil
}
// assign shared cores container. focus on pool.
regions := cra.getPoolRegions(ci.OriginOwnerPoolName)
if len(regions) > 0 {
return regions, nil
}
// create one region by owner pool name
r := region.NewQoSRegionShare(ci, cra.conf, cra.extraConf, cra.metaCache, cra.metaServer, cra.emitter)
klog.Infof("create a new share region (%s/%s) for container %s/%s", r.OwnerPoolName(), r.Name(), ci.PodUID, ci.ContainerName)
return []region.QoSRegion{r}, nil
} else if ci.IsNumaBinding() {
// assign dedicated cores numa exclusive containers. focus on container.
regions, err := cra.getContainerRegions(ci, types.QoSRegionTypeDedicatedNumaExclusive)
if err != nil {
return nil, err
} else if len(regions) > 0 {
return regions, nil
}
// create regions by numa node
for numaID := range ci.TopologyAwareAssignments {
r := region.NewQoSRegionDedicatedNumaExclusive(ci, cra.conf, numaID, cra.extraConf, cra.metaCache, cra.metaServer, cra.emitter)
regions = append(regions, r)
}
return regions, nil
}
return nil, nil
}
// gcRegionMap deletes empty regions in region map
func (cra *cpuResourceAdvisor) gcRegionMap() {
for regionName, r := range cra.regionMap {
if r.IsEmpty() {
delete(cra.regionMap, regionName)
klog.Infof("[qosaware-cpu] delete region %v", regionName)
}
}
}
// updateAdvisorEssentials updates following essentials after assigning containers to regions:
// 1. non-binding numas, i.e. numas without numa binding containers
// 2. binding numas of non numa binding regions
// 3. region quantity of each numa
func (cra *cpuResourceAdvisor) updateAdvisorEssentials() {
cra.nonBindingNumas = cra.metaServer.CPUDetails.NUMANodes()
// update non-binding numas
for _, r := range cra.regionMap {
if r.Type() == types.QoSRegionTypeDedicatedNumaExclusive {
cra.nonBindingNumas = cra.nonBindingNumas.Difference(r.GetBindingNumas())
}
}
// reset region quantity
for _, numaID := range cra.metaServer.CPUDetails.NUMANodes().ToSliceInt() {
cra.numRegionsPerNuma[numaID] = 0
}
for _, r := range cra.regionMap {
// set binding numas for non numa binding regions
if r.Type() == types.QoSRegionTypeShare {
r.SetBindingNumas(cra.nonBindingNumas)
}
// accumulate region quantity for each numa
for _, numaID := range r.GetBindingNumas().ToSliceInt() {
cra.numRegionsPerNuma[numaID] += 1
}
}
}
// assembleProvision generates internal calculation result.
// must make sure pool names from cpu provision following qrm definition;
// numa ID set as -1 means no numa-preference is needed.
func (cra *cpuResourceAdvisor) assembleProvision() (types.InternalCPUCalculationResult, error) {
if cra.provisionAssembler == nil {
return types.InternalCPUCalculationResult{}, fmt.Errorf("no legal provision assembler")
}
calculationResult, err := cra.provisionAssembler.AssembleProvision()
return calculationResult, err
}
func (cra *cpuResourceAdvisor) emitMetrics(calculationResult types.InternalCPUCalculationResult) {
// emit region indicator related metrics
for _, r := range cra.regionMap {
tags := region.GetRegionBasicMetricTags(r)
_ = cra.emitter.StoreInt64(metricRegionStatus, int64(cra.period.Seconds()), metrics.MetricTypeNameCount, tags...)
indicators := r.GetControlEssentials().Indicators
for indicatorName, indicator := range indicators {
_ = cra.emitter.StoreFloat64(metricRegionIndicatorTargetPrefix+indicatorName, indicator.Target, metrics.MetricTypeNameRaw, tags...)
_ = cra.emitter.StoreFloat64(metricRegionIndicatorCurrentPrefix+indicatorName, indicator.Current, metrics.MetricTypeNameRaw, tags...)
_ = cra.emitter.StoreFloat64(metricRegionIndicatorErrorPrefix+indicatorName, indicator.Current-indicator.Target, metrics.MetricTypeNameRaw, tags...)
}
}
// emit calculated pool sizes
for poolName, poolEntry := range calculationResult.PoolEntries {
for numaID, size := range poolEntry {
_ = cra.emitter.StoreInt64(metricCPUAdvisorPoolSize, int64(size), metrics.MetricTypeNameRaw,
metrics.MetricTag{Key: "name", Val: poolName},
metrics.MetricTag{Key: "numa_id", Val: strconv.Itoa(numaID)},
metrics.MetricTag{Key: "pool_type", Val: state.GetPoolType(poolName)})
}
}
}