Skip to content

Commit 132408d

Browse files
authored
Merge pull request #291 from newrelic/ignore_host_entity
Add ignore_entity attribute
2 parents ad165dd + af148ab commit 132408d

File tree

4 files changed

+72
-23
lines changed

4 files changed

+72
-23
lines changed

docs/v3tov4.md

+16
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The Go SDK v4 contains the following changes:
1010
* New metric data types: `count`, `summary`, `cumulative-count` and `cumulative-rate`.
1111
* Support for Prometheus Histogram and Summary metrics
1212
* LocalEntity has been replaced by HostEntity.
13+
* Support for disabling entity registration (IgnoreEntity).
1314
* Support for Go Modules
1415
* Removed support for protocols prior to v4.x.
1516

@@ -33,6 +34,7 @@ These are the most important changes:
3334
},
3435
"data":[ # List of objects containing entities, metrics, events and inventory
3536
{
37+
"ignore_entity": false,
3638
"entity":{ # this object is optional. If it's not provided, then the Entity will get
3739
# the same entity ID as the agent that executes the integration.
3840
"name":"redis:192.168.100.200:1234", # unique entity name per customer account
@@ -160,6 +162,20 @@ To add a tag just call
160162

161163
On both cases, if the `key` already exists the previous value will be overwritten with the new one.
162164

165+
#### Ignore entity
166+
167+
In older versions, the entity payload was decorated by the infra agent with an entity id to uniquely identify it in New
168+
Relic One. The entity registration method for New Relic has changed, the current default strategy is named entity
169+
synthesis, which can identify unique entities from its metadata and metrics name. You can find more information [here](https://docs.newrelic.com/docs/new-relic-one/core-concepts/what-entity-new-relic/).
170+
171+
All new integrations should be able to register using the entity synthesis strategy, but for backwards compatability and
172+
possible new host integrations, you can use the `IgnoreEntity` attribute for each entity.
173+
174+
By default, `IgnoreEntity` will be set to true, thus the agent will not register the entity. Nonetheless, if your entity
175+
needs to be registered or use the infra agent entity id just call:
176+
177+
`func (i *Entity) SetIgnoreEntity(value bool)`
178+
163179
### Metrics
164180

165181
#### Types

integration/entity.go

+15-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ type Entity struct {
1818
Metrics metric.Metrics `json:"metrics"`
1919
Inventory *inventory.Inventory `json:"inventory"`
2020
Events event.Events `json:"events"`
21-
lock sync.Locker
21+
// IgnoreEntity defines if the Entity should be registered within the infra agent, if true
22+
// the Entity will not be attached to the infra agent entity neither registered.
23+
IgnoreEntity bool `json:"ignore_entity"`
24+
lock sync.Locker
2225
}
2326

2427
// Common is the producer of the common dimensions/attributes.
@@ -114,6 +117,11 @@ func (e *Entity) AddMetadata(key string, value interface{}) error {
114117
return nil
115118
}
116119

120+
// SetIgnoreEntity set if the infra agent should register the entity
121+
func (e *Entity) SetIgnoreEntity(value bool) {
122+
e.IgnoreEntity = value
123+
}
124+
117125
// Name is the unique entity identifier within a New Relic customer account.
118126
func (e *Entity) Name() string {
119127
return e.Metadata.Name
@@ -127,11 +135,12 @@ func newHostEntity() *Entity {
127135
CommonDimensions: Common{
128136
Attributes: make(map[string]interface{}),
129137
},
130-
Metadata: nil,
131-
Metrics: metric.Metrics{},
132-
Inventory: inventory.New(),
133-
Events: event.Events{},
134-
lock: &sync.Mutex{},
138+
Metadata: nil,
139+
Metrics: metric.Metrics{},
140+
Inventory: inventory.New(),
141+
Events: event.Events{},
142+
IgnoreEntity: true,
143+
lock: &sync.Mutex{},
135144
}
136145
}
137146

integration/entity_test.go

+28-11
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func Test_Entity_AnonymousEntityIsProperlySerialized(t *testing.T) {
196196
j, err := json.Marshal(e)
197197

198198
assert.NoError(t, err)
199-
assert.Equal(t, `{"common":{},"metrics":[],"inventory":{},"events":[]}`, string(j))
199+
assert.Equal(t, `{"common":{},"metrics":[],"inventory":{},"events":[],"ignore_entity":true}`, string(j))
200200
}
201201

202202
func Test_Entity_EntitiesWithSameMetadataAreSameAs(t *testing.T) {
@@ -228,11 +228,12 @@ func TestEntity_AddCommonDimension(t *testing.T) {
228228
"k": "v",
229229
},
230230
},
231-
Metadata: nil,
232-
Metrics: metric.Metrics{},
233-
Inventory: inventory.New(),
234-
Events: event.Events{},
235-
lock: &sync.Mutex{},
231+
Metadata: nil,
232+
Metrics: metric.Metrics{},
233+
Inventory: inventory.New(),
234+
Events: event.Events{},
235+
lock: &sync.Mutex{},
236+
IgnoreEntity: true,
236237
}},
237238
{"two entries", metric.Dimensions{"k1": "v1", "k2": "v2"}, &Entity{
238239
CommonDimensions: Common{
@@ -241,11 +242,12 @@ func TestEntity_AddCommonDimension(t *testing.T) {
241242
"k2": "v2",
242243
},
243244
},
244-
Metadata: nil,
245-
Metrics: metric.Metrics{},
246-
Inventory: inventory.New(),
247-
Events: event.Events{},
248-
lock: &sync.Mutex{},
245+
Metadata: nil,
246+
Metrics: metric.Metrics{},
247+
Inventory: inventory.New(),
248+
Events: event.Events{},
249+
lock: &sync.Mutex{},
250+
IgnoreEntity: true,
249251
}},
250252
}
251253
for _, tt := range tests {
@@ -320,3 +322,18 @@ func TestEntity_AddCommonInterval(t *testing.T) {
320322
})
321323
}
322324
}
325+
326+
func Test_SetIgnoreEntity(t *testing.T) {
327+
e := newHostEntity()
328+
e.SetIgnoreEntity(true)
329+
j, err := json.Marshal(e)
330+
assert.NoError(t, err)
331+
assert.Equal(t, `{"common":{},"metrics":[],"inventory":{},"events":[],"ignore_entity":true}`, string(j))
332+
assert.Equal(t, true, e.IgnoreEntity)
333+
334+
e.SetIgnoreEntity(false)
335+
j, err = json.Marshal(e)
336+
assert.NoError(t, err)
337+
assert.Equal(t, `{"common":{},"metrics":[],"inventory":{},"events":[],"ignore_entity":false}`, string(j))
338+
assert.Equal(t, false, e.IgnoreEntity)
339+
}

