@@ -5,12 +5,8 @@ import (
5
5
"net/http"
6
6
7
7
"github.com/projecteru2/core/cluster"
8
- enginefactory "github.com/projecteru2/core/engine/factory"
9
8
"github.com/projecteru2/core/log"
10
9
"github.com/projecteru2/core/types"
11
- "github.com/prometheus/client_golang/prometheus"
12
- promClient "github.com/prometheus/client_model/go"
13
- "golang.org/x/exp/slices"
14
10
)
15
11
16
12
// ResourceMiddleware to make sure update resource correct
@@ -24,42 +20,15 @@ func (m *Metrics) ResourceMiddleware(cluster cluster.Cluster) func(http.Handler)
24
20
if err != nil {
25
21
logger .Error (ctx , err , "Get all nodes err" )
26
22
}
27
- existNodenames := getExistNodenames ()
28
- activeNodes := map [string ]* types.Node {}
29
23
for node := range nodes {
30
24
metrics , err := m .rmgr .GetNodeMetrics (ctx , node )
31
25
if err != nil {
32
26
logger .Error (ctx , err , "Get metrics failed" )
33
27
continue
34
28
}
35
- activeNodes [node .Name ] = node
36
29
m .SendMetrics (ctx , metrics ... )
37
30
}
38
- // refresh nodes
39
- invalidNodenames := []string {}
40
- for _ , nodename := range existNodenames {
41
- if node := activeNodes [nodename ]; node != nil {
42
- invalidNodenames = append (invalidNodenames , nodename )
43
- enginefactory .RemoveEngineFromCache (ctx , node .Endpoint , node .Ca , node .Cert , node .Key )
44
- }
45
- }
46
- m .RemoveInvalidNodes (invalidNodenames ... )
47
31
h .ServeHTTP (w , r )
48
32
})
49
33
}
50
34
}
51
-
52
- func getExistNodenames () []string {
53
- metrics , _ := prometheus .DefaultGatherer .Gather ()
54
- nodenames := []string {}
55
- for _ , metric := range metrics {
56
- for _ , mf := range metric .GetMetric () {
57
- if i := slices .IndexFunc (mf .Label , func (label * promClient.LabelPair ) bool {
58
- return label .GetName () == "nodename"
59
- }); i != - 1 {
60
- nodenames = append (nodenames , mf .Label [i ].GetValue ())
61
- }
62
- }
63
- }
64
- return nodenames
65
- }
0 commit comments