Skip to content

Commit 75bb030

Browse files
authored
Merge pull request #38 from newrelic/unique-keys
Unique keys
2 parents b5a5a1e + a47e4e7 commit 75bb030

4 files changed

Lines changed: 21 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ 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+
## 2.0.0 - 2019-04-29
9+
### Changed
10+
- Added identity attributes for better uniqueness
11+
- Updated the SDK
12+
813
## 1.0.4 - 2019-03-19
914
### Changed
1015
- Include jvm-metrics.yml.sample in package

src/jmx.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type argumentList struct {
2929

3030
const (
3131
integrationName = "com.newrelic.jmx"
32-
integrationVersion = "1.0.4"
32+
integrationVersion = "2.0.0"
3333
)
3434

3535
var (
@@ -95,7 +95,7 @@ func main() {
9595
os.Exit(1)
9696
}
9797

98-
if err := runCollection(collection, jmxIntegration); err != nil {
98+
if err := runCollection(collection, jmxIntegration, args.JmxHost, args.JmxPort); err != nil {
9999
log.Error("Failed to complete collection: %s", err)
100100
}
101101
}

src/request.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type beanAttrValuePair struct {
2424
value interface{}
2525
}
2626

27-
func runCollection(collection []*domainDefinition, i *integration.Integration) error {
27+
func runCollection(collection []*domainDefinition, i *integration.Integration, host, port string) error {
2828
for _, domain := range collection {
2929
var errors []error
3030
for _, request := range domain.beans {
@@ -34,7 +34,7 @@ func runCollection(collection []*domainDefinition, i *integration.Integration) e
3434
log.Error("Failed to retrieve metrics for request %s: %s", requestString, err)
3535
return err
3636
}
37-
if err := handleResponse(domain.eventType, request, result, i); err != nil {
37+
if err := handleResponse(domain.eventType, request, result, i, host, port); err != nil {
3838
errors = append(errors, err)
3939
}
4040
}
@@ -50,7 +50,7 @@ func runCollection(collection []*domainDefinition, i *integration.Integration) e
5050
// handleResponse takes a response, filters out the excluded beans,
5151
// sorts the responses by domain, and passes each domain off to
5252
// insertDomainMetrics to populate the metric list
53-
func handleResponse(eventType string, request *beanRequest, response queryResponse, i *integration.Integration) error {
53+
func handleResponse(eventType string, request *beanRequest, response queryResponse, i *integration.Integration, host, port string) error {
5454

5555
// Delete excluded mbeans
5656
for key := range response {
@@ -75,7 +75,7 @@ func handleResponse(eventType string, request *beanRequest, response queryRespon
7575

7676
// For each domain, create an entity and a metric set
7777
for domain, beanAttrVals := range domainsMap {
78-
err := insertDomainMetrics(eventType, domain, beanAttrVals, request, i)
78+
err := insertDomainMetrics(eventType, domain, beanAttrVals, request, i, host, port)
7979
if err != nil {
8080
return err
8181
}
@@ -87,10 +87,12 @@ func handleResponse(eventType string, request *beanRequest, response queryRespon
8787
// insertDomainMetrics akes a domain and a list of attr:value pairs,
8888
// creates an entity and metric set for the domain, and populates the
8989
// metric set for each attribute to be collected
90-
func insertDomainMetrics(eventType string, domain string, beanAttrVals []*beanAttrValuePair, request *beanRequest, i *integration.Integration) error {
90+
func insertDomainMetrics(eventType string, domain string, beanAttrVals []*beanAttrValuePair, request *beanRequest, i *integration.Integration, host, port string) error {
9191

9292
// Create an entity for the domain
93-
e, err := i.Entity(domain, "domain")
93+
hostIDAttr := integration.NewIDAttribute("host", host)
94+
portIDAttr := integration.NewIDAttribute("port", port)
95+
e, err := i.Entity(domain, "jmx-domain", hostIDAttr, portIDAttr)
9496
if err != nil {
9597
return err
9698
}

src/request_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestRunCollection(t *testing.T) {
5454

5555
i, _ := integration.New("jmxtest", "0.1.0")
5656

57-
runCollection(collection, i)
57+
runCollection(collection, i, "testhost", "1234")
5858

5959
if !reflect.DeepEqual(expectedMetrics, i.Entities[0].Metrics[0].Metrics) {
6060
fmt.Println(pretty.Diff(expectedMetrics, i.Entities[0].Metrics[0].Metrics))
@@ -233,7 +233,7 @@ func TestInsertDomainMetrics(t *testing.T) {
233233

234234
eventType := "TestEventTypeSample"
235235

236-
insertDomainMetrics(eventType, domain, beanAttrVals, request, i)
236+
insertDomainMetrics(eventType, domain, beanAttrVals, request, i, "testhost", "1234")
237237

238238
expectedMetrics := map[string]interface{}{
239239
"event_type": "TestEventTypeSample",
@@ -268,14 +268,15 @@ func TestHandleResponse(t *testing.T) {
268268
}
269269
i, _ := integration.New("jmx", "0.1.0")
270270

271-
err := handleResponse(eventType, request, response, i)
271+
err := handleResponse(eventType, request, response, i, "testhost", "1234")
272272
if err != nil {
273273
t.Error(err)
274274
}
275275

276276
jsonbytes, _ := i.MarshalJSON()
277277

278-
expectedMarshalled := `{"name":"jmx","protocol_version":"3","integration_version":"0.1.0","data":[{"entity":{"name":"test.domain","type":"domain","id_attributes":[]},"metrics":[],"inventory":{},"events":[]}]}`
278+
fmt.Println(string(jsonbytes))
279+
expectedMarshalled := `{"name":"jmx","protocol_version":"3","integration_version":"0.1.0","data":[{"entity":{"name":"test.domain","type":"jmx-domain","id_attributes":[{"Key":"host","Value":"testhost"},{"Key":"port","Value":"1234"}]},"metrics":[],"inventory":{},"events":[]}]}`
279280

280281
if string(jsonbytes) != expectedMarshalled {
281282
t.Error("Failed to get expected marshalled json")
@@ -302,7 +303,7 @@ func TestDefaultMetricType(t *testing.T) {
302303
}
303304
i, _ := integration.New("jmx", "0.1.0")
304305

305-
err = handleResponse(eventType, request, response, i)
306+
err = handleResponse(eventType, request, response, i, "testhost", "1234")
306307
if err != nil {
307308
t.Error(err)
308309
}

0 commit comments

Comments
 (0)