Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions IntegrationTest/BikeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public BikeService(OrderService orderService)
_orderService = orderService;
}

public void Order(int searchRadius)
{
public void Order(int searchRadius) =>
_orderService.FindNearestVehicle(searchRadius, "bike");
}
}
}
6 changes: 2 additions & 4 deletions IntegrationTest/CarService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public CarService(OrderService orderService)
_orderService = orderService;
}

public void Order(int searchRadius)
{
public void Order(int searchRadius) =>
_orderService.FindNearestVehicle(searchRadius, "car");
}
}
}
3 changes: 1 addition & 2 deletions IntegrationTest/Dockerfile.load-generator
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.9
FROM python:3.12

RUN pip3 install requests

Expand All @@ -7,4 +7,3 @@ COPY load-generator.py ./load-generator.py
ENV PYTHONUNBUFFERED=1

CMD [ "python", "load-generator.py" ]

35 changes: 35 additions & 0 deletions IntegrationTest/HelicopterService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Globalization;
using Pyroscope;

namespace Example;

internal class HelicopterService
{
private readonly OrderService _orderService;

public HelicopterService(OrderService orderService)
{
_orderService = orderService;
}

public async Task Order(int searchRadius)
{
_orderService.FindNearestVehicle(searchRadius, "helicopter");
await DoWorkAsync(searchRadius);
}

private static async Task DoWorkAsync(int searchRadius)
{
var labels = LabelSet.Empty.BuildUpon()
.Add("search_radius", searchRadius.ToString(CultureInfo.InvariantCulture))
.Build();

await LabelsWrapper.DoAsync(labels, async () =>
{
for (long i = 0; i < 1_000; i++)
{
await Task.Delay(0);
}
});
}
}
40 changes: 22 additions & 18 deletions IntegrationTest/OrderService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using Pyroscope;

namespace Example;

Expand All @@ -8,50 +8,54 @@ public void FindNearestVehicle(long searchRadius, string vehicle)
{
lock (_lock)
{
var labels = Pyroscope.LabelSet.Empty.BuildUpon()
var labels = LabelSet.Empty.BuildUpon()
.Add("vehicle", vehicle)
.Build();
Pyroscope.LabelsWrapper.Do(labels, () =>

LabelsWrapper.Do(labels, static (state) =>
{
for (long i = 0; i < searchRadius * 1000000000; i++)
for (long i = 0; i < state.searchRadius * 1_000_000_000; i++)
{
}

if (vehicle.Equals("car"))
if (string.Equals("car", state.vehicle))
{
CheckDriverAvailability(labels, searchRadius);
CheckDriverAvailability(state.labels, state.searchRadius);
}
});
},
(labels, searchRadius, vehicle));
}
}

private readonly object _lock = new();

private static void CheckDriverAvailability(Pyroscope.LabelSet ctx, long searchRadius)
private static void CheckDriverAvailability(LabelSet labels, long searchRadius)
{
var region = System.Environment.GetEnvironmentVariable("REGION") ?? "unknown_region";
ctx = ctx.BuildUpon()
var region = Environment.GetEnvironmentVariable("REGION") ?? "unknown_region";
labels = labels.BuildUpon()
.Add("driver_region", region)
.Build();
Pyroscope.LabelsWrapper.Do(ctx, () =>

LabelsWrapper.Do(labels, static (state) =>
{
for (long i = 0; i < searchRadius * 1000000000; i++)
for (long i = 0; i < state.searchRadius * 1_000_000_000; i++)
{
}

var now = DateTime.Now.Minute % 2 == 0;
var forceMutexLock = DateTime.Now.Minute % 2 == 0;
if ("eu-north".Equals(region) && forceMutexLock)

if (string.Equals("eu-north", state.region) && forceMutexLock)
{
MutexLock(searchRadius);
MutexLock(state.searchRadius);
}
});
},
(region, searchRadius));
}

private static void MutexLock(long searchRadius)
{
for (long i = 0; i < 30 * searchRadius * 1000000000; i++)
for (long i = 0; i < 30 * searchRadius * 1_000_000_000; i++)
{
}
}
}
}
74 changes: 33 additions & 41 deletions IntegrationTest/Program.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,37 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Collections;
using Example;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);

