forked from grafana/grafana-opentelemetry-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add .NET 8 to the test matrix (grafana#81)
* Add .NET 8 to the test matrix --------- Co-authored-by: Matthew Hensley <matthew.hensley@grafana.com>
- Loading branch information
1 parent
3281582
commit 082c712
Showing
15 changed files
with
407 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
docker/docker-compose-aspnetcore/docker-compose.net8.oats.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
version: '3.4' | ||
|
||
services: | ||
aspnetcore: | ||
image: ${DOCKER_REGISTRY-}aspnetcore | ||
build: | ||
context: ../.. | ||
dockerfile: examples/net8.0/aspnetcore/Dockerfile | ||
environment: | ||
- OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:4317 | ||
ports: | ||
- "5000:8080" | ||
- "8080:8080" # for OATs | ||
depends_on: | ||
- redis | ||
- mssql | ||
redis: | ||
image: redis:7.2 | ||
ports: | ||
- "6379:6379" | ||
mssql: | ||
image: mcr.microsoft.com/mssql/server:2022-latest | ||
environment: | ||
- ACCEPT_EULA=Y | ||
- MSSQL_SA_PASSWORD=Password12345%% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
examples/net8.0/aspnetcore/Controllers/HttpClientController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// Copyright Grafana Labs | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace aspnetcore.Controllers; | ||
[Route("api/[controller]/[action]")] | ||
[ApiController] | ||
public class HttpClientController : ControllerBase | ||
{ | ||
private readonly ILogger<HttpClientController> _logger; | ||
|
||
public HttpClientController(ILogger<HttpClientController> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
[HttpGet] | ||
public async Task<ActionResult<IEnumerable<string>>> Get() | ||
{ | ||
var client = new HttpClient(); | ||
var response = await client.GetAsync("https://postman-echo.com/get?hello=world"); | ||
var content = await response.Content.ReadAsStringAsync(); | ||
return Ok(content); | ||
} | ||
|
||
[HttpGet] | ||
public async Task<ActionResult<IEnumerable<string>>> GetError() | ||
{ | ||
var client = new HttpClient(); | ||
var response = await client.GetAsync("http://postman-echo.com/status/500"); | ||
var content = await response.Content.ReadAsStringAsync(); | ||
return Ok(content); | ||
} | ||
|
||
[HttpPost] | ||
public async Task<ActionResult<string>> Post() | ||
{ | ||
var client = new HttpClient(); | ||
var response = await client.PostAsync("https://postman-echo.com/post", new StringContent("Hello World")); | ||
var content = await response.Content.ReadAsStringAsync(); | ||
return Ok(content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// Copyright Grafana Labs | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
using System.Data; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Data.SqlClient; | ||
|
||
namespace aspnetcore.Controllers; | ||
[Route("api/[controller]/[action]")] | ||
[ApiController] | ||
public class MsSqlController : ControllerBase | ||
{ | ||
private readonly ILogger<MsSqlController> _logger; | ||
private readonly SqlConnection _db; | ||
|
||
public MsSqlController(ILogger<MsSqlController> logger, SqlConnection db) | ||
{ | ||
_logger = logger; | ||
_db = db; | ||
} | ||
|
||
[HttpGet] | ||
public async Task<ActionResult<IEnumerable<string>>> Tables() | ||
{ | ||
this._db.Open(); | ||
|
||
using (var command = _db.CreateCommand()) | ||
{ | ||
command.CommandText = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES"; | ||
var tables = new List<string>(); | ||
|
||
using (var reader = await command.ExecuteReaderAsync()) | ||
{ | ||
while (await reader.ReadAsync()) | ||
{ | ||
tables.Add(reader.GetString(0)); | ||
} | ||
} | ||
return Ok(tables); | ||
} | ||
} | ||
|
||
[HttpGet] | ||
public async Task<ActionResult<IEnumerable<string>>> ServerInfo() | ||
{ | ||
this._db.Open(); | ||
|
||
using (var command = _db.CreateCommand()) | ||
{ | ||
command.CommandText = "sp_server_info"; | ||
command.CommandType = CommandType.StoredProcedure; | ||
|
||
var serverInfo = new List<string>(); | ||
|
||
using (var reader = await command.ExecuteReaderAsync()) | ||
{ | ||
while (await reader.ReadAsync()) | ||
{ | ||
serverInfo.Add($"ID={reader.GetInt32(0)} , NAME={reader.GetString(1)} , VALUE={reader.GetString(2)}"); | ||
} | ||
} | ||
|
||
return Ok(serverInfo); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// Copyright Grafana Labs | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
using System.ComponentModel.DataAnnotations; | ||
using Microsoft.AspNetCore.Mvc; | ||
using StackExchange.Redis; | ||
|
||
namespace aspnetcore.Controllers; | ||
[Route("api/[controller]/[action]")] | ||
[ApiController] | ||
public class RedisController : ControllerBase | ||
{ | ||
const string LIST_KEY = "list"; | ||
private readonly ILogger<RedisController> _logger; | ||
private IDatabase _redisDb; | ||
|
||
public RedisController(ILogger<RedisController> logger, IDatabase database) | ||
{ | ||
_logger = logger; | ||
_redisDb = database; | ||
} | ||
|
||
[HttpPost] | ||
public async Task<ActionResult<string>> LeftPush([FromBody] LeftPushBody data) | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
return StatusCode(500); | ||
} | ||
|
||
var length = await _redisDb.ListLeftPushAsync(LIST_KEY, data.Name); | ||
_logger.LogInformation($"LeftPush: {data.Name} - {length}"); | ||
return Ok(); | ||
} | ||
|
||
[HttpPost] | ||
public async Task<ActionResult<string>> LeftPop() | ||
{ | ||
var value = await _redisDb.ListLeftPopAsync(LIST_KEY); | ||
_logger.LogInformation($"LeftPop: {value}"); | ||
return Ok(value); | ||
} | ||
|
||
public class LeftPushBody | ||
{ | ||
[Required] | ||
public string? Name { get; set; } | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
examples/net8.0/aspnetcore/Controllers/WeatherForecastController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// Copyright Grafana Labs | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace aspnetcore.Controllers; | ||
[ApiController] | ||
[Route("[controller]")] | ||
public class WeatherForecastController : ControllerBase | ||
{ | ||
private static readonly string[] Summaries = new[] | ||
{ | ||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
}; | ||
|
||
private readonly ILogger<WeatherForecastController> _logger; | ||
|
||
public WeatherForecastController(ILogger<WeatherForecastController> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
[HttpGet(Name = "GetWeatherForecast")] | ||
public IEnumerable<WeatherForecast> Get() | ||
{ | ||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast | ||
{ | ||
Date = DateTime.Now.AddDays(index), | ||
TemperatureC = Random.Shared.Next(-20, 55), | ||
Summary = Summaries[Random.Shared.Next(Summaries.Length)] | ||
}) | ||
.ToArray(); | ||
} | ||
|
||
public class WeatherForecast | ||
{ | ||
public DateTime Date { get; set; } | ||
public int TemperatureC { get; set; } | ||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
public string? Summary { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. | ||
|
||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base | ||
WORKDIR /app | ||
EXPOSE 80 | ||
|
||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build | ||
|
||
ARG DOTNET_PUBLISH_ARGS="" | ||
|
||
WORKDIR /src | ||
COPY ["examples/net8.0/aspnetcore/aspnetcore.csproj", "examples/net8.0/aspnetcore/"] | ||
RUN dotnet restore "examples/net8.0/aspnetcore/aspnetcore.csproj" | ||
COPY . . | ||
WORKDIR "/src/examples/net8.0/aspnetcore" | ||
RUN dotnet build "aspnetcore.csproj" -c Release -o /app/build | ||
|
||
FROM build AS publish | ||
RUN dotnet publish "aspnetcore.csproj" -c Release -o /app/publish ${DOTNET_PUBLISH_ARGS} | ||
|
||
FROM base AS final | ||
WORKDIR /app | ||
COPY --from=publish /app/publish . | ||
RUN apt-get update && apt-get install -y curl | ||
ENTRYPOINT ["dotnet", "aspnetcore.dll"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// Copyright Grafana Labs | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
using Grafana.OpenTelemetry; | ||
using Microsoft.Data.SqlClient; | ||
using OpenTelemetry.Trace; | ||
using StackExchange.Redis; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
builder.Services.AddOpenTelemetry() | ||
.WithMetrics(builder => builder.UseGrafana()) | ||
.WithTracing(builder => builder.UseGrafana().AddConsoleExporter()); | ||
|
||
// Redis | ||
builder.Services.AddSingleton<IConnectionMultiplexer>( | ||
sp => ConnectionMultiplexer.Connect("redis:6379")); | ||
builder.Services.AddScoped( | ||
sp => sp.GetRequiredService<IConnectionMultiplexer>().GetDatabase()); | ||
|
||
// MSSQL | ||
builder.Services.AddTransient(sp => | ||
{ | ||
var connectionString = "Server=mssql,1433;Database=master;User=sa;Password=Password12345%%;Encrypt=False;TrustServerCertificate=True"; | ||
return new SqlConnection(connectionString); | ||
}); | ||
|
||
builder.Services.AddControllers(); | ||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
var app = builder.Build(); | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
app.UseAuthorization(); | ||
app.MapControllers(); | ||
app.MapGet("/", () => Results.Redirect("/swagger")); | ||
app.Run(); |
Oops, something went wrong.