@@ -6,14 +6,13 @@ import (
6
6
"strconv"
7
7
"sync"
8
8
9
- enginefactory "github.com/projecteru2/core/engine/factory"
10
9
"github.com/projecteru2/core/log"
11
10
"github.com/projecteru2/core/resource"
12
11
"github.com/projecteru2/core/resource/cobalt"
13
12
plugintypes "github.com/projecteru2/core/resource/plugins/types"
14
13
"github.com/projecteru2/core/types"
15
14
"github.com/projecteru2/core/utils"
16
- io_prometheus_client "github.com/prometheus/client_model/go"
15
+ promClient "github.com/prometheus/client_model/go"
17
16
"golang.org/x/exp/slices"
18
17
19
18
statsdlib "github.com/CMGS/statsd"
@@ -88,55 +87,16 @@ func (m *Metrics) SendMetrics(ctx context.Context, metrics ...*plugintypes.Metri
88
87
}
89
88
}
90
89
91
- func (m * Metrics ) DeleteInactiveNodesWithCache (ctx context.Context , activeNodesMap map [string ]* types.Node ) {
92
- metricNodeNameMap := m .getNodeNameMapFromMetrics ()
93
- // 计算差集
94
- invalidNodes := make ([]string , 0 )
95
- for nodeName := range metricNodeNameMap {
96
- if node , exists := activeNodesMap [nodeName ]; ! exists {
97
- invalidNodes = append (invalidNodes , nodeName )
98
- enginefactory .RemoveEngineFromCache (ctx , node .Endpoint , node .Ca , node .Cert , node .Key )
99
- }
100
- }
101
- m .RemoveInvalidNodes (invalidNodes )
102
- }
103
-
104
- func (m * Metrics ) getNodeNameMapFromMetrics () map [string ]bool {
105
- metrics , _ := prometheus .DefaultGatherer .Gather ()
106
- nodeNameMap := make (map [string ]bool , 0 )
107
- for _ , metric := range metrics {
108
- for _ , mf := range metric .GetMetric () {
109
- if len (mf .Label ) == 0 {
110
- continue
111
- }
112
- for _ , label := range mf .Label {
113
- if label .GetName () == "nodename" {
114
- nodeNameMap [label .GetValue ()] = true
115
- break
116
- }
117
- }
118
- }
119
- }
120
- return nodeNameMap
121
- }
122
-
123
90
// RemoveInvalidNodes 清除多余的metric标签值
124
- func (m * Metrics ) RemoveInvalidNodes (invalidNodes [] string ) {
91
+ func (m * Metrics ) RemoveInvalidNodes (invalidNodes ... string ) {
125
92
if len (invalidNodes ) == 0 {
126
93
return
127
94
}
128
95
for _ , collector := range m .Collectors {
129
- if collector == nil {
130
- return
131
- }
132
96
metrics , _ := prometheus .DefaultGatherer .Gather ()
133
97
for _ , metric := range metrics {
134
98
for _ , mf := range metric .GetMetric () {
135
- if len (mf .Label ) == 0 {
136
- continue
137
- }
138
-
139
- if ! slices .ContainsFunc (mf .Label , func (label * io_prometheus_client.LabelPair ) bool {
99
+ if ! slices .ContainsFunc (mf .Label , func (label * promClient.LabelPair ) bool {
140
100
return label .GetName () == "nodename" && slices .ContainsFunc (invalidNodes , func (nodename string ) bool {
141
101
return label .GetValue () == nodename
142
102
})
0 commit comments