Skip to content

Commit bd9eb21

Browse files
authored
Merge branch 'main' into feature/use-wildcard
2 parents 00c1ed4 + 0c9b449 commit bd9eb21

File tree

27 files changed

+133
-118
lines changed

27 files changed

+133
-118
lines changed

.github/workflows/test-windows-iis-reporter.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ jobs:
2121
- uses: elastic/apm-pipeline-library/.github/actions/test-report@current
2222
with:
2323
artifact: test-results-iis # artifact name
24-
name: IIS Tests Summary # Name of the check run which will be created
25-
path: "junit-*.xml" # Path to test results (inside artifact .zip)
24+
name: IIS Tests Summary # Name of the check run which will be created
25+
path: "junit-*.xml" # Path to test results (inside artifact .zip)
2626
reporter: java-junit # Format of test results
2727
list-suites: 'failed'
2828
list-tests: 'failed'

.github/workflows/test-windows-reporter.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ jobs:
1616
- uses: elastic/apm-pipeline-library/.github/actions/test-report@current
1717
with:
1818
artifact: test-results-windows # artifact name
19-
name: Windows Tests Summary # Name of the check run which will be created
20-
path: "junit-*.xml" # Path to test results (inside artifact .zip)
19+
name: Windows Tests Summary # Name of the check run which will be created
20+
path: "junit-*.xml" # Path to test results (inside artifact .zip)
2121
reporter: java-junit # Format of test results
2222
list-suites: 'failed'
2323
list-tests: 'failed'

.github/workflows/test-windows.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
run: dotnet build -c Release --verbosity minimal
4242

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

8687
- name: Setup Testcontainers Cloud Client
88+
if: github.event_name != 'pull_request' || github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false
8789
uses: atomicjar/testcontainers-cloud-setup-action@v1
8890
with:
8991
token: ${{ secrets.TC_CLOUD_TOKEN }}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Licensed to Elasticsearch B.V under
2+
// one or more agreements.
3+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
4+
// See the LICENSE file in the project root for more information
5+
6+
using System.Diagnostics;
7+
using Elastic.Apm.Api.Constraints;
8+
using Elastic.Apm.Helpers;
9+
10+
namespace Elastic.Apm.Api;
11+
12+
internal class ProcessInformation
13+
{
14+
public int Pid { get; set; }
15+
16+
[MaxLength]
17+
public string Title { get; set; }
18+
19+
public static ProcessInformation Create()
20+
{
21+
var p = Process.GetCurrentProcess();
22+
return new ProcessInformation { Pid = p.Id, Title = p.ProcessName };
23+
}
24+
25+
public override string ToString() => new ToStringBuilder(nameof(Service))
26+
{
27+
{ nameof(Pid), Pid },
28+
{ nameof(Title), Title }
29+
}.ToString();
30+
}

src/Elastic.Apm/Model/Metadata.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ internal class Metadata
1818
// ReSharper disable once UnusedAutoPropertyAccessor.Global - used by Json.Net
1919
public Service Service { get; set; }
2020

21+
public ProcessInformation Process { get; set; }
22+
2123
// ReSharper disable once UnusedAutoPropertyAccessor.Global
2224
public Api.System System { get; set; }
2325

