Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

features - dotnet pe tester updates #178

Merged
merged 6 commits into from
Jul 25, 2024
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/pr-app-service-private-endpoint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

env:
CONFIGURATION: Release
DOTNET_CORE_VERSION: 7.0.x
DOTNET_CORE_VERSION: 8.0.x
WORKING_DIRECTORY: AppService-FrontDoor-PrivateEndpoints

permissions:
Expand All @@ -21,7 +21,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Build and Scan .Net Function App
uses: ./.github/actions/build-dotnet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageReference Include="Npgsql" Version="8.0.3" />
<PackageReference Include="OpenTelemetry" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.9.0-beta.2" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0" />
<PackageReference Include="StackExchange.Redis" Version="2.8.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>
Expand Down
35 changes: 27 additions & 8 deletions AppService-FrontDoor-PrivateEndpoints/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Dapper;
using Microsoft.Data.SqlClient;
using Npgsql;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
using StackExchange.Redis;

var builder = WebApplication.CreateBuilder(args);
Expand All @@ -15,18 +17,35 @@

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddHealthChecks();

builder.Services.AddOpenTelemetry()
.WithTracing(builder => builder
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddConsoleExporter()
.AddOtlpExporter())
.WithMetrics(builder => builder
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation()
.AddConsoleExporter()
.AddPrometheusExporter()
.AddOtlpExporter());

var app = builder.Build();

app.UseSwagger();
app.UseSwaggerUI();
app.UseOpenTelemetryPrometheusScrapingEndpoint();
app.MapHealthChecks("/health");

app.UseHttpsRedirection();
const string connStringMessage = "Connection string not found.";

app.MapGet("/testappconfig", async () =>
{
var endpoint = builder.Configuration["APP_CONFIG_ENDPOINT"] ?? "";
var key = builder.Configuration["CONFIG_NAME"] ?? "";
var key = builder.Configuration["APP_CONFIG_ENDPOINT_KEY"] ?? "";

var value = Guid.NewGuid().ToString();

Expand All @@ -45,7 +64,7 @@
var mySetting = configuration.GetValue<string>("POSTGRES_CONNECTIONSTRING");

if (string.IsNullOrEmpty(mySetting))
throw new ArgumentException("Connection string not found.");
throw new ArgumentException(connStringMessage);

await using var conn = new NpgsqlConnection(mySetting);
await conn.OpenAsync();
Expand All @@ -71,10 +90,10 @@
var mySetting = configuration.GetValue<string>("SQL_CONNECTIONSTRING");

if (string.IsNullOrEmpty(mySetting))
throw new ArgumentException("Connection string not found.");
throw new ArgumentException(connStringMessage);

using var con = new SqlConnection(mySetting);
con.Open();
await con.OpenAsync();

var version = await con.ExecuteScalarAsync<string>("SELECT @@VERSION");

Expand All @@ -95,9 +114,9 @@
var mySetting = configuration.GetValue<string>("CACHE_CONNECTIONSTRING");

if (string.IsNullOrEmpty(mySetting))
throw new ArgumentException("Connection string not found.");
throw new ArgumentException(connStringMessage);

var redis = ConnectionMultiplexer.Connect(mySetting);
var redis = await ConnectionMultiplexer.ConnectAsync(mySetting);

var cache = redis.GetDatabase();

Expand All @@ -122,7 +141,7 @@
var mySetting = configuration.GetValue<string>("STORAGE_CONNECTIONSTRING");

if (string.IsNullOrEmpty(mySetting))
throw new ArgumentException("Connection string not found.");
throw new ArgumentException(connStringMessage);

var containerName = "test-container";

Expand Down
2 changes: 1 addition & 1 deletion AppService-FrontDoor-PrivateEndpoints/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"AllowedHosts": "*",
"APP_CONFIG_ENDPOINT": "",
"CONFIG_NAME": "",
"APP_CONFIG_ENDPOINT_KEY": "",
"POSTGRES_CONNECTIONSTRING": "",
"SQL_CONNECTIONSTRING": "",
"CACHE_CONNECTIONSTRING": "",
Expand Down
72 changes: 72 additions & 0 deletions AppService-FrontDoor-PrivateEndpoints/k8s/dotnet-pe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: dotnet-pe-tester
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: dotnet-pe-tester
template:
metadata:
labels:
app: dotnet-pe-tester
annotations:
prometheus.io/scrape: 'true'
prometheus.io/path: '/metrics'
prometheus.io/port: '8080'
spec:
automountServiceAccountToken: false
containers:
- name: dotnet-pe-tester
image: ghcr.io/goncalvesj/dotnet-pe-tester:latest
imagePullPolicy: Always
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- NET_RAW
runAsUser: 5678
readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
env:
- name: APP_CONFIG_ENDPOINT
value: ""
- name: APP_CONFIG_ENDPOINT_KEY
value: ""
- name: POSTGRES_CONNECTIONSTRING
value: ""
- name: SQL_CONNECTIONSTRING
value: ""
- name: CACHE_CONNECTIONSTRING
value: ""
- name: STORAGE_CONNECTIONSTRING
value: ""
resources:
requests:
memory: "64Mi"
cpu: "250m"
ephemeral-storage: "1Gi"
limits:
memory: "128Mi"
cpu: "500m"
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: dotnet-pe-tester
namespace: default
spec:
selector:
app: dotnet-pe-tester
type: ClusterIP
ports:
- port: 8080
targetPort: 8080
Comment on lines +61 to +72

Check notice

Code scanning / checkov

The default namespace should not be used Note

The default namespace should not be used
16 changes: 16 additions & 0 deletions AppService-FrontDoor-PrivateEndpoints/k8s/network-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
namespace: default
name: dotnet-pe-tester-policy
spec:
podSelector:
matchLabels:
app: dotnet-pe-tester
policyTypes:
- Ingress
- Egress
ingress:
- {}
egress:
- {}
Loading