From c573adac511377e6e823603cbcb3a325b37ea844 Mon Sep 17 00:00:00 2001 From: duncanpo Date: Thu, 14 Sep 2023 14:47:12 -0400 Subject: [PATCH 1/3] download collector automatically for tests --- test/commonSetupOnce.m | 38 +++++++++++++++++++++++++++++++----- test/performance/traceTest.m | 3 +-- test/tbaggage.m | 7 ++++--- test/tcontextPropagation.m | 3 +-- test/ttrace.m | 3 +-- 5 files changed, 40 insertions(+), 14 deletions(-) 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 From 27953ad51d0ee81bb4b550d487ecb76e3982f21f Mon Sep 17 00:00:00 2001 From: duncanpo Date: Fri, 15 Sep 2023 09:41:35 -0400 Subject: [PATCH 2/3] Change tests to automatically download collector if not installed --- test/commonSetupOnce.m | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/test/commonSetupOnce.m b/test/commonSetupOnce.m index db37c1d..06aed5f 100644 --- a/test/commonSetupOnce.m +++ b/test/commonSetupOnce.m @@ -12,7 +12,6 @@ function commonSetupOnce(testCase) 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", " "); @@ -55,13 +54,16 @@ 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"; @@ -71,13 +73,21 @@ function commonSetupOnce(testCase) 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") + 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); From 15cfc4c7ebbf0bd9715fc70e40cfad15e27011dd Mon Sep 17 00:00:00 2001 From: duncanpo Date: Fri, 15 Sep 2023 10:09:48 -0400 Subject: [PATCH 3/3] update GitHub workflow --- .github/workflows/build.yml | 7 ------- 1 file changed, 7 deletions(-) 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