src/Elastic.Apm/Report/PayloadSenderV2.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public PayloadSenderV2(
8888
_cloudMetadataProviderCollection = new CloudMetadataProviderCollection(configuration.CloudProvider, _logger, environmentVariables);
8989
_apmServerInfo = apmServerInfo ?? new ApmServerInfo();
9090
_serverInfoCallback = serverInfoCallback;
91-
_metadata = new Metadata { Service = service, System = System };
91+
var process = ProcessInformation.Create();
92+
_metadata = new Metadata { Service = service, System = System, Process = process };
9293
foreach (var globalLabelKeyValue in configuration.GlobalLabels)
9394
_metadata.Labels.Add(globalLabelKeyValue.Key, globalLabelKeyValue.Value);
9495
_cachedActivationMethod = _metadata.Service?.Agent.ActivationMethod;

test/Elastic.Apm.Tests.MockApmServer/MetadataDto.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Elastic.Apm.Api;
77
using Elastic.Apm.Config;
88
using Elastic.Apm.Helpers;
9+
using Elastic.Apm.Model;
910

1011
// ReSharper disable MemberCanBePrivate.Global
1112
// ReSharper disable UnusedAutoPropertyAccessor.Global
@@ -17,6 +18,7 @@ namespace Elastic.Apm.Tests.MockApmServer
1718
internal class MetadataDto : IDto
1819
{
1920
public Service Service { get; set; }
21+
public ProcessInformation Process { get; set; }
2022
public Api.System System { get; set; }
2123
public Api.Cloud Cloud { get; set; }
2224
public Dictionary<string, string> Labels { get; set; }
@@ -25,6 +27,7 @@ public override string ToString() =>
2527
new ToStringBuilder(nameof(MetadataDto))
2628
{
2729
{ nameof(Service), Service },
30+
{ nameof(Process), Process },
2831
{ nameof(System), System },
2932
{ nameof(Labels), AbstractConfigurationReader.ToLogString(Labels) },
3033
{ nameof(Cloud), Cloud },

test/Elastic.Apm.Tests.Utilities/Docker/DockerFactAttribute.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.

test/Elastic.Apm.Tests.Utilities/Docker/DockerTheoryAttribute.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.

test/Elastic.Apm.Tests.Utilities/Docker/DockerUtils.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

test/Elastic.Apm.Tests.Utilities/TestEnvironment.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ public static class TestEnvironment
3636

3737
static TestEnvironment()
3838
{
39-
// TODO this IsCi check is no longer valid, once we are green on Github Action
40-
// we should be able to remove all special handling related to this
41-
IsCi = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("BUILD_ID"));
39+
IsCi = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CI"));
4240
IsGitHubActions = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GITHUB_ACTION"));
4341
IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
4442
IsLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);

test/Elastic.Apm.Tests.Utilities/XUnit/DisabledOnWindowsFact.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
44
// See the LICENSE file in the project root for more information
55

6-
using Elastic.Apm.Tests.Utilities.Docker;
76
using Xunit;
87

98
namespace Elastic.Apm.Tests.Utilities.XUnit;
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Licensed to Elasticsearch B.V under
2+
// one or more agreements.
3+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
4+
// See the LICENSE file in the project root for more information
5+
6+
using System;
7+
using System.IO;
8+
using ProcNet;
9+
using Xunit;
10+
11+
namespace Elastic.Apm.Tests.Utilities.XUnit;
12+
13+
14+
/// <inheritdoc cref="DockerTheory"/>
15+
public sealed class DockerFact : FactAttribute
16+
{
17+
public DockerFact() => Skip = DockerTheory.ShouldSkip();
18+
}
19+
20+
/// <summary>
21+
/// <para>Locally we always run TestContainers through docker.</para>
22+
/// <para>On Github Actions windows hosts we use TC cloud to launch linux docker containers</para>
23+
/// <para>
24+
/// When forks run the tests on pull request TestContainers Cloud won't be configured and available.
25+
/// So we opt to skip instead.
26+
/// </para>
27+
/// </summary>
28+
public sealed class DockerTheory : TheoryAttribute
29+
{
30+
public DockerTheory() => Skip = ShouldSkip();
31+
32+
public static string ShouldSkip()
33+
{
34+
var tcCloudConfigured = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TC_CLOUD_TOKEN"));
35+
if (TestEnvironment.IsGitHubActions
36+
&& TestEnvironment.IsWindows
37+
&& !tcCloudConfigured)
38+
return "Running on Github Action Windows host with no active TC_CLOUD_TOKEN configuration, skipping.";
39+
// if running locally skip the test because it needs docker installed.
40+
else if (!DockerUtils.HasDockerInstalled)
41+
return "This test requires docker to be installed";
42+
43+
return null;
44+
}
45+
}
46+
47+
/// <summary>
48+
/// Marks a test that has to be running inside of a docker container
49+
/// </summary>
50+
public class RunningInDockerFactAttribute : FactAttribute
51+
{
52+
public RunningInDockerFactAttribute()
53+
{
54+
if (!DockerUtils.IsRunningInDocker())
55+
Skip = "Not running in a docker container";
56+
}
57+
}
58+
59+
internal static class DockerUtils
60+
{
61+
public static bool IsRunningInDocker() =>
62+
File.Exists("/proc/1/cgroup") && File.ReadAllText("/proc/1/cgroup").Contains("docker");
63+
64+
public static bool HasDockerInstalled { get; }
65+
66+
static DockerUtils()
67+
{
68+
try
69+
{
70+
var result = Proc.Start(new StartArguments("docker", "--version"));
71+
HasDockerInstalled = result.ExitCode == 0;
72+
}
73+
catch (Exception)
74+
{
75+
HasDockerInstalled = false;
76+
}
77+
}
78+
79+
}

test/instrumentations/Elastic.Apm.Docker.Tests/BasicDockerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// See the LICENSE file in the project root for more information
44

55
using Elastic.Apm.Report;
6-
using Elastic.Apm.Tests.Utilities.Docker;
6+
using Elastic.Apm.Tests.Utilities.XUnit;
77
using FluentAssertions;
88

99
namespace Elastic.Apm.Docker.Tests

test/instrumentations/Elastic.Apm.Elasticsearch.Tests/ElasticsearchTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using Elastic.Apm.Api;
1010
using Elastic.Apm.DiagnosticSource;
1111
using Elastic.Apm.Tests.Utilities;
12-
using Elastic.Apm.Tests.Utilities.Docker;
1312
using Elastic.Apm.Tests.Utilities.XUnit;
1413
using Elasticsearch.Net;
1514
using FluentAssertions;

test/instrumentations/Elastic.Apm.MongoDb.Tests/MongoApmTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using Elastic.Apm.Api;
1111
using Elastic.Apm.MongoDb.Tests.Fixture;
1212
using Elastic.Apm.Tests.Utilities;
13-
using Elastic.Apm.Tests.Utilities.Docker;
1413
using Elastic.Apm.Tests.Utilities.XUnit;
1514
using FluentAssertions;
1615
using MongoDB.Bson;

test/instrumentations/Elastic.Apm.SqlClient.Tests/EfCoreWithMsSqlTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Elastic.Apm.EntityFrameworkCore;
99
using Elastic.Apm.Instrumentations.SqlClient;
1010
using Elastic.Apm.Tests.Utilities;
11-
using Elastic.Apm.Tests.Utilities.Docker;
1211
using Elastic.Apm.Tests.Utilities.XUnit;
1312
using FluentAssertions;
1413
using Microsoft.EntityFrameworkCore;

test/instrumentations/Elastic.Apm.SqlClient.Tests/SqlClientListenerTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using Elastic.Apm.Api;
1212
using Elastic.Apm.Instrumentations.SqlClient;
1313
using Elastic.Apm.Tests.Utilities;
14-
using Elastic.Apm.Tests.Utilities.Docker;
1514
using Elastic.Apm.Tests.Utilities.XUnit;
1615
using FluentAssertions;
1716
using Xunit;

test/instrumentations/Elastic.Apm.StackExchange.Redis.Tests/ProfilingSessionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using System.Threading.Tasks;
99
using Elastic.Apm.Api;
1010
using Elastic.Apm.Tests.Utilities;
11-
using Elastic.Apm.Tests.Utilities.Docker;
11+
using Elastic.Apm.Tests.Utilities.XUnit;
1212
using FluentAssertions;
1313
using StackExchange.Redis;
1414
using Testcontainers.Redis;

test/instrumentations/Elastic.Clients.Elasticsearch.Tests/ElasticsearchTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
using Elastic.Apm.DiagnosticSource;
1212
using Elastic.Apm.Elasticsearch;
1313
using Elastic.Apm.Tests.Utilities;
14-
using Elastic.Apm.Tests.Utilities.Docker;
14+
using Elastic.Apm.Tests.Utilities.XUnit;
1515
using FluentAssertions;
1616
using Xunit;
1717
using Xunit.Abstractions;

test/profiler/Elastic.Apm.Profiler.Managed.Tests/AdoNet/MySqlCommandTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using System.Threading.Tasks;
1010
using Elastic.Apm.Tests.MockApmServer;
1111
using Elastic.Apm.Tests.Utilities;
12-
using Elastic.Apm.Tests.Utilities.Docker;
12+
using Elastic.Apm.Tests.Utilities.XUnit;
1313
using FluentAssertions;
1414
using Xunit;
1515
using Xunit.Abstractions;

test/profiler/Elastic.Apm.Profiler.Managed.Tests/AdoNet/NpgSqlCommandTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using System.Threading.Tasks;
1010
using Elastic.Apm.Tests.MockApmServer;
1111
using Elastic.Apm.Tests.Utilities;
12-
using Elastic.Apm.Tests.Utilities.Docker;
12+
using Elastic.Apm.Tests.Utilities.XUnit;
1313
using FluentAssertions;
1414
using Xunit;
1515
using Xunit.Abstractions;

test/profiler/Elastic.Apm.Profiler.Managed.Tests/AdoNet/OracleManagedDataAccessCommandTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using System.Threading.Tasks;
1010
using Elastic.Apm.Tests.MockApmServer;
1111
using Elastic.Apm.Tests.Utilities;
12-
using Elastic.Apm.Tests.Utilities.Docker;
12+
using Elastic.Apm.Tests.Utilities.XUnit;
1313
using FluentAssertions;
1414
using Xunit;
1515
using Xunit.Abstractions;

0 commit comments

Comments
 (0)