Skip to content

Commit c573ada

Browse files
committed
download collector automatically for tests
1 parent e2525ed commit c573ada

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed

test/commonSetupOnce.m

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ function commonSetupOnce(testCase)
55

66
% file definitions
77
otelcolroot = getenv("OPENTELEMETRY_COLLECTOR_INSTALL");
8-
assert(~isempty(otelcolroot), "OPENTELEMETRY_COLLECTOR_INSTALL environment must be defined.")
98
testCase.OtelConfigFile = fullfile(fileparts(mfilename("fullpath")), ...
109
"otelcol_config.yml");
1110
otelroot = getenv("OPENTELEMETRY_MATLAB_INSTALL");
12-
assert(~isempty(otelroot), "OPENTELEMETRY_MATLAB_INSTALL environment must be defined.")
13-
testCase.OtelRoot = otelroot;
1411
testCase.JsonFile = "myoutput.json";
1512
testCase.PidFile = "testoutput.txt";
1613

@@ -19,7 +16,13 @@ function commonSetupOnce(testCase)
1916
if ispc
2017
testCase.ListPid = @(name)"tasklist /fi ""IMAGENAME eq " + name + ".exe""";
2118
testCase.ReadPidList = @(file)readtable(file, "VariableNamingRule", "preserve", "NumHeaderLines", 3, "MultipleDelimsAsOne", true, "Delimiter", " ");
22-
testCase.ExtractPid = @(table)table.Var2;
19+
testCase.ExtractPid = @(table)table.Var2;
20+
21+
% variables to support downloading OpenTelemetry Collector
22+
otelcol_arch_name = "windows_amd64";
23+
otelcol_exe_ext = ".exe";
24+
25+
% windows_kill
2326
windows_killroot = getenv("WINDOWS_KILL_INSTALL");
2427
windows_killname = "windows-kill";
2528
if isempty(windows_killroot)
@@ -41,6 +44,10 @@ function commonSetupOnce(testCase)
4144
testCase.ExtractPid = @(table)table.PID;
4245
testCase.Sigint = @(id)"kill " + id; % kill sends a SIGTERM instead of SIGINT but turns out this is sufficient to terminate OTEL collector on Linux
4346
testCase.Sigterm = @(id)"kill " + id;
47+
48+
% variables to support downloading OpenTelemetry Collector
49+
otelcol_arch_name = "linux_amd64";
50+
otelcol_exe_ext = "";
4451
elseif ismac
4552
testCase.ListPid = @(name)"pgrep -x " + name;
4653
testCase.ReadPidList = @readmatrix;
@@ -53,10 +60,31 @@ function commonSetupOnce(testCase)
5360
end
5461

5562
end
63+
64+
% OpenTelemetry Collector
65+
if isempty(otelcolroot)
66+
% collector not pre-installed
67+
otelcol_version = "0.85.0";
68+
otelcol_url = "https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v" ...
69+
+ otelcol_version;
70+
otelcol_zipfilename = "otelcol_" + otelcol_version + "_" + otelcol_arch_name;
71+
otelcolroot = fullfile(tempdir, otelcol_zipfilename);
72+
73+
% look for it in tempdir, download and install if it doesn't exist
74+
if ~exist(fullfile(otelcolroot, testCase.OtelcolName + otelcol_exe_ext),"file")
75+
otelcol_tar = gunzip(fullfile(otelcol_url, otelcol_zipfilename + ".tar.gz"), otelcolroot);
76+
otelcol_tar = otelcol_tar{1}; % should have only extracted 1 tar file
77+
untar(otelcol_tar, otelcolroot);
78+
delete(otelcol_tar);
79+
end
80+
end
81+
5682
testCase.Otelcol = fullfile(otelcolroot, testCase.OtelcolName);
5783

5884
% set up path
59-
testCase.applyFixture(matlab.unittest.fixtures.PathFixture(testCase.OtelRoot));
85+
if ~isempty(otelroot)
86+
testCase.applyFixture(matlab.unittest.fixtures.PathFixture(otelroot));
87+
end
6088

6189
% remove temporary files if present
6290
if exist(testCase.JsonFile, "file")

test/performance/traceTest.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33

44
properties
55
OtelConfigFile
6-
OtelRoot
76
JsonFile
87
PidFile
9-
OtelcolName
8+
OtelcolName
109
Otelcol
1110
ListPid
1211
ReadPidList

test/tbaggage.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44
% Copyright 2023 The MathWorks, Inc.
55

66
properties
7-
OtelRoot
87
BaggageKeys
98
BaggageValues
109
BaggageHeaders
1110
end
1211

1312
methods (TestClassSetup)
1413
function setupOnce(testCase)
15-
testCase.OtelRoot = getenv("OPENTELEMETRY_MATLAB_INSTALL");
14+
otelroot = getenv("OPENTELEMETRY_MATLAB_INSTALL");
1615

1716
% set up path
18-
addpath(testCase.OtelRoot);
17+
if ~isempty(otelroot)
18+
addpath(otelroot);
19+
end
1920

2021
testCase.BaggageKeys = ["userId", "serverNode", "isProduction"];
2122
testCase.BaggageValues = ["alice", "DF28", "false"];

test/tcontextPropagation.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
properties
77
OtelConfigFile
8-
OtelRoot
98
JsonFile
109
PidFile
11-
OtelcolName
10+
OtelcolName
1211
Otelcol
1312
ListPid
1413
ReadPidList

test/ttrace.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
properties
77
OtelConfigFile
8-
OtelRoot
98
JsonFile
109
PidFile
11-
OtelcolName
10+
OtelcolName
1211
Otelcol
1312
ListPid
1413
ReadPidList

0 commit comments

Comments
 (0)