Skip to content

Commit

Permalink
Fix nrUpdateConfig issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
asllop committed Mar 16, 2023
1 parent 5d361c8 commit 6d76dc2
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# CHANGELOG
All notable changes to this project will be documented in this file.

## [3.1.2] - 2023/03/16
### Fix
- `nrUpdateConfig` bug.
- Documentation errata.
### Update
- Remove unused field in NRAgent.

## [3.1.1] - 2022/10/04
### Fix
- Crash happening when using a playlist.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,8 @@ Return:
Nothing
Example:
config = { networkProxy: "http://example.com:8888/;" }
nrUpdateConig(m.nr, config)
config = { proxyUrl: "http://example.com:8888/;" }
nrUpdateConfig(m.nr, config)
```

**nrSendLog**
Expand Down
18 changes: 11 additions & 7 deletions components/NewRelicAgent/NRAgent.brs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ sub init()
m.logApiUrl = ""
m.metricApiUrl = ""
m.nrRegion = "US"
m.testServer = "http://my.test.server:8888"
print "************************************************************"
print " New Relic Agent for Roku v" + m.nrAgentVersion
print " Copyright 2019-2022 New Relic Inc. All Rights Reserved."
Expand Down Expand Up @@ -116,7 +117,7 @@ function NewRelicInit(account as String, apikey as String, region as String) as
'Create and configure tasks (metrics)
m.bgTaskMetrics = m.top.findNode("NRTaskMetrics")
m.bgTaskMetrics.setField("apiKey", m.nrInsightsApiKey)
m.metricApiUrl = box(nrMetricsApiUrl())
m.metricApiUrl = box(nrMetricApiUrl())
m.bgTaskMetrics.setField("metricApiUrl", m.metricApiUrl)
m.bgTaskMetrics.sampleType = "metric"

Expand Down Expand Up @@ -201,10 +202,13 @@ end function
function nrUpdateConfig(config as object) as void
if config = invalid then return
if config.proxyUrl <> invalid
nrLog("------------> Set Proxy Url " + config.proxyUrl)
m.eventApiUrl = box(nrEventApiUrl())
m.logApiUrl = box(nrLogApiUrl())
m.bgTask.setField("eventApiUrl", config.proxyUrl + m.eventApiUrl)
m.bgTask.setField("logApiUrl", config.proxyUrl + m.logApiUrl)
m.metricApiUrl = box(nrMetricApiUrl())
m.bgTaskEvents.setField("eventApiUrl", config.proxyUrl + m.eventApiUrl)
m.bgTaskLogs.setField("logApiUrl", config.proxyUrl + m.logApiUrl)
m.bgTaskMetrics.setField("metricApiUrl", config.proxyUrl + m.logApiUrl)
end if
end function

Expand Down Expand Up @@ -828,7 +832,7 @@ function nrEventApiUrl() as String
return "https://insights-collector.eu01.nr-data.net/v1/accounts/" + m.nrAccountNumber + "/events"
else if m.nrRegion = "TEST"
'NOTE: set address hosting the test server
return "http://x.x.x.x:5000/event"
return m.testServer + "/event"
end if
end function

Expand All @@ -839,18 +843,18 @@ function nrLogApiUrl() as String
return "https://log-api.eu.newrelic.com/log/v1"
else if m.nrRegion = "TEST"
'NOTE: set address hosting the test server
return "http://x.x.x.x:5000/log"
return m.testServer + "/log"
end if
end function

function nrMetricsApiUrl() as String
function nrMetricApiUrl() as String
if m.nrRegion = "US"
return "https://metric-api.newrelic.com/metric/v1"
else if m.nrRegion = "EU"
return "https://metric-api.eu.newrelic.com/metric/v1"
else if m.nrRegion = "TEST"
'NOTE: set address hosting the test server
return "http://x.x.x.x:5000/metric"
return m.testServer + "/metric"
end if
end function

Expand Down
2 changes: 1 addition & 1 deletion components/NewRelicAgent/NRAgent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<interface>
<!-- Properties -->
<field id="version" type="string" value="3.1.1"/>
<field id="version" type="string" value="3.1.2"/>
<!-- Public Methods (wrapped) -->
<function name="NewRelicInit"/>
<function name="NewRelicVideoStart"/>
Expand Down
18 changes: 12 additions & 6 deletions components/NewRelicAgent/NRTask.brs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ function nrPushSamples(samples as Object, endpoint as String, sampleType as Stri
end function

function nrEventProcessor() as Void
m.nr.callFunc("nrLog", "-- nrEventProcessor --")
m.nr.callFunc("nrLog", "-- nrEventProcessor at URL " + m.eventApiUrl)
nrSampleProcessor("event", m.eventApiUrl)
end function

function nrLogProcessor() as Void
m.nr.callFunc("nrLog", "-- nrLogProcessor --")
m.nr.callFunc("nrLog", "-- nrLogProcessor at URL " + m.logApiUrl)
nrSampleProcessor("log", m.logApiUrl)
end function

function nrMetricProcessor() as Void
m.nr.callFunc("nrLog", "-- nrMetricProcessor --")
m.nr.callFunc("nrLog", "-- nrMetricProcessor at URL " + m.metricApiUrl)
nrSampleProcessor("metric", m.metricApiUrl)
end function

Expand Down Expand Up @@ -89,10 +89,10 @@ function nrTaskMain() as Void
'Assuming that parent node is com.newrelic.NRAgent
m.nr = m.top.getParent()
m.apiKey = m.top.apiKey
m.eventApiUrl = m.top.eventApiUrl
m.logApiUrl = m.top.logApiUrl
m.metricApiUrl = m.top.metricApiUrl
m.sampleType = m.top.sampleType
if m.eventApiUrl = "" then m.eventApiUrl = m.top.eventApiUrl
if m.logApiUrl = "" then m.logApiUrl = m.top.logApiUrl
if m.metricApiUrl = "" then m.metricApiUrl = m.top.metricApiUrl
end if
m.nr.callFunc("nrLog", "---- Running NRTask ---- " + m.sampleType)
if m.sampleType = "event"
Expand All @@ -103,4 +103,10 @@ function nrTaskMain() as Void
nrMetricProcessor()
end if
m.nr.callFunc("nrLog", "---- Ended running NRTask ---- " + m.sampleType)
end function

function onConfigUpdate() as Void
m.eventApiUrl = m.top.eventApiUrl
m.logApiUrl = m.top.logApiUrl
m.metricApiUrl = m.top.metricApiUrl
end function
6 changes: 3 additions & 3 deletions components/NewRelicAgent/NRTask.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<component name="com.newrelic.NRTask" extends="Task">
<interface>
<!-- Properties -->
<field id="eventApiUrl" type="string" value=""/>
<field id="logApiUrl" type="string" value=""/>
<field id="metricApiUrl" type="string" value=""/>
<field id="eventApiUrl" type="string" onChange="onConfigUpdate" value=""/>
<field id="logApiUrl" type="string" onChange="onConfigUpdate" value=""/>
<field id="metricApiUrl" type="string" onChange="onConfigUpdate" value=""/>
<field id="apiKey" type="string" value=""/>
<field id="sampleType" type="string" value=""/>
</interface>
Expand Down
2 changes: 1 addition & 1 deletion components/SearchTask.brs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function searchTaskMain()
_url = box("https://www.google.com/search?source=hp&q=" + m.top.searchString)
if Rnd(5) = 4
' Generates an error
_url = box("https://www.google.com/shitrequest")
_url = box("https://www.google.com/wrongrequest")
end if
urlReq = CreateObject("roUrlTransfer")
urlReq.SetUrl(_url)
Expand Down

0 comments on commit 6d76dc2

Please sign in to comment.