blob: b423580d2039903e98ce4224bf02b58882deb85d (
plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tango.Telemetry
{
/// <summary>
/// Represents the result of publishing a telemetry package to one or more destinations.
/// Contains the status and metrics per destination and total publish time.
/// </summary>
public class TelemetryPublishResult
{
/// <summary>
/// Defines the outcome of an attempt to publish to a specific destination.
/// </summary>
public enum DestinationStatus
{
None,
Passed,
Unavailable,
Failed,
Postponed
}
/// <summary>
/// Contains information about the result of publishing telemetry to a specific destination.
/// </summary>
public class DestinationResult
{
/// <summary>
/// The destination to which the telemetry was attempted to be published.
/// </summary>
public ITelemetryDestination Destination { get; set; }
/// <summary>
/// The result status of the publish attempt.
/// </summary>
public DestinationStatus Status { get; set; }
/// <summary>
/// Any error that occurred during the publish attempt.
/// </summary>
public Exception Error { get; set; }
/// <summary>
/// The amount of time it took to attempt publishing to this destination.
/// </summary>
public TimeSpan ElapsedTime { get; set; }
/// <summary>
/// Number of retry attempts for this destination.
/// </summary>
public int RetryCount { get; internal set; }
/// <summary>
/// Time until the next eligible retry attempt.
/// </summary>
public TimeSpan RetryDelay { get; internal set; }
}
/// <summary>
/// Gets or sets the telemetry source that generated the package associated with this publish result.
/// </summary>
public ITelemetrySource Source { get; set; }
/// <summary>
/// Gets or sets the source type of the telemetry (e.g., Streaming, ExternalStorage, PendingStorage).
/// </summary>
public TelemetrySourceTypes SourceType { get; set; }
/// <summary>
/// List of results for each destination that was part of the publish process.
/// </summary>
public List<DestinationResult> DestinationsResults { get; set; }
/// <summary>
/// Total elapsed time taken to publish the telemetry package across all destinations.
/// </summary>
public TimeSpan TotalElapsedTime { get; set; }
/// <summary>
/// Time spent outside of destination publishing, typically system overhead or coordination.
/// </summary>
public TimeSpan OverheadTime
{
get { return TimeSpan.FromMilliseconds(TotalElapsedTime.TotalMilliseconds - DestinationsResults.Sum(x => x.ElapsedTime.TotalMilliseconds)); }
}
/// <summary>
/// Initializes a new instance of the TelemetryPublishResult class.
/// </summary>
public TelemetryPublishResult()
{
DestinationsResults = new List<DestinationResult>();
}
public override string ToString()
{
var sb = new StringBuilder();
sb.AppendLine($"Source: {Source?.Name ?? "Unknown"} ({SourceType})");
sb.AppendLine($"Total Elapsed Time: {TotalElapsedTime.TotalMilliseconds:F1} ms");
sb.AppendLine($"Overhead Time: {OverheadTime.TotalMilliseconds:F1} ms");
sb.AppendLine("Destination Results:");
foreach (var result in DestinationsResults ?? Enumerable.Empty<DestinationResult>())
{
sb.Append($" - {result.Destination.Name}: {result.Status}, {result.ElapsedTime.TotalMilliseconds:F1} ms");
if (!string.IsNullOrWhiteSpace(result.Error.ToStringSafe()))
sb.Append($" (Error: {result.Error})");
sb.AppendLine();
}
return sb.ToString();
}
}
}
|