Skip to content

Commit 430cc8e

Browse files
authored
Merge pull request #34 from newrelic/config-parse-fix
Fixed bug when reading a config yml file that had nested objects
2 parents c5798b3 + deda568 commit 430cc8e

6 files changed

+40
-3
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## 1.1.0 - 2018-11-28
9+
### Added
10+
- ClusterEnvironment argument to help further identify clusters
11+
### Fixed
12+
- Issue when loading a config yaml file that had nested objects. Theses objects are ignored for inventory data.
13+
814
## 1.0.1 - 2018-11-20
915
### Changed
1016
- Added host and IP to Nodes as additional attributes

elasticsearch-config.yml.sample

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ instances:
44
- name: elasticsearch
55
command: <"all" or "inventory">
66
arguments:
7+
cluster_environment: <A way to further specify which cluster we are gathering data for, example: 'staging'>
78
config_path: <absolute path to the ElasticSearch configuration .yml file. (default "/etc/elasticsearch/elasticsearch.yml")>
89
hostname: <hostname or IP where Elasticsearch Node is running. (default "localhost")>
910
local_hostname: <(Optional) Hostname or IP of the Elasticsearch node from which to collect inventory data. (default "localhost"). Should only be set if you do not wish to collect inventory data against localhost>

src/elasticsearch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type argumentList struct {
2828

2929
const (
3030
integrationName = "com.newrelic.elasticsearch"
31-
integrationVersion = "1.0.1"
31+
integrationVersion = "1.1.0"
3232
)
3333

3434
var (

src/inventory.go

+10
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ func populateConfigInventory(entity *integration.Entity) error {
6666
}
6767

6868
for key, value := range configYaml {
69+
// special case to look for nested types
70+
switch value.(type) {
71+
case map[interface{}]interface{}:
72+
log.Debug("Unsupported data type '%T' for yaml key %s", value, key)
73+
continue
74+
case []interface{}:
75+
log.Debug("Unsupported data type '%T' for yaml key %s", value, key)
76+
continue
77+
}
78+
6979
err = entity.SetInventoryItem("config/"+key, "value", value)
7080
if err != nil {
7181
log.Error("Could not set inventory item: %v", err)

src/inventory_test.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ func TestReadConfigFile(t *testing.T) {
3838
"path.data": "/var/lib/elasticsearch",
3939
"path.logs": "/var/log/elasticsearch",
4040
"network.host": "0.0.0.0",
41+
"xpack": map[interface{}]interface{}{
42+
"security": map[interface{}]interface{}{
43+
"authc": "ssl",
44+
},
45+
},
46+
"items": []interface{}{
47+
"one",
48+
2,
49+
},
4150
},
4251
},
4352
}
@@ -49,7 +58,7 @@ func TestReadConfigFile(t *testing.T) {
4958
t.Errorf("couldn't read config file: %v", err)
5059
} else {
5160
if expected := reflect.DeepEqual(tc.expectedMap, resultMap); !expected {
52-
t.Errorf("maps didn't match")
61+
t.Errorf("Expected %+v got %+v", tc.expectedMap, resultMap)
5362
}
5463
}
5564
}
@@ -86,7 +95,10 @@ func TestPopulateConfigInventory(t *testing.T) {
8695

8796
populateConfigInventory(e)
8897

89-
actual, _ := i.MarshalJSON()
98+
actual, err := i.MarshalJSON()
99+
if err != nil {
100+
t.Fatalf("Failed to create json: %s", err.Error())
101+
}
90102

91103
writeGoldenFile(t, goldenPath, actual)
92104

src/testdata/elasticsearch_sample.yml

+8
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,11 @@ network.host: 0.0.0.0
8686
# Require explicit names when deleting indices:
8787
#
8888
#action.destructive_requires_name: true
89+
90+
xpack:
91+
security:
92+
authc: "ssl"
93+
94+
items:
95+
- "one"
96+
- 2

0 commit comments

Comments
 (0)