Skip to content

Commit

Permalink
Merge pull request #978 from iamemilio/secure_agent_connect
Browse files Browse the repository at this point in the history
hotfix security agent: only refresh state when connected to new relic
  • Loading branch information
iamemilio authored Oct 24, 2024
2 parents 694f21f + c9b52de commit aa932cf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
13 changes: 10 additions & 3 deletions v3/internal/connect_reply.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ const (
// consumer.
func CreateFullTxnName(input string, reply *ConnectReply, isWeb bool) string {
var afterURLRules string
if "" != input {
if input != "" {
afterURLRules = reply.URLRules.Apply(input)
if "" == afterURLRules {
if afterURLRules == "" {
return ""
}
}
Expand All @@ -249,7 +249,7 @@ func CreateFullTxnName(input string, reply *ConnectReply, isWeb bool) string {
}

afterNameRules := reply.TxnNameRules.Apply(beforeNameRules)
if "" == afterNameRules {
if afterNameRules == "" {
return ""
}

Expand All @@ -266,6 +266,13 @@ const (
CustomEventHarvestsPerMinute = 5
)

// IsConnectedToNewRelic returns true if the connect reply is a valid connect reply
// from a New Relic connect endpoint. This is determined by the presence of a RunID
// and an EntityGUID which the agent needs to send data to a collector.
func (r *ConnectReply) IsConnectedToNewRelic() bool {
return r != nil && r.RunID != "" && r.EntityGUID != ""
}

// MockConnectReplyEventLimits sets up a mock connect reply to test event limits
// currently only verifies custom insights events
func (r *ConnectReply) MockConnectReplyEventLimits(limits *RequestEventLimits) {
Expand Down
14 changes: 14 additions & 0 deletions v3/internal/connect_reply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,17 @@ func TestDefaultEventHarvestConfigJSON(t *testing.T) {
t.Errorf("DefaultEventHarvestConfig does not match expected valued:\nExpected:\t%s\nActual:\t\t%s", expect, string(js))
}
}

func TestConnectReply_IsConnectedToNewRelic(t *testing.T) {
reply := ConnectReplyDefaults()
if reply.IsConnectedToNewRelic() {
t.Error("Connect Reply Defaults should not be considered connected to New Relic")
}

reply = ConnectReplyDefaults()
reply.RunID = "foo"
reply.EntityGUID = "bar"
if !reply.IsConnectedToNewRelic() {
t.Error("Connect Reply with RunID and EntityGUID should be considered connected to New Relic")
}
}
2 changes: 1 addition & 1 deletion v3/newrelic/secure_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (app *Application) RegisterSecurityAgent(s securityAgent) {
if app != nil && app.app != nil && s != nil {
secureAgent = s
run, _ := app.app.getState()
if run != nil {
if run.Reply.IsConnectedToNewRelic() {
secureAgent.RefreshState(getLinkedMetaData(app.app))
}
}
Expand Down

0 comments on commit aa932cf

Please sign in to comment.