Skip to content

Commit

Permalink
Add telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
machaval committed Mar 2, 2021
1 parent 6f6b76f commit 48bfaef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class DataWeaveCLIRunner {
val filesToWatch: ArrayBuffer[File] = ArrayBuffer()
var cleanCache = false
var remoteDebug = false
var telemetry = false

val inputs: mutable.Map[String, File] = mutable.Map()
val properties: mutable.Map[String, String] = mutable.Map()
Expand Down Expand Up @@ -240,6 +241,9 @@ class DataWeaveCLIRunner {
return Right("Missing <outputPath>")
}
}
case "--telemetry" => {
telemetry = true
}
case "-main" | "-m" => {
if (i + 1 < args.length) {
i = i + 1
Expand Down Expand Up @@ -294,7 +298,7 @@ class DataWeaveCLIRunner {
if (scriptToRun.isEmpty) {
Right(s"Missing <scriptContent> or -m <nameIdentifier> of -f <filePath> or --spell ")
} else {
Left(WeaveRunnerConfig(paths, profile, eval, cleanCache, scriptToRun.get, properties.toMap, inputs.toMap, output, filesToWatch, watch, remoteDebug))
Left(WeaveRunnerConfig(paths, profile, eval, cleanCache, scriptToRun.get, properties.toMap, inputs.toMap, output, filesToWatch, watch, remoteDebug, telemetry))
}
}

Expand Down Expand Up @@ -363,6 +367,7 @@ class DataWeaveCLIRunner {
| --version | The version of the CLI and Runtime
| --clean-cache | Cleans the cache where all artifacts are being downloaded this force to download all artifacts every time
| --remote-debug | Enables remote debugging
| --telemetry | Enables telemetry reporting
|
| Example:
|
Expand Down Expand Up @@ -450,7 +455,7 @@ class DataWeaveCLIRunner {
}
Signal.handle(new Signal("INT"), signalHandler)
Signal.handle(new Signal("TERM"), signalHandler)
val result: ExecuteResult = nativeRuntime.eval(module.content, scriptingBindings, module.nameIdentifier, config.profile, config.remoteDebug)
val result: ExecuteResult = nativeRuntime.eval(module.content, scriptingBindings, module.nameIdentifier, config.profile, config.remoteDebug, config.telemetry)
Runtime.getRuntime.addShutdownHook(new Thread() {
override def run(): Unit = {
Try(result.close())
Expand All @@ -474,7 +479,7 @@ class DataWeaveCLIRunner {
} else {
val out = if (config.outputPath.isDefined) new FileOutputStream(config.outputPath.get) else System.out
val defaultOutputType = Option(System.getenv(DW_DEFAULT_OUTPUT_MIMETYPE_VAR)).getOrElse("application/json")
val result: WeaveExecutionResult = nativeRuntime.run(module.content, module.nameIdentifier, scriptingBindings, out, defaultOutputType, config.profile, config.remoteDebug)
val result: WeaveExecutionResult = nativeRuntime.run(module.content, module.nameIdentifier, scriptingBindings, out, defaultOutputType, config.profile, config.remoteDebug, config.telemetry)
//load inputs from
if (result.success()) {
exitCode = 0
Expand Down Expand Up @@ -587,7 +592,8 @@ case class WeaveRunnerConfig(path: Array[String],
outputPath: Option[String],
filesToWatch: Seq[File],
watch: Boolean,
remoteDebug: Boolean
remoteDebug: Boolean,
telemetry: Boolean
)

case class WeaveModule(content: String, nameIdentifier: String)
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,16 @@ class NativeRuntime(resourcesCacheDir: File, libDir: File, path: Array[File], ex
}


def run(script: String, nameIdentifier: String, inputs: ScriptingBindings, out: OutputStream, defaultOutputMimeType: String = "application/json", profile: Boolean = false, debug: Boolean = false): WeaveExecutionResult = {
def run(script: String, nameIdentifier: String, inputs: ScriptingBindings, out: OutputStream, defaultOutputMimeType: String = "application/json", profile: Boolean = false, remoteDebug: Boolean = false, telemetry: Boolean = false): WeaveExecutionResult = {
try {
val dataWeaveScript: DataWeaveScript = compileScript(script, inputs, NameIdentifier(nameIdentifier), defaultOutputMimeType, profile)
if(debug) {
if(remoteDebug) {
dataWeaveScript.enableDebug()
}
if(telemetry){
dataWeaveScript.enableTelemetry()
dataWeaveScript.enableMemoryTelemetry()
}
val serviceManager: ServiceManager = createServiceManager()
val result: DataWeaveResult =
if (profile) {
Expand Down Expand Up @@ -169,12 +173,16 @@ class NativeRuntime(resourcesCacheDir: File, libDir: File, path: Array[File], ex
serviceManager
}

def eval(script: String, inputs: ScriptingBindings, nameIdentifier: String, profile: Boolean, debug: Boolean = false): ExecuteResult = {
def eval(script: String, inputs: ScriptingBindings, nameIdentifier: String, profile: Boolean, debug: Boolean = false, telemetry: Boolean = false): ExecuteResult = {
try {
val dataWeaveScript: DataWeaveScript = compileScript(script, inputs, NameIdentifier(nameIdentifier), "application/dw", profile)
if(debug) {
dataWeaveScript.enableDebug()
}
if(telemetry){
dataWeaveScript.enableTelemetry()
dataWeaveScript.enableMemoryTelemetry()
}
val serviceManager: ServiceManager = createServiceManager()
if (profile) {
time(() => dataWeaveScript.exec(inputs, serviceManager), "Execution")
Expand Down

0 comments on commit 48bfaef

Please sign in to comment.