Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix security agent: only refresh state when connected to new relic #978

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
iamemilio marked this conversation as resolved.
Show resolved Hide resolved
secureAgent.RefreshState(getLinkedMetaData(app.app))
}
}
Expand Down
Loading