newrelic / infra-integrations-sdk

New Relic Infrastructure Integrations SDK
Apache License 2.0
46 stars 24 forks source link

NewEntity does add the new entity to the integration #275

Open jregovic opened 3 years ago

jregovic commented 3 years ago

Description

When calling integration.NewEntity in an integration, the entity is not added to the list of entities for the integration. This results in the integration data being missing

Expected Behavior

The entity should be added to the list of integrations and the data serialized.

Steps to Reproduce

{"protocol_version":"4","integration":{"name":"com.myorg.redis","version":"0.1.0"},"data":[]}

## Your Environment
MacOS 10.15.7
infra-integrations-sdk v4.1.0

## Additional context
The issue is fixed by creating the entity and adding : 

i.Entities = append(i.Entities,entity) go run redis.go -metrics -hostname localhost

{"protocol_version":"4","integration":{"name":"com.myorg.redis","version":"0.1.0"},"data":[{"common":{},"entity":{"name":"redis_01","displayName":"RedisServer","type":"my-redis","metadata":{}},"metrics":[{"timestamp":1631239424,"name":"query.instantaneousOpsPerSecond","type":"gauge","attributes":{},"value":0}],"inventory":{},"events":[]}]}

jregovic commented 3 years ago

In v3.7.0, the somewhat equivalent method, Entity does add the new entity to the list of entities. https://github.com/newrelic/infra-integrations-sdk/blob/1f48f6c9407a8be59e2494cf7f426563420a46f1/integration/integration.go#L194

The AddEntity method exists, but it is not obvious that this would need to be called, especially when updating to the v4 protocol.