diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f7e5ee2..2dcee3a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,9 +6,7 @@ jobs: build-and-run-tests: runs-on: ubuntu-latest env: - OPENTELEMETRY_CPP_INSTALL: "${{ github.workspace }}/otel_cpp_install" OPENTELEMETRY_MATLAB_INSTALL: "${{ github.workspace }}/otel_matlab_install" - OPENTELEMETRY_COLLECTOR_INSTALL: "${{ github.workspace }}/otelcol" SYSTEM_LIBSTDCPP_PATH: "/usr/lib/x86_64-linux-gnu/libstdc++.so.6" steps: - name: Download OpenTelemetry-Matlab source @@ -17,11 +15,6 @@ jobs: path: opentelemetry-matlab - name: Install MATLAB uses: matlab-actions/setup-matlab@v1 - - name: Download OpenTelemetry Collector binary - run: | - mkdir otelcol && cd otelcol - wget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.75.0/otelcol_0.75.0_linux_amd64.tar.gz - tar -xzf otelcol_0.75.0_linux_amd64.tar.gz - name: Build OpenTelemetry-Matlab run: | cd opentelemetry-matlab diff --git a/test/commonSetupOnce.m b/test/commonSetupOnce.m index f70a2a5..06aed5f 100644 --- a/test/commonSetupOnce.m +++ b/test/commonSetupOnce.m @@ -5,21 +5,23 @@ 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"; % process definitions -testCase.OtelcolName = "otelcol"; 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 +43,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; @@ -48,15 +54,47 @@ function commonSetupOnce(testCase) testCase.Sigint = @(id)"kill -s INT " + id; testCase.Sigterm = @(id)"kill -s TERM " + id; if computer == "MACA64" - % only the contrib version of OpenTelemetry Collector is available on Apple silicon - testCase.OtelcolName = "otelcol-contrib"; + otelcol_arch_name = "darwin_arm64"; + else + otelcol_arch_name = "darwin_amd64"; end + otelcol_exe_ext = ""; + +end +% OpenTelemetry Collector +otelcolname = "otelcol"; +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, otelcolname + otelcol_exe_ext),"file") || ... + exist(fullfile(otelcolroot,otelcolname + "-contrib" + otelcol_exe_ext),"file")) + % download and install + 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 +% check for contrib version +if exist(fullfile(otelcolroot,otelcolname + "-contrib" + otelcol_exe_ext),"file") + testCase.OtelcolName = otelcolname + "-contrib"; +else + testCase.OtelcolName = otelcolname; 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