-
Notifications
You must be signed in to change notification settings - Fork 55
/
util.go
96 lines (83 loc) · 3.04 KB
/
util.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
package vulcanizer
import (
"errors"
"fmt"
"strings"
"github.com/tidwall/gjson"
)
func excludeSettingsFromJSON(settings []gjson.Result) ExcludeSettings {
excludeSettings := ExcludeSettings{}
if settings[0].String() == "" {
excludeSettings.Ips = []string{}
} else {
excludeSettings.Ips = strings.Split(settings[0].String(), ",")
}
if settings[1].String() == "" {
excludeSettings.Names = []string{}
} else {
excludeSettings.Names = strings.Split(settings[1].String(), ",")
}
if settings[2].String() == "" {
excludeSettings.Hosts = []string{}
} else {
excludeSettings.Hosts = strings.Split(settings[2].String(), ",")
}
return excludeSettings
}
// Returns caption based on cluster health explaining the meaning of this state.
func captionHealth(clusterHealth ClusterHealth) (caption string) {
unhealthyIndexList := make([]string, 0, len(clusterHealth.UnhealthyIndices))
for _, index := range clusterHealth.UnhealthyIndices {
status := fmt.Sprintf("%s is %s. %d shards are unassigned.", index.Name, index.Status, index.UnassignedShards)
unhealthyIndexList = append(unhealthyIndexList, status)
}
switch clusterHealth.Status {
case "red":
caption := fmt.Sprintf("The cluster is red: One or more primary shards is not allocated on an index or indices. Please check for missing instances and return them to service if possible.\n%s", strings.Join(unhealthyIndexList, "\n"))
return caption
case "yellow":
caption := fmt.Sprintf("The cluster is yellow: One or more replica shards is not allocated on an index or indices. Please check for missing instances and return them to service if possible.\n%s", strings.Join(unhealthyIndexList, "\n"))
return caption
case "green":
caption := "The cluster is green: All primary and replica shards are allocated. This does NOT mean the cluster is otherwise healthy."
return caption
default:
return clusterHealth.Status
}
}
func enrichNodesWithAllocations(nodes []Node, allocations []DiskAllocation) []Node {
nodeAllocation := make(map[string]DiskAllocation)
for _, alloc := range allocations {
nodeAllocation[alloc.Node] = alloc
}
enrichedNodes := make([]Node, 0, len(nodes))
for _, node := range nodes {
enrichedNode := Node{
Name: node.Name,
IP: node.IP,
ID: node.ID,
Role: node.Role,
Master: node.Master,
Jdk: node.Jdk,
Version: node.Version,
Shards: nodeAllocation[node.Name].Shards,
DiskIndices: nodeAllocation[node.Name].DiskIndices,
DiskUsed: nodeAllocation[node.Name].DiskUsed,
DiskAvail: nodeAllocation[node.Name].DiskAvail,
DiskTotal: nodeAllocation[node.Name].DiskTotal,
DiskPercent: nodeAllocation[node.Name].DiskPercent,
}
enrichedNodes = append(enrichedNodes, enrichedNode)
}
return enrichedNodes
}
func combineErrors(errs []error) error {
errorText := []string{}
for _, err := range errs {
errorText = append(errorText, err.Error())
}
return errors.New(strings.Join(errorText, "\n"))
}
func escapeIndexName(index string) string {
return strings.ReplaceAll(index, ".", "\\.")
}