Last active
November 26, 2019 13:14
Tracking Feature Flags In New Relic And NRQL Using The Java Agent In Lucee CFML 5.3.3.62
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
average( duration ) | |
FROM | |
Transaction | |
WHERE | |
appName = 'local-cfprojects-bennadel' | |
AND | |
resourceUri = '/d/ben/default' | |
SINCE | |
10 minutes ago | |
FACET | |
features.DemoOptimization | |
TIMESERIES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
average( duration ) | |
FROM | |
Transaction | |
WHERE | |
appName = 'local-cfprojects-bennadel' | |
AND | |
resourceUri = '/d/ben/default' | |
AND | |
features.DemoOptimization = 'false' | |
SINCE | |
10 minutes ago | |
TIMESERIES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
average( duration ) | |
FROM | |
Transaction | |
WHERE | |
appName = 'local-cfprojects-bennadel' | |
AND | |
resourceUri = '/d/ben/default' | |
AND | |
features.DemoOptimization = 'true' | |
SINCE | |
10 minutes ago | |
TIMESERIES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component | |
output = false | |
accessors = true | |
{ | |
// Define properties for dependency-injection. | |
property javaAgentHelper; | |
// --- | |
// PUBLIC METHODS. | |
// --- | |
/** | |
* I render the demo for the New Relic feature-flag tracking. | |
* | |
* @rc I am the FW/1 request context. | |
*/ | |
public void function default( required struct rc ) { | |
var isFeatureEnabled = shouldUseFeature( userID = 1 ); | |
// Now that we know if the feature-flag is enabled, we're going to track the | |
// feature flag state as a TRANSACTION PARAMETER using the New Relic Java Agent. | |
// This way, we can differentiate requests by feature-flag in our Transaction | |
// traces and NRQL (New Relic Query Language) queries. | |
javaAgentHelper.addCustomParameter( | |
"features.DemoOptimization", | |
booleanFormat( isFeatureEnabled ) | |
); | |
// DEMO LOGIC: For the purposes of the demo, we're going to randomly assign | |
// better performance to the branch with the feature enabled. This way, we | |
// should be able to see a difference in New Relic's Insights dashboards. | |
if ( isFeatureEnabled ) { | |
sleep( randRange( 50, 150 ) ); | |
} else { | |
sleep( randRange( 100, 1000 ) ); | |
} | |
} | |
// --- | |
// PRIVATE METHODS. | |
// --- | |
/** | |
* I determine if the feature should be enabled for the given user. | |
* | |
* @userID I am the user being tested. | |
*/ | |
private boolean function shouldUseFeature( required numeric userID ) { | |
// FOR THE DEMO, we are going to randomly enable or disable the given feature. | |
// This way, we can see the difference in the New Relic transactions. | |
// -- | |
// NOTE: This is the logical equivalent of a 50% feature roll-out. | |
return( !! randRange( 0, 1 ) ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
count( * ) | |
FROM | |
Transaction | |
WHERE | |
appName = 'local-cfprojects-bennadel' | |
AND | |
resourceUri = '/d/ben/default' | |
SINCE | |
10 minutes ago | |
FACET | |
features.DemoOptimization | |
TIMESERIES |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment