Skip to content

Commit

Permalink
Merge branch 'main' into chore/#2266_CleanupPackages
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz authored Feb 2, 2024
2 parents 647af11 + 0c9b449 commit b61d45c
Show file tree
Hide file tree
Showing 27 changed files with 133 additions and 118 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-windows-iis-reporter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
- uses: elastic/apm-pipeline-library/.github/actions/test-report@current
with:
artifact: test-results-iis # artifact name
name: IIS Tests Summary # Name of the check run which will be created
path: "junit-*.xml" # Path to test results (inside artifact .zip)
name: IIS Tests Summary # Name of the check run which will be created
path: "junit-*.xml" # Path to test results (inside artifact .zip)
reporter: java-junit # Format of test results
list-suites: 'failed'
list-tests: 'failed'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-windows-reporter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
- uses: elastic/apm-pipeline-library/.github/actions/test-report@current
with:
artifact: test-results-windows # artifact name
name: Windows Tests Summary # Name of the check run which will be created
path: "junit-*.xml" # Path to test results (inside artifact .zip)
name: Windows Tests Summary # Name of the check run which will be created
path: "junit-*.xml" # Path to test results (inside artifact .zip)
reporter: java-junit # Format of test results
list-suites: 'failed'
list-tests: 'failed'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
run: dotnet build -c Release --verbosity minimal

- name: Setup Testcontainers Cloud Client
if: github.event_name != 'pull_request' || github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false
uses: atomicjar/testcontainers-cloud-setup-action@v1
with:
token: ${{ secrets.TC_CLOUD_TOKEN }}
Expand Down Expand Up @@ -84,6 +85,7 @@ jobs:
run: ./build.bat profiler-zip

- name: Setup Testcontainers Cloud Client
if: github.event_name != 'pull_request' || github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false
uses: atomicjar/testcontainers-cloud-setup-action@v1
with:
token: ${{ secrets.TC_CLOUD_TOKEN }}
Expand Down
30 changes: 30 additions & 0 deletions src/Elastic.Apm/Api/ProcessInformation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to Elasticsearch B.V under
// one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.Diagnostics;
using Elastic.Apm.Api.Constraints;
using Elastic.Apm.Helpers;

namespace Elastic.Apm.Api;

internal class ProcessInformation
{
public int Pid { get; set; }

[MaxLength]
public string Title { get; set; }

public static ProcessInformation Create()
{
var p = Process.GetCurrentProcess();
return new ProcessInformation { Pid = p.Id, Title = p.ProcessName };
}

public override string ToString() => new ToStringBuilder(nameof(Service))
{
{ nameof(Pid), Pid },
{ nameof(Title), Title }
}.ToString();
}
2 changes: 2 additions & 0 deletions src/Elastic.Apm/Model/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ internal class Metadata
// ReSharper disable once UnusedAutoPropertyAccessor.Global - used by Json.Net
public Service Service { get; set; }

public ProcessInformation Process { get; set; }

// ReSharper disable once UnusedAutoPropertyAccessor.Global
public Api.System System { get; set; }

