11
11
using Microsoft . Azure . WebJobs . Script . Configuration ;
12
12
using Microsoft . Azure . WebJobs . Script . Description ;
13
13
using Microsoft . Azure . WebJobs . Script . Diagnostics ;
14
+ using Microsoft . Azure . WebJobs . Script . WebHost . ContainerManagement ;
15
+ using Microsoft . Azure . WebJobs . Script . WebHost . Management ;
14
16
using Microsoft . Azure . WebJobs . Script . WebHost . Metrics ;
15
17
using Microsoft . Azure . WebJobs . Script . WebHost . Models ;
18
+ using Microsoft . Extensions . Logging ;
16
19
using Microsoft . Extensions . Options ;
17
20
18
21
namespace Microsoft . Azure . WebJobs . Script . WebHost . Diagnostics
@@ -27,11 +30,12 @@ public class MetricsEventManager : IDisposable
27
30
private readonly int _functionActivityFlushIntervalSeconds ;
28
31
private readonly Timer _metricsFlushTimer ;
29
32
private readonly object _functionActivityTrackerLockObject = new object ( ) ;
33
+ private readonly IMetricsPublisher _metricsPublisher ;
34
+ private readonly ILinuxContainerActivityPublisher _linuxContainerActivityPublisher ;
30
35
private bool _disposed ;
31
- private IMetricsPublisher _metricsPublisher ;
32
36
private IOptionsMonitor < AppServiceOptions > _appServiceOptions ;
33
37
34
- public MetricsEventManager ( IOptionsMonitor < AppServiceOptions > appServiceOptions , IEventGenerator generator , int functionActivityFlushIntervalSeconds , IMetricsPublisher metricsPublisher , int metricsFlushIntervalMS = DefaultFlushIntervalMS )
38
+ public MetricsEventManager ( IOptionsMonitor < AppServiceOptions > appServiceOptions , IEventGenerator generator , int functionActivityFlushIntervalSeconds , IMetricsPublisher metricsPublisher , ILinuxContainerActivityPublisher linuxContainerActivityPublisher , int metricsFlushIntervalMS = DefaultFlushIntervalMS )
35
39
{
36
40
// we read these in the ctor (not static ctor) since it can change on the fly
37
41
_appServiceOptions = appServiceOptions ;
@@ -43,6 +47,7 @@ public MetricsEventManager(IOptionsMonitor<AppServiceOptions> appServiceOptions,
43
47
_metricsFlushTimer = new Timer ( TimerFlush , null , metricsFlushIntervalMS , metricsFlushIntervalMS ) ;
44
48
45
49
_metricsPublisher = metricsPublisher ;
50
+ _linuxContainerActivityPublisher = linuxContainerActivityPublisher ;
46
51
}
47
52
48
53
/// <summary>
@@ -162,7 +167,8 @@ internal void FunctionStarted(FunctionStartedEvent startedEvent)
162
167
{
163
168
if ( instance == null )
164
169
{
165
- instance = new FunctionActivityTracker ( _appServiceOptions , _eventGenerator , _metricsPublisher , _functionActivityFlushIntervalSeconds ) ;
170
+ instance = new FunctionActivityTracker ( _appServiceOptions , _eventGenerator , _metricsPublisher ,
171
+ _linuxContainerActivityPublisher , _functionActivityFlushIntervalSeconds ) ;
166
172
}
167
173
instance . FunctionStarted ( startedEvent ) ;
168
174
}
@@ -325,21 +331,23 @@ private class FunctionActivityTracker : IDisposable
325
331
{
326
332
private readonly string _executionId = Guid . NewGuid ( ) . ToString ( ) ;
327
333
private readonly object _functionMetricEventLockObject = new object ( ) ;
334
+ private readonly IMetricsPublisher _metricsPublisher ;
335
+ private readonly ILinuxContainerActivityPublisher _linuxContainerActivityPublisher ;
328
336
private ulong _totalExecutionCount = 0 ;
329
337
private int _functionActivityFlushInterval ;
330
338
private CancellationTokenSource _etwTaskCancellationSource = new CancellationTokenSource ( ) ;
331
339
private ConcurrentQueue < FunctionMetrics > _functionMetricsQueue = new ConcurrentQueue < FunctionMetrics > ( ) ;
332
340
private Dictionary < string , RunningFunctionInfo > _runningFunctions = new Dictionary < string , RunningFunctionInfo > ( ) ;
333
341
private bool _disposed = false ;
334
342
private IOptionsMonitor < AppServiceOptions > _appServiceOptions ;
335
- private IMetricsPublisher _metricsPublisher ;
336
343
337
- internal FunctionActivityTracker ( IOptionsMonitor < AppServiceOptions > appServiceOptions , IEventGenerator generator , IMetricsPublisher metricsPublisher , int functionActivityFlushInterval )
344
+ internal FunctionActivityTracker ( IOptionsMonitor < AppServiceOptions > appServiceOptions , IEventGenerator generator , IMetricsPublisher metricsPublisher , ILinuxContainerActivityPublisher linuxContainerActivityPublisher , int functionActivityFlushInterval )
338
345
{
339
346
MetricsEventGenerator = generator ;
340
347
_appServiceOptions = appServiceOptions ;
341
348
_functionActivityFlushInterval = functionActivityFlushInterval ;
342
349
_metricsPublisher = metricsPublisher ;
350
+ _linuxContainerActivityPublisher = linuxContainerActivityPublisher ;
343
351
Task . Run (
344
352
async ( ) =>
345
353
{
@@ -413,7 +421,10 @@ internal void FunctionStarted(FunctionStartedEvent startedEvent)
413
421
{
414
422
if ( ! _runningFunctions . ContainsKey ( key ) )
415
423
{
416
- _runningFunctions . Add ( key , new RunningFunctionInfo ( startedEvent . FunctionMetadata . Name , startedEvent . InvocationId , startedEvent . Timestamp , startedEvent . Success ) ) ;
424
+ _runningFunctions . Add ( key ,
425
+ new RunningFunctionInfo ( startedEvent . FunctionMetadata . Name , startedEvent . InvocationId ,
426
+ startedEvent . Timestamp , startedEvent . Success ,
427
+ startedEvent . FunctionMetadata . Trigger ? . Type ) ) ;
417
428
}
418
429
}
419
430
}
@@ -501,6 +512,11 @@ private void RaiseFunctionMetricEvent(RunningFunctionInfo runningFunctionInfo, i
501
512
currentTime ,
502
513
runningFunctionInfo . StartTime ) ;
503
514
}
515
+
516
+ _linuxContainerActivityPublisher . PublishFunctionExecutionActivity (
517
+ new ContainerFunctionExecutionActivity ( DateTime . UtcNow , runningFunctionInfo . Name ,
518
+ runningFunctionInfo . ExecutionStage , runningFunctionInfo . TriggerType ,
519
+ runningFunctionInfo . Success ) ) ;
504
520
}
505
521
506
522
private static string GetDictionaryKey ( string name , Guid invocationId )
@@ -547,13 +563,14 @@ private List<FunctionMetrics> GetMetricsQueueSnapshot()
547
563
548
564
private class RunningFunctionInfo
549
565
{
550
- public RunningFunctionInfo ( string name , Guid invocationId , DateTime startTime , bool success , ExecutionStage executionStage = ExecutionStage . InProgress )
566
+ public RunningFunctionInfo ( string name , Guid invocationId , DateTime startTime , bool success , string triggerType , ExecutionStage executionStage = ExecutionStage . InProgress )
551
567
{
552
568
Name = name ;
553
569
InvocationId = invocationId ;
554
570
StartTime = startTime ;
555
571
Success = success ;
556
572
ExecutionStage = executionStage ;
573
+ TriggerType = triggerType ;
557
574
}
558
575
559
576
public string Name { get ; private set ; }
@@ -567,6 +584,8 @@ public RunningFunctionInfo(string name, Guid invocationId, DateTime startTime, b
567
584
public DateTime EndTime { get ; set ; }
568
585
569
586
public bool Success { get ; set ; }
587
+
588
+ public string TriggerType { get ; private set ; }
570
589
}
571
590
}
572
591
}
0 commit comments