-
Notifications
You must be signed in to change notification settings - Fork 2
/
MetricsReporter.cs
61 lines (55 loc) · 2.25 KB
/
MetricsReporter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using Akka.Actor;
using Arcane.Operator.Configurations;
using Arcane.Operator.Extensions;
using Arcane.Operator.Models.Api;
using Arcane.Operator.Models.Commands;
using Arcane.Operator.Services.Base.Metrics;
using Arcane.Operator.Services.Metrics.Actors;
using k8s;
using k8s.Models;
using Microsoft.Extensions.Options;
using Snd.Sdk.Metrics.Base;
namespace Arcane.Operator.Services.Metrics;
/// <summary>
/// The IMetricsReporter implementation.
/// </summary>
public class MetricsReporter : IMetricsReporter
{
private readonly MetricsService metricsService;
private readonly IActorRef statusActor;
public MetricsReporter(MetricsService metricsService, ActorSystem actorSystem,
IOptions<MetricsReporterConfiguration> metricsReporterConfiguration)
{
this.metricsService = metricsService;
this.statusActor = actorSystem.ActorOf(Props.Create(() => new MetricsPublisherActor(
metricsReporterConfiguration.Value.MetricsPublisherActorConfiguration,
metricsService)),
nameof(MetricsPublisherActor));
}
/// <inheritdoc cref="IMetricsReporter.ReportStatusMetrics"/>
public SetStreamClassStatusCommand ReportStatusMetrics(SetStreamClassStatusCommand command)
{
if (command.phase.IsFinal())
{
this.statusActor.Tell(new RemoveStreamClassMetricsMessage(command.streamClass.KindRef));
}
else
{
var msg = new AddStreamClassMetricsMessage(command.streamClass.KindRef, "stream_class", command.GetMetricsTags());
this.statusActor.Tell(msg);
}
return command;
}
/// <inheritdoc cref="IMetricsReporter.ReportTrafficMetrics"/>
public (WatchEventType, V1Job) ReportTrafficMetrics((WatchEventType, V1Job) jobEvent)
{
this.metricsService.Count(jobEvent.Item1.TrafficMetricName(), 1, jobEvent.Item2.GetMetricsTags());
return jobEvent;
}
/// <inheritdoc cref="IMetricsReporter.ReportTrafficMetrics"/>
public ResourceEvent<TResource> ReportTrafficMetrics<TResource>(ResourceEvent<TResource> ev) where TResource : IKubernetesObject<V1ObjectMeta>
{
this.metricsService.Count(ev.EventType.TrafficMetricName(), 1, ev.kubernetesObject.GetMetricsTags());
return ev;
}
}