@@ -39,7 +39,7 @@ func populateMetrics(i *integration.Integration, client Client, env string) {
39
39
}
40
40
}
41
41
42
- func populateNodesMetrics (i * integration.Integration , client Client , clusterName * string ) error {
42
+ func populateNodesMetrics (i * integration.Integration , client Client , clusterName string ) error {
43
43
log .Info ("Collecting node metrics" )
44
44
nodeResponse := new (NodeResponse )
45
45
err := client .Request (nodeStatsEndpoint , & nodeResponse )
@@ -52,35 +52,31 @@ func populateNodesMetrics(i *integration.Integration, client Client, clusterName
52
52
}
53
53
54
54
// setNodesMetricsResponse calls setMetricsResponse for each node in the response
55
- func setNodesMetricsResponse (integration * integration.Integration , resp * NodeResponse , clusterName * string ) {
55
+ func setNodesMetricsResponse (integration * integration.Integration , resp * NodeResponse , clusterName string ) {
56
56
for node := range resp .Nodes {
57
- err := setMetricsResponse (integration , resp .Nodes [node ], * resp .Nodes [node ].Name , "node" , clusterName )
57
+ err := setMetricsResponse (integration , resp .Nodes [node ], * resp .Nodes [node ].Name , "es- node" , clusterName )
58
58
if err != nil {
59
59
log .Error ("There was an error setting metrics for node metrics on %s: %v" , node , err )
60
60
}
61
61
}
62
62
}
63
63
64
- func populateClusterMetrics (i * integration.Integration , client Client , env string ) (* string , error ) {
64
+ func populateClusterMetrics (i * integration.Integration , client Client , env string ) (string , error ) {
65
65
log .Info ("Collecting cluster metrics." )
66
66
clusterResponse := new (ClusterResponse )
67
67
err := client .Request (clusterEndpoint , & clusterResponse )
68
68
if err != nil {
69
- return nil , err
69
+ return "" , err
70
70
}
71
71
72
72
if clusterResponse .Name == nil {
73
- return nil , errors .New ("cannot set metric response, missing cluster name" )
74
- }
75
-
76
- if env != "" {
77
- * clusterResponse .Name = * clusterResponse .Name + ":" + env
73
+ return "" , errors .New ("cannot set metric response, missing cluster name" )
78
74
}
79
75
80
- return clusterResponse .Name , setMetricsResponse (i , clusterResponse , * clusterResponse .Name , "cluster" , nil )
76
+ return * clusterResponse .Name , setMetricsResponse (i , clusterResponse , * clusterResponse .Name , "es- cluster" , * clusterResponse . Name )
81
77
}
82
78
83
- func populateCommonMetrics (i * integration.Integration , client Client , clusterName * string ) (* CommonMetrics , error ) {
79
+ func populateCommonMetrics (i * integration.Integration , client Client , clusterName string ) (* CommonMetrics , error ) {
84
80
log .Info ("Collecting common metrics." )
85
81
commonResponse := new (CommonMetrics )
86
82
err := client .Request (commonStatsEndpoint , & commonResponse )
@@ -89,13 +85,13 @@ func populateCommonMetrics(i *integration.Integration, client Client, clusterNam
89
85
}
90
86
91
87
if args .CollectPrimaries {
92
- err = setMetricsResponse (i , commonResponse .All , "commonMetrics" , "common" , clusterName )
88
+ err = setMetricsResponse (i , commonResponse .All , "commonMetrics" , "es- common" , clusterName )
93
89
}
94
90
95
91
return commonResponse , err
96
92
}
97
93
98
- func populateIndicesMetrics (i * integration.Integration , client Client , commonStats * CommonMetrics , clusterName * string ) error {
94
+ func populateIndicesMetrics (i * integration.Integration , client Client , commonStats * CommonMetrics , clusterName string ) error {
99
95
log .Info ("Collecting indices metrics" )
100
96
indicesStats := make ([]* IndexStats , 0 )
101
97
err := client .Request (indicesStatsEndpoint , & indicesStats )
@@ -122,7 +118,7 @@ func buildRegex() (indexRegex *regexp.Regexp, err error) {
122
118
return indexRegex , nil
123
119
}
124
120
125
- func setIndicesStatsMetricsResponse (integration * integration.Integration , indexResponse []* IndexStats , commonResponse * CommonMetrics , clusterName * string , indexRegex * regexp.Regexp ) {
121
+ func setIndicesStatsMetricsResponse (integration * integration.Integration , indexResponse []* IndexStats , commonResponse * CommonMetrics , clusterName string , indexRegex * regexp.Regexp ) {
126
122
type indexStatsObject struct {
127
123
name string
128
124
stats * IndexStats
@@ -164,7 +160,7 @@ func setIndicesStatsMetricsResponse(integration *integration.Integration, indexR
164
160
}
165
161
166
162
for _ , index := range indicesToCollect {
167
- if err := setMetricsResponse (integration , index .stats , index .name , "index" , clusterName ); err != nil {
163
+ if err := setMetricsResponse (integration , index .stats , index .name , "es- index" , clusterName ); err != nil {
168
164
log .Error ("There was an error setting metrics for indices metrics: %v" , err )
169
165
}
170
166
}
@@ -180,27 +176,29 @@ func getIndexFromCommon(indexName string, indexList map[string]*Index) (*Index,
180
176
181
177
// setMetricsResponse creates an entity and a metric set for the
182
178
// type of response and calls MarshalMetrics using that response
183
- func setMetricsResponse (integration * integration.Integration , resp interface {}, name string , namespace string , clusterName * string ) error {
184
- entity , err := integration .Entity (name , namespace )
179
+ func setMetricsResponse (i * integration.Integration , resp interface {}, name string , namespace string , clusterName string ) error {
180
+ entityIDAttrs := []integration.IDAttribute {
181
+ {Key : "clusterName" , Value : clusterName },
182
+ }
183
+ if args .ClusterEnvironment != "" {
184
+ entityIDAttrs = append (entityIDAttrs , integration.IDAttribute {Key : "env" , Value : args .ClusterEnvironment })
185
+ }
186
+
187
+ entity , err := i .EntityReportedVia (fmt .Sprintf ("%s:%d" , args .Hostname , args .Port ), name , namespace , entityIDAttrs ... )
185
188
if err != nil {
186
189
return err
187
190
}
188
191
189
- idAttributes := []metric.Attribute {
192
+ msAttributes := []metric.Attribute {
190
193
{Key : "displayName" , Value : entity .Metadata .Name },
191
194
{Key : "entityName" , Value : entity .Metadata .Namespace + ":" + entity .Metadata .Name },
192
195
}
193
196
194
- // If clusterName is non empty apply it
195
- if clusterName != nil {
196
- idAttributes = append (idAttributes , metric.Attribute {Key : "clusterName" , Value : * clusterName })
197
- }
198
-
199
- metricSet := entity .NewMetricSet (getSampleName (namespace ), idAttributes ... )
197
+ metricSet := entity .NewMetricSet (getSampleName (namespace ), msAttributes ... )
200
198
201
199
return metricSet .MarshalMetrics (resp )
202
200
}
203
201
204
202
func getSampleName (entityType string ) string {
205
- return fmt .Sprintf ("Elasticsearch%sSample" , strings .Title (entityType ))
203
+ return fmt .Sprintf ("Elasticsearch%sSample" , strings .Title (strings . TrimPrefix ( entityType , "es-" ) ))
206
204
}
0 commit comments