-
Notifications
You must be signed in to change notification settings - Fork 106
/
fake_metric.go
153 lines (120 loc) · 5.77 KB
/
fake_metric.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
/*
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.
*/
// 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 metric
import (
"context"
"sync"
v1 "k8s.io/api/core/v1"
"github.com/kubewharf/katalyst-core/pkg/metrics"
"github.com/kubewharf/katalyst-core/pkg/util/machine"
"github.com/kubewharf/katalyst-core/pkg/util/metric"
)
// NewFakeMetricsFetcher returns a fake MetricsFetcher.
func NewFakeMetricsFetcher(emitter metrics.MetricEmitter) MetricsFetcher {
return &FakeMetricsFetcher{
metricStore: metric.NewMetricStore(),
emitter: emitter,
}
}
type FakeMetricsFetcher struct {
sync.RWMutex
metricStore *metric.MetricStore
emitter metrics.MetricEmitter
registeredMetric []func(store *metric.MetricStore)
}
func (f *FakeMetricsFetcher) Run(ctx context.Context) {
f.RLock()
defer f.RUnlock()
for _, fu := range f.registeredMetric {
fu(f.metricStore)
}
}
func (f *FakeMetricsFetcher) RegisterNotifier(scope MetricsScope, req NotifiedRequest, response chan NotifiedResponse) string {
return ""
}
func (f *FakeMetricsFetcher) DeRegisterNotifier(scope MetricsScope, key string) {}
func (f *FakeMetricsFetcher) RegisterExternalMetric(fu func(store *metric.MetricStore)) {
f.Lock()
defer f.Unlock()
f.registeredMetric = append(f.registeredMetric, fu)
}
func (f *FakeMetricsFetcher) GetNodeMetric(metricName string) (metric.MetricData, error) {
return f.metricStore.GetNodeMetric(metricName)
}
func (f *FakeMetricsFetcher) GetNumaMetric(numaID int, metricName string) (metric.MetricData, error) {
return f.metricStore.GetNumaMetric(numaID, metricName)
}
func (f *FakeMetricsFetcher) GetDeviceMetric(deviceName string, metricName string) (metric.MetricData, error) {
return f.metricStore.GetDeviceMetric(deviceName, metricName)
}
func (f *FakeMetricsFetcher) GetCPUMetric(coreID int, metricName string) (metric.MetricData, error) {
return f.metricStore.GetCPUMetric(coreID, metricName)
}
func (f *FakeMetricsFetcher) GetContainerMetric(podUID, containerName, metricName string) (metric.MetricData, error) {
return f.metricStore.GetContainerMetric(podUID, containerName, metricName)
}
func (f *FakeMetricsFetcher) GetContainerNumaMetric(podUID, containerName, numaNode, metricName string) (metric.MetricData, error) {
return f.metricStore.GetContainerNumaMetric(podUID, containerName, numaNode, metricName)
}
func (f *FakeMetricsFetcher) SetNodeMetric(metricName string, data metric.MetricData) {
f.metricStore.SetNodeMetric(metricName, data)
}
func (f *FakeMetricsFetcher) SetNumaMetric(numaID int, metricName string, data metric.MetricData) {
f.metricStore.SetNumaMetric(numaID, metricName, data)
}
func (f *FakeMetricsFetcher) SetCPUMetric(cpu int, metricName string, data metric.MetricData) {
f.metricStore.SetCPUMetric(cpu, metricName, data)
}
func (f *FakeMetricsFetcher) SetDeviceMetric(deviceName string, metricName string, data metric.MetricData) {
f.metricStore.SetDeviceMetric(deviceName, metricName, data)
}
func (f *FakeMetricsFetcher) SetContainerMetric(podUID, containerName, metricName string, data metric.MetricData) {
f.metricStore.SetContainerMetric(podUID, containerName, metricName, data)
}
func (f *FakeMetricsFetcher) SetContainerNumaMetric(podUID, containerName, numaNode, metricName string, data metric.MetricData) {
f.metricStore.SetContainerNumaMetric(podUID, containerName, numaNode, metricName, data)
}
func (f *FakeMetricsFetcher) AggregatePodNumaMetric(podList []*v1.Pod, numaNode, metricName string, agg metric.Aggregator, filter metric.ContainerMetricFilter) metric.MetricData {
return f.metricStore.AggregatePodNumaMetric(podList, numaNode, metricName, agg, filter)
}
func (f *FakeMetricsFetcher) AggregatePodMetric(podList []*v1.Pod, metricName string, agg metric.Aggregator, filter metric.ContainerMetricFilter) metric.MetricData {
return f.metricStore.AggregatePodMetric(podList, metricName, agg, filter)
}
func (f *FakeMetricsFetcher) AggregateCoreMetric(cpuset machine.CPUSet, metricName string, agg metric.Aggregator) metric.MetricData {
return f.metricStore.AggregateCoreMetric(cpuset, metricName, agg)
}
func (f *FakeMetricsFetcher) SetCgroupMetric(cgroupPath, metricName string, data metric.MetricData) {
f.metricStore.SetCgroupMetric(cgroupPath, metricName, data)
}
func (f *FakeMetricsFetcher) GetCgroupMetric(cgroupPath, metricName string) (metric.MetricData, error) {
return f.metricStore.GetCgroupMetric(cgroupPath, metricName)
}
func (f *FakeMetricsFetcher) SetCgroupNumaMetric(cgroupPath, numaNode, metricName string, data metric.MetricData) {
f.metricStore.SetCgroupNumaMetric(cgroupPath, numaNode, metricName, data)
}
func (f *FakeMetricsFetcher) GetCgroupNumaMetric(cgroupPath, numaNode, metricName string) (metric.MetricData, error) {
return f.metricStore.GetCgroupNumaMetric(cgroupPath, numaNode, metricName)
}