namespace Example;
builder.Services.AddSingleton<BikeService>();
builder.Services.AddSingleton<CarService>();
builder.Services.AddSingleton<HelicopterService>();
builder.Services.AddSingleton<OrderService>();
builder.Services.AddSingleton<ScooterService>();

public static class Program
var app = builder.Build();

app.MapGet("/bike", (BikeService service) =>
{
service.Order(1);
return "Bike ordered";
});

app.MapGet("/scooter", (ScooterService service) =>
{
service.Order(2);
return "Scooter ordered";
});

app.MapGet("/car", (CarService service) =>
{
service.Order(3);
return "Car ordered";
});

app.MapGet("/helicopter", async (HelicopterService service) =>
{
private static readonly List<FileStream> Files = new();
public static void Main(string[] args)
{
var orderService = new OrderService();
var bikeService = new BikeService(orderService);
var scooterService = new ScooterService(orderService);
var carService = new CarService(orderService);

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/bike", () =>
{
bikeService.Order(1);
return "Bike ordered";
});
app.MapGet("/scooter", () =>
{
scooterService.Order(2);
return "Scooter ordered";
});

app.MapGet("/car", () =>
{
carService.Order(3);
return "Car ordered";
});

app.Run();
}
}
await service.Order(4);
return "Helicopter ordered";
});

app.Run();
12 changes: 12 additions & 0 deletions IntegrationTest/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"Rideshare": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:56129;http://localhost:56130"
}
}
}
6 changes: 5 additions & 1 deletion IntegrationTest/Rideshare.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
<AssemblyName>rideshare</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>rideshare</PackageId>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<!-- Disable NETSDK1138 -->
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../Pyroscope/Pyroscope/Pyroscope.csproj" />
Expand Down
9 changes: 4 additions & 5 deletions IntegrationTest/ScooterService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Diagnostics;

namespace Example;

internal class ScooterService
Expand All @@ -13,9 +11,10 @@ public ScooterService(OrderService orderService)

public void Order(int searchRadius)
{
for (long i = 0; i < 2000000000; i++)
for (long i = 0; i < 2_000_000_000; i++)
{
}

OrderInternal(searchRadius);
DoSomeOtherWork();
}
Expand All @@ -25,9 +24,9 @@ private void OrderInternal(int searchRadius)
_orderService.FindNearestVehicle(searchRadius, "scooter");
}

private void DoSomeOtherWork()
private static void DoSomeOtherWork()
{
for (long i = 0; i < 1000000000; i++)
for (long i = 0; i < 1_000_000_000; i++)
{
}
}
Expand Down
1 change: 1 addition & 0 deletions IntegrationTest/load-generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'bike',
'scooter',
'car',
'helicopter',
]

if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions IntegrationTest/verify_profiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cat profilecli_output.json
labels=$(cat profilecli_output.json)

# Verify that all expected labels are present
expected_labels=("bike" "car" "scooter")
expected_labels=("bike" "car" "helicopter" "scooter")
actual_labels=($(cat profilecli_output.json))

if [ ${#actual_labels[@]} -ne ${#expected_labels[@]} ]; then
Expand All @@ -41,4 +41,4 @@ for i in "${!expected_labels[@]}"; do
fi
done

echo "Successfully verified all expected labels (bike, car, scooter) are present"
echo "Successfully verified all expected labels (bike, car, helicopter, scooter) are present"
4 changes: 2 additions & 2 deletions Pyroscope/Pyroscope.OpenTracing/PyroscopeSpanBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class PyroscopeSpanBuilder : ISpanBuilder
private const string ProfileIdSpanTagKey = "pyroscope.profile.id";

private readonly ISpanBuilder _delegate;
private ISpanContext? _parent;
private readonly ISpanContext? _parent;

internal PyroscopeSpanBuilder(ISpanBuilder spanBuilder, ISpanContext? parent)
{
Expand Down Expand Up @@ -135,7 +135,7 @@ public ISpanBuilder IgnoreActiveSpan()
return this;
}

class PyroscopeScope : IScope
private sealed class PyroscopeScope : IScope
{
private readonly IScope _delegate;
private readonly ISpanContext? _parent;
Expand Down
Loading
Loading