diff --git a/test/commonSetupOnce.m b/test/commonSetupOnce.m index f70a2a5..db37c1d 100644 --- a/test/commonSetupOnce.m +++ b/test/commonSetupOnce.m @@ -5,12 +5,9 @@ function commonSetupOnce(testCase) % file definitions otelcolroot = getenv("OPENTELEMETRY_COLLECTOR_INSTALL"); -assert(~isempty(otelcolroot), "OPENTELEMETRY_COLLECTOR_INSTALL environment must be defined.") testCase.OtelConfigFile = fullfile(fileparts(mfilename("fullpath")), ... "otelcol_config.yml"); otelroot = getenv("OPENTELEMETRY_MATLAB_INSTALL"); -assert(~isempty(otelroot), "OPENTELEMETRY_MATLAB_INSTALL environment must be defined.") -testCase.OtelRoot = otelroot; testCase.JsonFile = "myoutput.json"; testCase.PidFile = "testoutput.txt"; @@ -19,7 +16,13 @@ function commonSetupOnce(testCase) if ispc testCase.ListPid = @(name)"tasklist /fi ""IMAGENAME eq " + name + ".exe"""; testCase.ReadPidList = @(file)readtable(file, "VariableNamingRule", "preserve", "NumHeaderLines", 3, "MultipleDelimsAsOne", true, "Delimiter", " "); - testCase.ExtractPid = @(table)table.Var2; + testCase.ExtractPid = @(table)table.Var2; + + % variables to support downloading OpenTelemetry Collector + otelcol_arch_name = "windows_amd64"; + otelcol_exe_ext = ".exe"; + + % windows_kill windows_killroot = getenv("WINDOWS_KILL_INSTALL"); windows_killname = "windows-kill"; if isempty(windows_killroot) @@ -41,6 +44,10 @@ function commonSetupOnce(testCase) testCase.ExtractPid = @(table)table.PID; testCase.Sigint = @(id)"kill " + id; % kill sends a SIGTERM instead of SIGINT but turns out this is sufficient to terminate OTEL collector on Linux testCase.Sigterm = @(id)"kill " + id; + + % variables to support downloading OpenTelemetry Collector + otelcol_arch_name = "linux_amd64"; + otelcol_exe_ext = ""; elseif ismac testCase.ListPid = @(name)"pgrep -x " + name; testCase.ReadPidList = @readmatrix; @@ -53,10 +60,31 @@ function commonSetupOnce(testCase) end end + +% OpenTelemetry Collector +if isempty(otelcolroot) + % collector not pre-installed + otelcol_version = "0.85.0"; + otelcol_url = "https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v" ... + + otelcol_version; + otelcol_zipfilename = "otelcol_" + otelcol_version + "_" + otelcol_arch_name; + otelcolroot = fullfile(tempdir, otelcol_zipfilename); + + % look for it in tempdir, download and install if it doesn't exist + if ~exist(fullfile(otelcolroot, testCase.OtelcolName + otelcol_exe_ext),"file") + otelcol_tar = gunzip(fullfile(otelcol_url, otelcol_zipfilename + ".tar.gz"), otelcolroot); + otelcol_tar = otelcol_tar{1}; % should have only extracted 1 tar file + untar(otelcol_tar, otelcolroot); + delete(otelcol_tar); + end +end + testCase.Otelcol = fullfile(otelcolroot, testCase.OtelcolName); % set up path -testCase.applyFixture(matlab.unittest.fixtures.PathFixture(testCase.OtelRoot)); +if ~isempty(otelroot) + testCase.applyFixture(matlab.unittest.fixtures.PathFixture(otelroot)); +end % remove temporary files if present if exist(testCase.JsonFile, "file") diff --git a/test/performance/traceTest.m b/test/performance/traceTest.m index c9700eb..91ed707 100644 --- a/test/performance/traceTest.m +++ b/test/performance/traceTest.m @@ -3,10 +3,9 @@ properties OtelConfigFile - OtelRoot JsonFile PidFile - OtelcolName + OtelcolName Otelcol ListPid ReadPidList diff --git a/test/tbaggage.m b/test/tbaggage.m index 91c2592..8a99609 100644 --- a/test/tbaggage.m +++ b/test/tbaggage.m @@ -4,7 +4,6 @@ % Copyright 2023 The MathWorks, Inc. properties - OtelRoot BaggageKeys BaggageValues BaggageHeaders @@ -12,10 +11,12 @@ methods (TestClassSetup) function setupOnce(testCase) - testCase.OtelRoot = getenv("OPENTELEMETRY_MATLAB_INSTALL"); + otelroot = getenv("OPENTELEMETRY_MATLAB_INSTALL"); % set up path - addpath(testCase.OtelRoot); + if ~isempty(otelroot) + addpath(otelroot); + end testCase.BaggageKeys = ["userId", "serverNode", "isProduction"]; testCase.BaggageValues = ["alice", "DF28", "false"]; diff --git a/test/tcontextPropagation.m b/test/tcontextPropagation.m index bcf9dc3..8b8ec71 100644 --- a/test/tcontextPropagation.m +++ b/test/tcontextPropagation.m @@ -5,10 +5,9 @@ properties OtelConfigFile - OtelRoot JsonFile PidFile - OtelcolName + OtelcolName Otelcol ListPid ReadPidList diff --git a/test/ttrace.m b/test/ttrace.m index 115fe3d..8b01773 100644 --- a/test/ttrace.m +++ b/test/ttrace.m @@ -5,10 +5,9 @@ properties OtelConfigFile - OtelRoot JsonFile PidFile - OtelcolName + OtelcolName Otelcol ListPid ReadPidList