Skip to content

Commit

Permalink
[repo] Add geneva integration test leg to CI (#2219)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBlanch authored Oct 21, 2024
1 parent 177748e commit 52099ac
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 14 deletions.
30 changes: 27 additions & 3 deletions .github/workflows/Component.BuildTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ on:
default: '[ "net462", "net8.0" ]'
required: false
type: string
test-case-filter:
required: false
type: string
test-require-elevated:
default: false
required: false
type: boolean
pack:
default: true
required: false
type: boolean

jobs:
build-test:
Expand Down Expand Up @@ -88,10 +99,22 @@ jobs:

- name: dotnet test ${{ steps.resolve-project.outputs.title }}
if: ${{ inputs.run-tests }}
run: dotnet test ${{ steps.resolve-project.outputs.project }} --collect:"Code Coverage" --results-directory:TestResults --framework ${{ matrix.version }} --configuration Release --no-restore --no-build --logger:"console;verbosity=detailed" -- RunConfiguration.DisableAppDomain=true
run: >
${{ inputs.test-require-elevated && matrix.os != 'windows-latest' && 'sudo -E' || '' }}
dotnet test ${{ steps.resolve-project.outputs.project }}
--collect:"Code Coverage"
--results-directory:TestResults
--framework ${{ matrix.version }}
--configuration Release
--no-restore
--no-build
--logger:"console;verbosity=detailed"
--filter "${{ inputs.test-case-filter }}"
-- RunConfiguration.DisableAppDomain=true
${{ inputs.test-require-elevated && matrix.os != 'windows-latest' && '&& sudo chmod a+rw ./TestResults' || '' }}
- name: dotnet pack ${{ steps.resolve-project.outputs.title }}
if: ${{ matrix.os == 'windows-latest' }}
if: ${{ matrix.os == 'windows-latest' && inputs.pack }}
run: dotnet pack ${{ steps.resolve-project.outputs.project }} --configuration Release --no-restore --no-build -p:EnablePackageValidation=true

- name: Install coverage tool
Expand All @@ -109,10 +132,11 @@ jobs:
env:
OS: ${{ matrix.os }}
TFM: ${{ matrix.version }}
FILTER: ${{ inputs.test-case-filter }}
token: ${{ secrets.CODECOV_TOKEN }}
with:
file: TestResults/Cobertura.xml
env_vars: OS,TFM
env_vars: OS,TFM,FILTER
flags: ${{ inputs.code-cov-prefix }}-${{ inputs.code-cov-name }}
name: Code Coverage for ${{ inputs.code-cov-prefix }}-${{ inputs.code-cov-name }} on [${{ matrix.os }}.${{ matrix.version }}]
codecov_yml_path: .github/codecov.yml
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ jobs:
project-name: Component[OpenTelemetry.Exporter.Geneva]
code-cov-name: Exporter.Geneva

build-test-exporter-geneva-integration:
needs: detect-changes
if: |
contains(needs.detect-changes.outputs.changes, 'exporter-geneva')
|| contains(needs.detect-changes.outputs.changes, 'build')
|| contains(needs.detect-changes.outputs.changes, 'shared')
uses: ./.github/workflows/Component.BuildTest.yml
with:
project-name: Component[OpenTelemetry.Exporter.Geneva]
code-cov-name: Exporter.Geneva
os-list: '[ "ubuntu-24.04" ]' # Note: This may be switched to latest once ubuntu-latest has a kernel version >= 6.8.0-1014-azure
tfm-list: '[ "net8.0" ]' # Note: Should be able to remove this once the above is using ubuntu-latest
test-case-filter: CategoryName=Geneva:user_events:metrics
test-require-elevated: true
pack: false

build-test-exporter-influxdb:
needs: detect-changes
if: |
Expand Down Expand Up @@ -573,6 +589,7 @@ jobs:
lint-yml,
lint-dotnet-format,
build-test-exporter-geneva,
build-test-exporter-geneva-integration,
build-test-exporter-influxdb,
build-test-exporter-instana,
build-test-exporter-onecollector,
Expand Down
5 changes: 5 additions & 0 deletions build/Common.prod.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
<AssemblyVersion>$(MinVerMajor).$(MinVerMinor).$(MinVerPatch).$(RevisionNumber)</AssemblyVersion>
<Version>$(MinVerMajor).$(MinVerMinor).$(MinVerPatch).$(RevisionNumber)</Version>
<FileVersion>$(MinVerMajor).$(MinVerMinor).$(MinVerPatch).$(RevisionNumber)</FileVersion>

<!-- Note: If MinVerVersion is set to the default value we disable
PackageValidation because this most likely means we are running on a fork
without a valid tag to use for versioning and it will fail. -->
<EnablePackageValidation Condition="$(MinVerVersion.StartsWith('0.0.0-alpha.0'))">false</EnablePackageValidation>
</PropertyGroup>

<!-- Note: The '$(TargetFramework)' != '' check here is to reduce log spam
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public void UserEvents_Enabled_Succes_Linux()
MetricUnixUserEventsDataTransport.MetricsTracepointName,
MetricUnixUserEventsDataTransport.MetricsTracepointNameArgs);

