aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Telemetry/TelemetryPublisherConfiguration.cs
blob: a9f4954dd7f6e626d595536f70c207adf6826ea6 (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
using System;
using Tango.BL.Enumerations;

namespace Tango.Telemetry
{
    public class TelemetryPublisherConfiguration
    {
        /// <summary>
        /// Unique identifier of the machine sending telemetry. Used for tagging and routing.
        /// </summary>
        public String SerialNumber { get; set; }

        /// <summary>
        /// Enum representing the type of machine (e.g., X1, X4). Helps differentiate models in telemetry.
        /// </summary>
        public MachineTypes MachineType { get; set; }

        /// <summary>
        /// Environment in which the telemetry is being published (e.g., Production, QA, Dev).
        /// </summary>
        public String Environment { get; set; }

        /// <summary>
        /// Interval for checking and reprocessing failed/pending telemetry from local storage.
        /// </summary>
        public TimeSpan PendingStorageCheckInterval { get; set; }

        /// <summary>
        /// Maximum number of pending telemetry records to process in a single retry cycle.
        /// </summary>
        public int MaxPendingStorageTelemetriesPerCycle { get; set; }

        /// <summary>
        /// Frequency at which historical sources are polled to request backlogged or missed telemetry.
        /// </summary>
        public TimeSpan HistorySourcesRequestInterval { get; set; }

        /// <summary>
        /// Maximum number of telemetry packages allowed in memory queues before rejecting new packages.
        /// </summary>
        public int MaxPendingTelemetries { get; set; }

        /// <summary>
        /// Whether exponential backoff should be applied to retry logic per destination.
        /// </summary>
        public bool EnableBackoff { get; set; }

        /// <summary>
        /// The maximum amount of time to delay retries during exponential backoff.
        /// </summary>
        public TimeSpan MaxExponentialBackoff { get; set; } = TimeSpan.FromHours(1);

        /// <summary>
        /// Gets or sets the interval at which the published telemetry cache cleanup process should occur.
        /// This defines how frequently old published telemetry entries are eligible for pruning,
        /// based on their publication timestamp.
        /// </summary>
        public TimeSpan PublishedTelemetriesCacheCleanupInterval { get; set; } = TimeSpan.FromHours(1);

        public TelemetryPublisherConfiguration()
        {
            PendingStorageCheckInterval = TimeSpan.FromMinutes(1);
            MaxPendingStorageTelemetriesPerCycle = 100;
            HistorySourcesRequestInterval = TimeSpan.FromMinutes(1);
            MaxPendingTelemetries = 200;
        }

        public void Validate()
        {
            if (!SerialNumber.IsNotNullOrEmpty())
                throw new ArgumentNullException(nameof(SerialNumber), "SerialNumber is not set or empty.");

            if (!Environment.IsNotNullOrEmpty())
                throw new ArgumentNullException(nameof(Environment), "Environment is not set or empty.");

            if (!Enum.IsDefined(typeof(MachineTypes), MachineType))
                throw new ArgumentOutOfRangeException(nameof(MachineType), "MachineType is not a valid enum value.");

            if (PendingStorageCheckInterval.TotalSeconds < 5)
                throw new ArgumentOutOfRangeException(nameof(PendingStorageCheckInterval), "PendingStorageCheckInterval must be at least 5 seconds.");
        }
    }
}