Expand Down
3 changes: 2 additions & 1 deletion src/Elastic.Apm/Report/PayloadSenderV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public PayloadSenderV2(
_cloudMetadataProviderCollection = new CloudMetadataProviderCollection(configuration.CloudProvider, _logger, environmentVariables);
_apmServerInfo = apmServerInfo ?? new ApmServerInfo();
_serverInfoCallback = serverInfoCallback;
_metadata = new Metadata { Service = service, System = System };
var process = ProcessInformation.Create();
_metadata = new Metadata { Service = service, System = System, Process = process };
foreach (var globalLabelKeyValue in configuration.GlobalLabels)
_metadata.Labels.Add(globalLabelKeyValue.Key, globalLabelKeyValue.Value);
_cachedActivationMethod = _metadata.Service?.Agent.ActivationMethod;
Expand Down
3 changes: 3 additions & 0 deletions test/Elastic.Apm.Tests.MockApmServer/MetadataDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Elastic.Apm.Api;
using Elastic.Apm.Config;
using Elastic.Apm.Helpers;
using Elastic.Apm.Model;

// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
Expand All @@ -17,6 +18,7 @@ namespace Elastic.Apm.Tests.MockApmServer
internal class MetadataDto : IDto
{
public Service Service { get; set; }
public ProcessInformation Process { get; set; }
public Api.System System { get; set; }
public Api.Cloud Cloud { get; set; }
public Dictionary<string, string> Labels { get; set; }
Expand All @@ -25,6 +27,7 @@ public override string ToString() =>
new ToStringBuilder(nameof(MetadataDto))
{
{ nameof(Service), Service },
{ nameof(Process), Process },
{ nameof(System), System },
{ nameof(Labels), AbstractConfigurationReader.ToLogString(Labels) },
{ nameof(Cloud), Cloud },
Expand Down
35 changes: 0 additions & 35 deletions test/Elastic.Apm.Tests.Utilities/Docker/DockerFactAttribute.cs

This file was deleted.

35 changes: 0 additions & 35 deletions test/Elastic.Apm.Tests.Utilities/Docker/DockerTheoryAttribute.cs

This file was deleted.

25 changes: 0 additions & 25 deletions test/Elastic.Apm.Tests.Utilities/Docker/DockerUtils.cs

This file was deleted.

4 changes: 1 addition & 3 deletions test/Elastic.Apm.Tests.Utilities/TestEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public static class TestEnvironment

static TestEnvironment()
{
// TODO this IsCi check is no longer valid, once we are green on Github Action
// we should be able to remove all special handling related to this
IsCi = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("BUILD_ID"));
IsCi = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CI"));
IsGitHubActions = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GITHUB_ACTION"));
IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
IsLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using Elastic.Apm.Tests.Utilities.Docker;
using Xunit;

namespace Elastic.Apm.Tests.Utilities.XUnit;
Expand Down
79 changes: 79 additions & 0 deletions test/Elastic.Apm.Tests.Utilities/XUnit/DockerAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Licensed to Elasticsearch B.V under
// one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System;
using System.IO;
using ProcNet;
using Xunit;

namespace Elastic.Apm.Tests.Utilities.XUnit;


/// <inheritdoc cref="DockerTheory"/>
public sealed class DockerFact : FactAttribute
{
public DockerFact() => Skip = DockerTheory.ShouldSkip();
}

/// <summary>
/// <para>Locally we always run TestContainers through docker.</para>
/// <para>On Github Actions windows hosts we use TC cloud to launch linux docker containers</para>
/// <para>
/// When forks run the tests on pull request TestContainers Cloud won't be configured and available.
/// So we opt to skip instead.
/// </para>
/// </summary>
public sealed class DockerTheory : TheoryAttribute
{
public DockerTheory() => Skip = ShouldSkip();

public static string ShouldSkip()
{
var tcCloudConfigured = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TC_CLOUD_TOKEN"));
if (TestEnvironment.IsGitHubActions
&& TestEnvironment.IsWindows
&& !tcCloudConfigured)
return "Running on Github Action Windows host with no active TC_CLOUD_TOKEN configuration, skipping.";
// if running locally skip the test because it needs docker installed.
else if (!DockerUtils.HasDockerInstalled)
return "This test requires docker to be installed";

return null;
}
}

/// <summary>
/// Marks a test that has to be running inside of a docker container
/// </summary>
public class RunningInDockerFactAttribute : FactAttribute
{
public RunningInDockerFactAttribute()
{
if (!DockerUtils.IsRunningInDocker())
Skip = "Not running in a docker container";
}
}

internal static class DockerUtils
{
public static bool IsRunningInDocker() =>
File.Exists("/proc/1/cgroup") && File.ReadAllText("/proc/1/cgroup").Contains("docker");

public static bool HasDockerInstalled { get; }

static DockerUtils()
{
try
{
var result = Proc.Start(new StartArguments("docker", "--version"));
HasDockerInstalled = result.ExitCode == 0;
}
catch (Exception)
{
HasDockerInstalled = false;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See the LICENSE file in the project root for more information

using Elastic.Apm.Report;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;

namespace Elastic.Apm.Docker.Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Elastic.Apm.Api;
using Elastic.Apm.DiagnosticSource;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using Elasticsearch.Net;
using FluentAssertions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Elastic.Apm.Api;
using Elastic.Apm.MongoDb.Tests.Fixture;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using MongoDB.Bson;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Elastic.Apm.EntityFrameworkCore;
using Elastic.Apm.Instrumentations.SqlClient;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Elastic.Apm.Api;
using Elastic.Apm.Instrumentations.SqlClient;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using Xunit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Threading.Tasks;
using Elastic.Apm.Api;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using StackExchange.Redis;
using Testcontainers.Redis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Elastic.Apm.DiagnosticSource;
using Elastic.Apm.Elasticsearch;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Threading.Tasks;
using Elastic.Apm.Tests.MockApmServer;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Threading.Tasks;
using Elastic.Apm.Tests.MockApmServer;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Threading.Tasks;
using Elastic.Apm.Tests.MockApmServer;
using Elastic.Apm.Tests.Utilities;
using Elastic.Apm.Tests.Utilities.Docker;
using Elastic.Apm.Tests.Utilities.XUnit;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;
Expand Down
Loading

0 comments on commit b61d45c

Please sign in to comment.