Skip to content

Commit db2825c

Browse files
Validate monitor config values and send max changes configuration on startup (#467)
* Validate monitor config values and send max changes configuration on startup * Add enum values
1 parent 50ec58a commit db2825c

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/Telemetry/Telemetry.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ public enum TelemetryPropertyName
362362
ExceptionType,
363363
HasIdentityColumn,
364364
HasConfiguredBatchSize,
365+
HasConfiguredMaxChangesPerWorker,
365366
HasConfiguredPollingInterval,
366367
LeasesTableName,
367368
QueryType,
@@ -392,6 +393,7 @@ public enum TelemetryMeasureName
392393
GetPrimaryKeysDurationMs,
393394
GetUnprocessedChangesDurationMs,
394395
InsertGlobalStateTableRowDurationMs,
396+
MaxChangesPerWorker,
395397
PollingIntervalMs,
396398
ReleaseLeasesDurationMs,
397399
RetryAttemptNumber,

src/TriggerBinding/SqlTableChangeMonitor.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,26 @@ public SqlTableChangeMonitor(
130130
int? configuredBatchSize = configuration.GetValue<int?>(ConfigKey_SqlTrigger_BatchSize);
131131
int? configuredPollingInterval = configuration.GetValue<int?>(ConfigKey_SqlTrigger_PollingInterval);
132132
this._batchSize = configuredBatchSize ?? this._batchSize;
133+
if (this._batchSize <= 0)
134+
{
135+
throw new InvalidOperationException($"Invalid value for configuration setting '{ConfigKey_SqlTrigger_BatchSize}'. Ensure that the value is a positive integer.");
136+
}
133137
this._pollingIntervalInMs = configuredPollingInterval ?? this._pollingIntervalInMs;
134-
var monitorStartProps = new Dictionary<TelemetryPropertyName, string>(telemetryProps)
138+
if (this._pollingIntervalInMs <= 0)
135139
{
136-
{ TelemetryPropertyName.HasConfiguredBatchSize, (configuredBatchSize != null).ToString() },
137-
{ TelemetryPropertyName.HasConfiguredPollingInterval, (configuredPollingInterval != null).ToString() },
138-
};
140+
throw new InvalidOperationException($"Invalid value for configuration setting '{ConfigKey_SqlTrigger_PollingInterval}'. Ensure that the value is a positive integer.");
141+
}
139142
TelemetryInstance.TrackEvent(
140143
TelemetryEventName.TriggerMonitorStart,
141-
monitorStartProps,
144+
new Dictionary<TelemetryPropertyName, string>(telemetryProps) {
145+
{ TelemetryPropertyName.HasConfiguredBatchSize, (configuredBatchSize != null).ToString() },
146+
{ TelemetryPropertyName.HasConfiguredPollingInterval, (configuredPollingInterval != null).ToString() },
147+
},
142148
new Dictionary<TelemetryMeasureName, double>() {
143149
{ TelemetryMeasureName.BatchSize, this._batchSize },
144150
{ TelemetryMeasureName.PollingIntervalMs, this._pollingIntervalInMs }
145-
});
151+
}
152+
);
146153

147154
// Prep search-conditions that will be used besides WHERE clause to match table rows.
148155
this._rowMatchConditions = Enumerable.Range(0, this._batchSize)

src/TriggerBinding/SqlTriggerListener.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ internal sealed class SqlTriggerListener<T> : IListener, IScaleMonitor<SqlTrigge
4747

4848
private readonly IDictionary<TelemetryPropertyName, string> _telemetryProps = new Dictionary<TelemetryPropertyName, string>();
4949
private readonly int _maxChangesPerWorker;
50+
private readonly bool _hasConfiguredMaxChangesPerWorker = false;
5051

5152
private SqlTableChangeMonitor<T> _changeMonitor;
5253
private int _listenerState = ListenerNotStarted;
@@ -74,13 +75,13 @@ public SqlTriggerListener(string connectionString, string tableName, string user
7475
// Do not convert the scale-monitor ID to lower-case string since SQL table names can be case-sensitive
7576
// depending on the collation of the current database.
7677
this._scaleMonitorDescriptor = new ScaleMonitorDescriptor($"{userFunctionId}-SqlTrigger-{tableName}");
77-
7878
configuredMaxChangesPerWorker = configuration.GetValue<int?>(ConfigKey_SqlTrigger_MaxChangesPerWorker);
7979
this._maxChangesPerWorker = configuredMaxChangesPerWorker ?? DefaultMaxChangesPerWorker;
8080
if (this._maxChangesPerWorker <= 0)
8181
{
8282
throw new InvalidOperationException($"Invalid value for configuration setting '{ConfigKey_SqlTrigger_MaxChangesPerWorker}'. Ensure that the value is a positive integer.");
8383
}
84+
this._hasConfiguredMaxChangesPerWorker = configuredMaxChangesPerWorker != null;
8485
}
8586

8687
public void Cancel()
@@ -105,7 +106,15 @@ public async Task StartAsync(CancellationToken cancellationToken)
105106
}
106107

107108
this.InitializeTelemetryProps();
108-
TelemetryInstance.TrackEvent(TelemetryEventName.StartListenerStart, this._telemetryProps);
109+
TelemetryInstance.TrackEvent(
110+
TelemetryEventName.StartListenerStart,
111+
new Dictionary<TelemetryPropertyName, string>(this._telemetryProps) {
112+
{ TelemetryPropertyName.HasConfiguredMaxChangesPerWorker, this._hasConfiguredMaxChangesPerWorker.ToString() }
113+
},
114+
new Dictionary<TelemetryMeasureName, double>() {
115+
{ TelemetryMeasureName.MaxChangesPerWorker, this._maxChangesPerWorker }
116+
}
117+
);
109118

110119
try
111120
{

0 commit comments

Comments
 (0)