Skip to content

Commit f1d26b4

Browse files
first draft
1 parent 50db228 commit f1d26b4

24 files changed

+518
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using Azure.Iot.Operations.Protocol;
5+
6+
namespace Azure.Iot.Operations.Services.Observability;
7+
8+
public class AkriObservabilityServiceStub : AkriObservabilityService.AkriObservabilityService.Client
9+
{
10+
public AkriObservabilityServiceStub(
11+
ApplicationContext applicationContext,
12+
IMqttPubSubClient mqttClient,
13+
Dictionary<string, string>? topicTokenMap = null) : base(
14+
applicationContext,
15+
mqttClient,
16+
topicTokenMap)
17+
{
18+
}
19+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using System.Collections.Concurrent;
5+
using Azure.Iot.Operations.Services.Observability.AkriObservabilityService;
6+
7+
namespace Azure.Iot.Operations.Services.Observability;
8+
9+
internal class CachedCounter : ICounter
10+
{
11+
private readonly ConcurrentQueue<IncrementOperation> _operations = new();
12+
13+
public string Name { get; }
14+
public Dictionary<string, string> Labels { get; }
15+
public string? Unit { get; }
16+
17+
public CachedCounter(string name, Dictionary<string, string> labels, string? unit)
18+
{
19+
Name = name;
20+
Labels = labels;
21+
Unit = unit;
22+
}
23+
24+
public void Add(double value)
25+
{
26+
_operations.Enqueue(new IncrementOperation
27+
{
28+
OperationId = Guid.NewGuid().ToString(),
29+
Timestamp = DateTime.UtcNow,
30+
Value = value
31+
});
32+
}
33+
34+
public void Increment()
35+
{
36+
Add(1);
37+
}
38+
39+
public List<IncrementOperation> GetOperationsAndClear(int maxCount)
40+
{
41+
var result = new List<IncrementOperation>();
42+
43+
int count = 0;
44+
while (count < maxCount && _operations.TryDequeue(out var operation))
45+
{
46+
result.Add(operation);
47+
count++;
48+
}
49+
50+
return result;
51+
}
52+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using System.Collections.Concurrent;
5+
using Azure.Iot.Operations.Services.Observability.AkriObservabilityService;
6+
7+
namespace Azure.Iot.Operations.Services.Observability;
8+
9+
internal class CachedGauge : IGauge
10+
{
11+
private readonly ConcurrentQueue<RecordOperation> _operations = new();
12+
13+
public string Name { get; }
14+
public Dictionary<string, string> Labels { get; }
15+
public string? Unit { get; }
16+
17+
public CachedGauge(string name, Dictionary<string, string> labels, string? unit)
18+
{
19+
Name = name;
20+
Labels = labels;
21+
Unit = unit;
22+
}
23+
24+
public void Record(double value)
25+
{
26+
_operations.Enqueue(new RecordOperation
27+
{
28+
OperationId = Guid.NewGuid().ToString(),
29+
Timestamp = DateTime.UtcNow,
30+
Value = value
31+
});
32+
}
33+
34+
public List<RecordOperation> GetOperationsAndClear(int maxCount)
35+
{
36+
var result = new List<RecordOperation>();
37+
38+
int count = 0;
39+
while (count < maxCount && _operations.TryDequeue(out var operation))
40+
{
41+
result.Add(operation);
42+
count++;
43+
}
44+
45+
return result;
46+
}
47+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using System.Collections.Concurrent;
5+
using Azure.Iot.Operations.Services.Observability.AkriObservabilityService;
6+
7+
namespace Azure.Iot.Operations.Services.Observability
8+
{
9+
internal class CachedHistogram : IHistogram
10+
{
11+
private readonly ConcurrentQueue<RecordOperation> _operations = new();
12+
13+
public string Name { get; }
14+
public Dictionary<string, string> Labels { get; }
15+
public string? Unit { get; }
16+
17+
public CachedHistogram(string name, Dictionary<string, string> labels, string? unit)
18+
{
19+
Name = name;
20+
Labels = labels;
21+
Unit = unit;
22+
}
23+
24+
public void Record(double value)
25+
{
26+
_operations.Enqueue(new RecordOperation
27+
{
28+
OperationId = Guid.NewGuid().ToString(),
29+
Timestamp = DateTime.UtcNow,
30+
Value = value
31+
});
32+
}
33+
34+
public List<RecordOperation> GetOperationsAndClear(int maxCount)
35+
{
36+
var result = new List<RecordOperation>();
37+
38+
int count = 0;
39+
while (count < maxCount && _operations.TryDequeue(out var operation))
40+
{
41+
result.Add(operation);
42+
count++;
43+
}
44+
45+
return result;
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)