Skip to content

Commit

Permalink
Add domain as attribute.
Browse files Browse the repository at this point in the history
  • Loading branch information
asllop committed Sep 1, 2022
1 parent ad2ae84 commit 8ea81f6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# CHANGELOG
All notable changes to this project will be documented in this file.

## [3.1.0] - 2022/09/01
### Add
- Attribute `domain` to all HTTP events and metrics.

## [3.0.2] - 2022/08/30
### Fix
- Harvest initial time, from 10 to 60 seconds.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ There is a set of attributes common to all actions sent over a `RokuSystem` and
| `httpCode` | Response code. | `HTTP_COMPLETE`, `HTTP_CONNECT`, `HTTP_ERROR`, `HTTP_RESPONSE` |
| `method` | HTTP method. | `HTTP_COMPLETE`, `HTTP_CONNECT`, `HTTP_ERROR`, `HTTP_REQUEST ` |
| `origUrl` | Original URL of request. | `HTTP_COMPLETE`, `HTTP_CONNECT`, `HTTP_ERROR`, `HTTP_REQUEST`, `HTTP_RESPONSE` |
| `domain` | Host part of `origUrl`. | `HTTP_COMPLETE`, `HTTP_CONNECT`, `HTTP_ERROR`, `HTTP_REQUEST`, `HTTP_RESPONSE` |
| `status` | Current request status. | `HTTP_COMPLETE`, `HTTP_CONNECT`, `HTTP_ERROR` |
| `targetIp` | Target IP address of request. | `HTTP_COMPLETE`, `HTTP_CONNECT`, `HTTP_ERROR` |
| `url` | Actual URL of request. | `HTTP_COMPLETE`, `HTTP_CONNECT`, `HTTP_ERROR` |
Expand Down Expand Up @@ -938,6 +939,8 @@ The Roku agent generates the following metrics OOTB:

Each metric is associated with an event generated by the agent.

All metrics include the attribute `domain`, that is the host of the HTTP request.

<a name="ad-track"></a>
### Ad Tracking

Expand Down
19 changes: 11 additions & 8 deletions components/NewRelicAgent/NRAgent.brs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ function nrSendVideoEvent(actionName as String, attr = invalid) as Void
end function

function nrSendHttpRequest(attr as Object) as Void
attr["domain"] = nrExtractDomainFromUrl(attr["origUrl"])
transId = stri(attr["transferIdentity"])
m.nrRequestIdentifiers[transId] = nrTimestamp()
'Clean up old transfers
Expand Down Expand Up @@ -277,13 +278,14 @@ function nrSendHttpRequest(attr as Object) as Void
end function

function nrSendHttpResponse(attr as Object) as Void
attr["domain"] = nrExtractDomainFromUrl(attr["origUrl"])
transId = stri(attr["transferIdentity"])
if m.nrRequestIdentifiers[transId] <> invalid
deltaMs = nrTimestamp() - m.nrRequestIdentifiers[transId]
attr["timeSinceHttpRequest"] = deltaMs
m.nrRequestIdentifiers.Delete(transId)
'Generate metrics
nrSendMetric("roku.http.response.time", deltaMs, {"host": nrExtractHostFromUrl(attr["origUrl"])})
nrSendMetric("roku.http.response.time", deltaMs, {"domain": attr["domain"]})
end if

'Calculate counts for metrics
Expand Down Expand Up @@ -731,6 +733,7 @@ function nrAddCommonHTTPAttr(info as Object) as Object
"httpCode": info["HttpCode"],
"method": info["Method"],
"origUrl": info["OrigUrl"],
"domain": nrExtractDomainFromUrl(info["OrigUrl"]),
"status": info["Status"],
"targetIp": info["TargetIp"],
"url": info["Url"]
Expand Down Expand Up @@ -800,12 +803,12 @@ function nrSendHTTPComplete(info as Object) as Void

if m.http_events_enabled then nrSendCustomEvent("RokuSystem", "HTTP_COMPLETE", attr)