if (listener.IsEnabled())
{
throw new NotSupportedException($"{MetricUnixUserEventsDataTransport.MetricsTracepointName} is already enabled");
}

try
{
listener.Enable();
Expand Down Expand Up @@ -120,6 +125,11 @@ public void UserEvents_Disabled_Succes_Linux()
MetricUnixUserEventsDataTransport.MetricsTracepointName,
MetricUnixUserEventsDataTransport.MetricsTracepointNameArgs);

if (listener.IsEnabled())
{
throw new NotSupportedException($"{MetricUnixUserEventsDataTransport.MetricsTracepointName} is already enabled");
}

try
{
MetricUnixUserEventsDataTransport.Instance.SendOtlpProtobufEvent(
Expand All @@ -138,8 +148,9 @@ public void UserEvents_Disabled_Succes_Linux()

private static void EnsureUserEventsEnabled()
{
using var userEventsEnableTest = ConsoleCommand.Run("cat", "/sys/kernel/tracing/user_events_status");
if (userEventsEnableTest.Errors.Any())
var errors = ConsoleCommand.Run("cat", "/sys/kernel/tracing/user_events_status");

if (errors.Any())
{
throw new NotSupportedException("Kernel does not support user_events. Verify your distribution/kernel supports user_events: https://docs.kernel.org/trace/user_events.html.");
}
Expand Down Expand Up @@ -205,7 +216,29 @@ private ConsoleCommand(

public IEnumerable<string> Errors => this.errors;

public static ConsoleCommand Run(
public static IEnumerable<string> Run(
string command,
string arguments)
{
Run(command, arguments, out _, out var errors);

return errors;
}

public static void Run(
string command,
string arguments,
out IEnumerable<string> output,
out IEnumerable<string> errors)
{
var consoleCommand = new ConsoleCommand(command, arguments, onOutputReceived: null, onErrorReceived: null);
consoleCommand.Dispose();

output = consoleCommand.Output;
errors = consoleCommand.Errors;
}

public static ConsoleCommand Start(
string command,
string arguments,
Action<string>? onOutputReceived = null,
Expand Down Expand Up @@ -250,7 +283,7 @@ public PerfTracepointListener(string name, string nameArgs)
throw new NotSupportedException($"Tracepoint could not be registered: '{this.tracepoint.RegisterResult}'");
}

this.catCommand = ConsoleCommand.Run("cat", "/sys/kernel/debug/tracing/trace_pipe", onOutputReceived: this.OnCatOutputReceived);
this.catCommand = ConsoleCommand.Start("cat", "/sys/kernel/debug/tracing/trace_pipe", onOutputReceived: this.OnCatOutputReceived);
if (this.catCommand.Errors.Any())
{
throw new InvalidOperationException($"Could not read '{name}' tracepoints");
Expand All @@ -261,26 +294,32 @@ public PerfTracepointListener(string name, string nameArgs)

public bool IsEnabled()
{
using var command = ConsoleCommand.Run("cat", $"/sys/kernel/tracing/events/user_events/{this.name}/enable");
ConsoleCommand.Run(
"cat",
$"/sys/kernel/tracing/events/user_events/{this.name}/enable",
out var output,
out var errors);

return command.Errors.Any() || command.Output.Count() != 1
return errors.Any() || output.Count() != 1
? throw new InvalidOperationException($"Could not determine if '{this.name}' tracepoint is enabled")
: command.Output.First() != "0";
: output.First() != "0";
}

public void Enable()
{
using var command = ConsoleCommand.Run("sh", @$"-c ""echo '1' > /sys/kernel/tracing/events/user_events/{this.name}/enable""");
if (command.Errors.Any())
var errors = ConsoleCommand.Run("sh", @$"-c ""echo '1' > /sys/kernel/tracing/events/user_events/{this.name}/enable""");

if (errors.Any())
{
throw new InvalidOperationException($"Could not enable '{this.name}' tracepoint");
}
}

public void Disable()
{
using var command = ConsoleCommand.Run("sh", @$"-c ""echo '0' > /sys/kernel/tracing/events/user_events/{this.name}/enable""");
if (command.Errors.Any())
var errors = ConsoleCommand.Run("sh", @$"-c ""echo '0' > /sys/kernel/tracing/events/user_events/{this.name}/enable""");

if (errors.Any())
{
throw new InvalidOperationException($"Could not disable '{this.name}' tracepoint");
}
Expand All @@ -292,6 +331,11 @@ public void Dispose()
{
if (this.catCommand != null)
{
if (this.catCommand.Errors.Any())
{
throw new InvalidOperationException($"Could not read '{this.name}' tracepoints");
}

this.catCommand.Kill();
this.catCommand.Dispose();
}
Expand Down

0 comments on commit 52099ac

Please sign in to comment.