Skip to content

Commit 01f224d

Browse files
Ticket #14 : Configure function in order to return "/metrics"
1 parent ef1d2dc commit 01f224d

19 files changed

+177
-4
lines changed

GatewayDockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ FROM mcr.microsoft.com/dotnet/aspnet:5.0
22

33
COPY build/results/services/Gateway/ App/
44
ENV ASPNETCORE_URLS=http://*:8080
5+
ENV ASPNETCORE_ENVIRONMENT=Docker
56

67
EXPOSE 8080
78

conf/docker/prometheus/prometheus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ scrape_configs:
2323
- job_name: "prometheus"
2424
file_sd_configs:
2525
- files:
26-
- 'targets.json'
26+
- '/shared/targets.json'

default.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ task initLocalKubernetes {
9090
exec { kubectl apply -f ./kubernetes/run-mssql.yml --namespace=faas }
9191
exec { kubectl apply -f ./kubernetes/mssql-external-svc.yml --namespace=faas }
9292
exec { kubectl apply -f ./kubernetes/mssql-internal-svc.yml --namespace=faas }
93+
exec { kubectl apply -f ./kubernetes/prometheus-persistent-volume.yml --namespace=faas }
94+
exec { kubectl apply -f ./kubernetes/prometheus-persistent-volume-claim.yml --namespace=faas }
9395
exec { kubectl apply -f ./kubernetes/run-faas-kubernetes.yml --namespace=faas }
9496
exec { kubectl apply -f ./kubernetes/faas-kubernetes-svc.yml --namespace=faas }
9597
exec { kubectl apply -f ./kubernetes/run-faas-gateway.yml --namespace=faas }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim
3+
metadata:
4+
name: prometheus-pv-claim
5+
spec:
6+
storageClassName: manual
7+
accessModes:
8+
- ReadWriteOnce
9+
resources:
10+
requests:
11+
storage: 3Gi
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: PersistentVolume
3+
metadata:
4+
name: prometheus-pv-volume
5+
labels:
6+
type: local
7+
spec:
8+
storageClassName: manual
9+
capacity:
10+
storage: 10Gi
11+
accessModes:
12+
- ReadWriteOnce
13+
hostPath:
14+
path: "/conf"

kubernetes/run-faas-gateway.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ spec:
1212
labels:
1313
run: faas-gateway
1414
spec:
15+
volumes:
16+
- name: prometheus-pv-storage
17+
persistentVolumeClaim:
18+
claimName: prometheus-pv-claim
1519
containers:
1620
- name: faas-gateway
1721
image: localhost:5000/faasgateway
1822
ports:
1923
- containerPort: 8080
24+
volumeMounts:
25+
- mountPath: "/shared"
26+
name: prometheus-pv-storage

kubernetes/run-prometheus.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ spec:
1212
labels:
1313
run: faas-prometheus
1414
spec:
15+
volumes:
16+
- name: prometheus-pv-storage
17+
persistentVolumeClaim:
18+
claimName: prometheus-pv-claim
1519
containers:
1620
- name: faas-website
1721
image: localhost:5000/faasprometheus
1822
ports:
1923
- containerPort: 9090
24+
volumeMounts:
25+
- mountPath: "/shared"
26+
name: prometheus-pv-storage

src/FaasNet.Gateway.Core/Functions/Commands/Handlers/PublishFunctionCommandHandler.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using FaasNet.Gateway.Core.Domains;
22
using FaasNet.Gateway.Core.Exceptions;
33
using FaasNet.Gateway.Core.Factories;
4+
using FaasNet.Gateway.Core.Helpers;
45
using FaasNet.Gateway.Core.Repositories;
56
using FaasNet.Gateway.Core.Resources;
67
using MediatR;
@@ -18,15 +19,18 @@ public class PublishFunctionCommandHandler : IRequestHandler<PublishFunctionComm
1819
{
1920
private readonly IHttpClientFactory _httpClientFactory;
2021
private readonly IFunctionCommandRepository _functionRepository;
22+
private readonly IPrometheusHelper _prometheusHelper;
2123
private readonly GatewayConfiguration _configuration;
2224

2325
public PublishFunctionCommandHandler(
2426
IHttpClientFactory httpClientFactory,
2527
IFunctionCommandRepository functionRepository,
28+
IPrometheusHelper prometheusHelper,
2629
IOptions<GatewayConfiguration> configuration)
2730
{
2831
_httpClientFactory = httpClientFactory;
2932
_functionRepository = functionRepository;
33+
_prometheusHelper = prometheusHelper;
3034
_configuration = configuration.Value;
3135
}
3236

@@ -51,6 +55,7 @@ public async Task<bool> Handle(PublishFunctionCommand command, CancellationToken
5155
function = FunctionAggregate.Create(command.Name, command.Image);
5256
await _functionRepository.Add(function, cancellationToken);
5357
await _functionRepository.SaveChanges(cancellationToken);
58+
_prometheusHelper.Add(command.Name);
5459
return true;
5560
}
5661
}

src/FaasNet.Gateway.Core/Functions/Commands/Handlers/UnpublishFunctionCommandHandler.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using FaasNet.Gateway.Core.Exceptions;
22
using FaasNet.Gateway.Core.Factories;
3+
using FaasNet.Gateway.Core.Helpers;
34
using FaasNet.Gateway.Core.Repositories;
45
using FaasNet.Gateway.Core.Resources;
56
using MediatR;
@@ -15,15 +16,18 @@ public class UnpublishFunctionCommandHandler : IRequestHandler<UnpublishFunction
1516
{
1617
private readonly IHttpClientFactory _httpClientFactory;
1718
private readonly IFunctionCommandRepository _functionRepository;
19+
private readonly IPrometheusHelper _prometheusHelper;
1820
private readonly GatewayConfiguration _configuration;
1921

2022
public UnpublishFunctionCommandHandler(
2123
IHttpClientFactory httpClientFactory,
2224
IFunctionCommandRepository functionRepository,
25+
IPrometheusHelper prometheusHelper,
2326
IOptions<GatewayConfiguration> configuration)
2427
{
2528
_httpClientFactory = httpClientFactory;
2629
_functionRepository = functionRepository;
30+
_prometheusHelper = prometheusHelper;
2731
_configuration = configuration.Value;
2832
}
2933

@@ -46,6 +50,7 @@ public async Task<bool> Handle(UnpublishFunctionCommand command, CancellationTok
4650
httpResult.EnsureSuccessStatusCode();
4751
await _functionRepository.Delete(function, cancellationToken);
4852
await _functionRepository.SaveChanges(cancellationToken);
53+
_prometheusHelper.Remove(command.Name);
4954
return true;
5055
}
5156
}

src/FaasNet.Gateway.Core/GatewayConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ public GatewayConfiguration()
88
}
99

1010
public string FunctionApi { get; set; }
11+
public string PrometheusFilePath { get; set; }
1112
}
1213
}

0 commit comments

Comments
 (0)