@@ -5,21 +5,23 @@ function commonSetupOnce(testCase)
55
66% file definitions
77otelcolroot = getenv(" OPENTELEMETRY_COLLECTOR_INSTALL" );
8- assert(~isempty(otelcolroot ), " OPENTELEMETRY_COLLECTOR_INSTALL environment must be defined." )
98testCase.OtelConfigFile = fullfile(fileparts(mfilename(" fullpath" )), ...
109 " otelcol_config.yml" );
1110otelroot = getenv(" OPENTELEMETRY_MATLAB_INSTALL" );
12- assert(~isempty(otelroot ), " OPENTELEMETRY_MATLAB_INSTALL environment must be defined." )
13- testCase.OtelRoot = otelroot ;
1411testCase.JsonFile = " myoutput.json" ;
1512testCase.PidFile = " testoutput.txt" ;
1613
1714% process definitions
18- testCase.OtelcolName = " otelcol" ;
1915if ispc
2016 testCase.ListPid = @(name )"tasklist / fi " " IMAGENAME eq " + name + " .exe"" " ;
2117 testCase.ReadPidList = @(file )readtable(file , " VariableNamingRule" , " preserve" , " NumHeaderLines" , 3 , " MultipleDelimsAsOne" , true , " Delimiter" , " " );
22- testCase.ExtractPid = @(table )table .Var2 ;
18+ testCase.ExtractPid = @(table )table .Var2 ;
19+
20+ % variables to support downloading OpenTelemetry Collector
21+ otelcol_arch_name = " windows_amd64" ;
22+ otelcol_exe_ext = " .exe" ;
23+
24+ % windows_kill
2325 windows_killroot = getenv(" WINDOWS_KILL_INSTALL" );
2426 windows_killname = " windows-kill" ;
2527 if isempty(windows_killroot )
@@ -41,22 +43,58 @@ function commonSetupOnce(testCase)
4143 testCase.ExtractPid = @(table )table .PID ;
4244 testCase.Sigint = @(id )"kill " + id; % kill sends a SIGTERM instead of SIGINT but turns out this is sufficient to terminate OTEL collector on Linux
4345 testCase.Sigterm = @(id)" kill " + id ;
46+
47+ % variables to support downloading OpenTelemetry Collector
48+ otelcol_arch_name = " linux_amd64" ;
49+ otelcol_exe_ext = " " ;
4450elseif ismac
4551 testCase.ListPid = @(name )"pgrep - x " + name;
4652 testCase.ReadPidList = @readmatrix;
4753 testCase.ExtractPid = @(x)x; % no-op that returns itself
4854 testCase.Sigint = @(id)" kill -s INT " + id ;
4955 testCase.Sigterm = @(id )"kill - s TERM " + id;
5056 if computer == " MACA64"
51- % only the contrib version of OpenTelemetry Collector is available on Apple silicon
52- testCase.OtelcolName = " otelcol-contrib" ;
57+ otelcol_arch_name = " darwin_arm64" ;
58+ else
59+ otelcol_arch_name = " darwin_amd64" ;
5360 end
61+ otelcol_exe_ext = " " ;
62+
63+ end
5464
65+ % OpenTelemetry Collector
66+ otelcolname = " otelcol" ;
67+ if isempty(otelcolroot )
68+ % collector not pre-installed
69+ otelcol_version = " 0.85.0" ;
70+ otelcol_url = " https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v" ...
71+ + otelcol_version ;
72+ otelcol_zipfilename = " otelcol_" + otelcol_version + " _" + otelcol_arch_name ;
73+ otelcolroot = fullfile(tempdir , otelcol_zipfilename );
74+
75+ % look for it in tempdir, download and install if it doesn't exist
76+ if ~(exist(fullfile(otelcolroot , otelcolname + otelcol_exe_ext )," file" ) || ...
77+ exist(fullfile(otelcolroot ,otelcolname + " -contrib" + otelcol_exe_ext )," file" ))
78+ % download and install
79+ otelcol_tar = gunzip(fullfile(otelcol_url , otelcol_zipfilename + " .tar.gz" ), otelcolroot );
80+ otelcol_tar = otelcol_tar{1 }; % should have only extracted 1 tar file
81+ untar(otelcol_tar , otelcolroot );
82+ delete(otelcol_tar );
83+ end
84+ end
85+ % check for contrib version
86+ if exist(fullfile(otelcolroot ,otelcolname + " -contrib" + otelcol_exe_ext )," file" )
87+ testCase.OtelcolName = otelcolname + " -contrib" ;
88+ else
89+ testCase.OtelcolName = otelcolname ;
5590end
91+
5692testCase.Otelcol = fullfile(otelcolroot , testCase .OtelcolName );
5793
5894% set up path
59- testCase .applyFixture(matlab .unittest .fixtures .PathFixture(testCase .OtelRoot ));
95+ if ~isempty(otelroot )
96+ testCase .applyFixture(matlab .unittest .fixtures .PathFixture(otelroot ));
97+ end
6098
6199% remove temporary files if present
62100if exist(testCase .JsonFile , " file" )
0 commit comments