host = nrExtractHostFromUrl(attr["origUrl"])
nrSendMetric("roku.http.complete.connectTime", attr["connectTime"], {"host": host})
nrSendMetric("roku.http.complete.downSpeed", attr["downloadSpeed"], {"host": host})
nrSendMetric("roku.http.complete.upSpeed", attr["uploadSpeed"], {"host": host})
nrSendMetric("roku.http.complete.firstByteTime", attr["transferTime"], {"host": host})
nrSendMetric("roku.http.complete.dnsTime", attr["dnsLookupTime"], {"host": host})
domain = nrExtractDomainFromUrl(attr["origUrl"])
nrSendMetric("roku.http.complete.connectTime", attr["connectTime"], {"domain": domain})
nrSendMetric("roku.http.complete.downSpeed", attr["downloadSpeed"], {"domain": domain})
nrSendMetric("roku.http.complete.upSpeed", attr["uploadSpeed"], {"domain": domain})
nrSendMetric("roku.http.complete.firstByteTime", attr["transferTime"], {"domain": domain})
nrSendMetric("roku.http.complete.dnsTime", attr["dnsLookupTime"], {"domain": domain})
end function

function nrSendBandwidth(info as Object) as Void
Expand Down Expand Up @@ -1148,7 +1151,7 @@ function isAction(name as String, action as String) as Boolean
return r.isMatch(action)
end function

function nrExtractHostFromUrl(url as String) as String
function nrExtractDomainFromUrl(url as String) as String
r = CreateObject("roRegex", "\/\/|\/", "")
arr = r.Split(url)

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.0.2"/>
<field id="version" type="string" value="3.1.0"/>
<field id="patternGen" type="node"/>
<!-- Public Methods (wrapped) -->
<function name="NewRelicInit"/>
Expand Down
2 changes: 0 additions & 2 deletions components/SearchTask.brs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ function searchTaskMain()
'Send HTTP_RESPONSE action
nrSendHttpResponse(m.nr, _url, msg)
nrSendLog(m.nr, "Google Search", "URL Request", { "url": _url, "counter": counter, "bodysize": Len(msg) })
nrSendMetric(m.nr, "roku.http.response", requestTimer.TotalMilliseconds())

' Update max, min and sum
if requestTimer.TotalMilliseconds() > m_max then m_max = requestTimer.TotalMilliseconds()
Expand All @@ -56,7 +55,6 @@ function searchTaskMain()
counter = counter + 1

if countTimer.TotalMilliseconds() > 7500
nrSendCountMetric(m.nr, "roku.http.request.count", counter, countTimer.TotalMilliseconds())
nrSendSummaryMetric(m.nr, "roku.http.response.summary", countTimer.TotalMilliseconds(), counter, m_sum, m_min, m_max)
m_min = 999999
m_max = 0
Expand Down
7 changes: 4 additions & 3 deletions components/VideoScene.brs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function nrRefUpdated()
'setupSingleVideo()

'Setup the video player with a playlist
setupVideoPlaylist()
setupVideoPlaylist(true)

'Setup the video player with a single video and ads
'setupVideoWithAds()
Expand Down Expand Up @@ -61,10 +61,10 @@ function setupSingleVideo() as void
m.video.control = "play"
end function

function setupVideoPlaylist() as void
function setupVideoPlaylist(loop as boolean) as void
print "Prepare video player with Playlist"

httprange = "http://mirrors.standaloneinstaller.com/video-sample/jellyfish-25-mbps-hd-hevc.m4v"
'httprange = "http://mirrors.standaloneinstaller.com/video-sample/jellyfish-25-mbps-hd-hevc.m4v"
hls = "https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8"
dash = "http://yt-dash-mse-test.commondatastorage.googleapis.com/media/car-20120827-manifest.mpd"

Expand All @@ -84,6 +84,7 @@ function setupVideoPlaylist() as void
m.video.content = playlistContent
m.video.contentIsPlaylist = True
m.video.control = "play"
m.video.loop = loop
end function

function setupVideoWithAds() as void
Expand Down

0 comments on commit 8ea81f6

Please sign in to comment.