|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
| 17 | +using System; |
| 18 | +using System.Threading; |
| 19 | +using System.Threading.Tasks; |
| 20 | +using AdbcDrivers.Databricks.Telemetry.Models; |
17 | 21 | using AdbcDrivers.Databricks.Telemetry.Proto; |
18 | 22 |
|
19 | 23 | namespace AdbcDrivers.Databricks.Telemetry |
20 | 24 | { |
21 | 25 | /// <summary> |
22 | | - /// Placeholder interface for telemetry client. |
23 | | - /// Will be fully implemented in a future work item. |
| 26 | + /// Client that receives telemetry events from multiple connections to the same host, |
| 27 | + /// batches them, and manages periodic flushing to the backend service. |
24 | 28 | /// </summary> |
25 | | - internal interface ITelemetryClient |
| 29 | + /// <remarks> |
| 30 | + /// <para> |
| 31 | + /// One instance is shared per host via TelemetryClientManager to prevent rate limiting |
| 32 | + /// by consolidating telemetry traffic from concurrent connections to the same host. |
| 33 | + /// </para> |
| 34 | + /// <para> |
| 35 | + /// Thread Safety: All methods are thread-safe and can be called concurrently from |
| 36 | + /// multiple connections. Enqueue() is non-blocking and safe to call from any thread. |
| 37 | + /// FlushAsync() and CloseAsync() coordinate with ongoing flush operations using |
| 38 | + /// internal synchronization. |
| 39 | + /// </para> |
| 40 | + /// <para> |
| 41 | + /// Lifecycle: The client is created by TelemetryClientManager when the first connection |
| 42 | + /// to a host is opened. It remains active as long as any connection to that host is open |
| 43 | + /// (reference counting). When the last connection closes, TelemetryClientManager calls |
| 44 | + /// CloseAsync() to flush pending events and dispose resources. |
| 45 | + /// </para> |
| 46 | + /// </remarks> |
| 47 | + internal interface ITelemetryClient : IAsyncDisposable |
26 | 48 | { |
| 49 | + /// <summary> |
| 50 | + /// Queue a telemetry event for export. This method is non-blocking and thread-safe. |
| 51 | + /// </summary> |
| 52 | + /// <param name="log">The telemetry frontend log to enqueue.</param> |
| 53 | + /// <remarks> |
| 54 | + /// <para> |
| 55 | + /// Events are batched and flushed periodically (configurable flush interval) or when |
| 56 | + /// the batch size limit is reached. This method returns immediately after adding the |
| 57 | + /// event to an internal queue. |
| 58 | + /// </para> |
| 59 | + /// <para> |
| 60 | + /// Called by DatabricksStatement when a statement completes, or by other driver |
| 61 | + /// components that generate telemetry events. |
| 62 | + /// </para> |
| 63 | + /// <para> |
| 64 | + /// This method never throws exceptions. If the client is closed or disposing, |
| 65 | + /// the event is silently dropped. |
| 66 | + /// </para> |
| 67 | + /// </remarks> |
| 68 | + void Enqueue(TelemetryFrontendLog log); |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// Force flush all pending events immediately. |
| 72 | + /// </summary> |
| 73 | + /// <param name="ct">Cancellation token to cancel the flush operation.</param> |
| 74 | + /// <returns>A task that completes when all pending events have been flushed.</returns> |
| 75 | + /// <remarks> |
| 76 | + /// <para> |
| 77 | + /// This method blocks until all queued events are exported to the backend service. |
| 78 | + /// It is called when a connection closes to ensure no events are lost. |
| 79 | + /// </para> |
| 80 | + /// <para> |
| 81 | + /// If a flush is already in progress, this method waits for it to complete rather |
| 82 | + /// than starting a new flush operation. |
| 83 | + /// </para> |
| 84 | + /// <para> |
| 85 | + /// This method never throws exceptions related to telemetry failures. Export errors |
| 86 | + /// are caught and logged internally to ensure telemetry operations never impact |
| 87 | + /// driver functionality. |
| 88 | + /// </para> |
| 89 | + /// </remarks> |
| 90 | + Task FlushAsync(CancellationToken ct = default); |
| 91 | + |
| 92 | + /// <summary> |
| 93 | + /// Gracefully close the client. Flushes all pending events before disposing resources. |
| 94 | + /// </summary> |
| 95 | + /// <returns>A task that completes when the client is fully closed.</returns> |
| 96 | + /// <remarks> |
| 97 | + /// <para> |
| 98 | + /// This method is called by TelemetryClientManager when the reference count for this |
| 99 | + /// host reaches zero (i.e., the last connection to this host has been closed). |
| 100 | + /// </para> |
| 101 | + /// <para> |
| 102 | + /// The close operation performs the following steps: |
| 103 | + /// 1. Cancel any pending background flush timers |
| 104 | + /// 2. Flush all remaining queued events |
| 105 | + /// 3. Dispose internal resources (timers, semaphores, etc.) |
| 106 | + /// </para> |
| 107 | + /// <para> |
| 108 | + /// This method is idempotent - calling it multiple times is safe and has no effect |
| 109 | + /// after the first call completes. |
| 110 | + /// </para> |
| 111 | + /// <para> |
| 112 | + /// This method never throws exceptions. All errors during close are caught and |
| 113 | + /// logged internally. |
| 114 | + /// </para> |
| 115 | + /// </remarks> |
| 116 | + Task CloseAsync(); |
27 | 117 | } |
28 | 118 |
|
29 | 119 | /// <summary> |
|
0 commit comments