integration/integration_test.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ func Test_Integration_PublishThrowsNoError(t *testing.T) {
222222
"summary": "evnt2sum",
223223
"category": "evnt2cat"
224224
}
225-
]
225+
],
226+
"ignore_entity": false
226227
},
227228
{
228229
"common": {
@@ -248,7 +249,8 @@ func Test_Integration_PublishThrowsNoError(t *testing.T) {
248249
}
249250
],
250251
"inventory": {},
251-
"events": []
252+
"events": [],
253+
"ignore_entity": true
252254
},
253255
{
254256
"common": {
@@ -281,7 +283,8 @@ func Test_Integration_PublishThrowsNoError(t *testing.T) {
281283
}
282284
],
283285
"inventory": {},
284-
"events": []
286+
"events": [],
287+
"ignore_entity": true
285288
},
286289
{
287290
"common": {},
@@ -359,7 +362,8 @@ func Test_Integration_PublishThrowsNoError(t *testing.T) {
359362
"summary": "evnt2sum",
360363
"category": "evnt2cat"
361364
}
362-
]
365+
],
366+
"ignore_entity": true
363367
}
364368
]
365369
}`)
@@ -375,6 +379,7 @@ func Test_Integration_PublishThrowsNoError(t *testing.T) {
375379
e, err := i.NewEntity("EntityOne", "test", "")
376380
assert.NoError(t, err)
377381
_ = e.AddTag("env", "prod")
382+
e.SetIgnoreEntity(false)
378383

379384
gauge, _ := Gauge(time.Unix(10000000, 0), "metric-gauge", 1)
380385
count, _ := Count(time.Unix(10000000, 0), "metric-count", 100)
@@ -488,7 +493,8 @@ func Test_Integration_HostId(t *testing.T) {
488493
},
489494
"metrics": [],
490495
"inventory": {},
491-
"events": []
496+
"events": [],
497+
"ignore_entity": true
492498
},
493499
{
494500
"common": {
@@ -514,7 +520,8 @@ func Test_Integration_HostId(t *testing.T) {
514520
}
515521
],
516522
"inventory": {},
517-
"events": []
523+
"events": [],
524+
"ignore_entity": true
518525
}
519526
]
520527
}`)

0 commit comments

Comments
 (0)