4
4
5
5
package io .airbyte .workers .general ;
6
6
7
+ import io .airbyte .config .Configs ;
7
8
import io .airbyte .config .FailureReason ;
8
9
import io .airbyte .config .ReplicationAttemptSummary ;
9
10
import io .airbyte .config .ReplicationOutput ;
14
15
import io .airbyte .config .SyncStats ;
15
16
import io .airbyte .config .WorkerDestinationConfig ;
16
17
import io .airbyte .config .WorkerSourceConfig ;
18
+ import io .airbyte .metrics .lib .DatadogClientConfiguration ;
19
+ import io .airbyte .metrics .lib .DogStatsDMetricSingleton ;
20
+ import io .airbyte .metrics .lib .MetricEmittingApps ;
21
+ import io .airbyte .metrics .lib .OssMetricsRegistry ;
17
22
import io .airbyte .protocol .models .AirbyteMessage ;
18
23
import io .airbyte .protocol .models .AirbyteRecordMessage ;
19
24
import io .airbyte .workers .*;
@@ -77,14 +82,16 @@ public class DefaultReplicationWorker implements ReplicationWorker {
77
82
private final AtomicBoolean cancelled ;
78
83
private final AtomicBoolean hasFailed ;
79
84
private final RecordSchemaValidator recordSchemaValidator ;
85
+ private final Configs configs ;
80
86
81
87
public DefaultReplicationWorker (final String jobId ,
82
88
final int attempt ,
83
89
final AirbyteSource source ,
84
90
final AirbyteMapper mapper ,
85
91
final AirbyteDestination destination ,
86
92
final MessageTracker messageTracker ,
87
- final RecordSchemaValidator recordSchemaValidator ) {
93
+ final RecordSchemaValidator recordSchemaValidator ,
94
+ final Configs configs ) {
88
95
this .jobId = jobId ;
89
96
this .attempt = attempt ;
90
97
this .source = source ;
@@ -93,11 +100,22 @@ public DefaultReplicationWorker(final String jobId,
93
100
this .messageTracker = messageTracker ;
94
101
this .executors = Executors .newFixedThreadPool (2 );
95
102
this .recordSchemaValidator = recordSchemaValidator ;
103
+ this .configs = configs ;
96
104
97
105
this .cancelled = new AtomicBoolean (false );
98
106
this .hasFailed = new AtomicBoolean (false );
99
107
}
100
108
109
+ public DefaultReplicationWorker (final String jobId ,
110
+ final int attempt ,
111
+ final AirbyteSource source ,
112
+ final AirbyteMapper mapper ,
113
+ final AirbyteDestination destination ,
114
+ final MessageTracker messageTracker ,
115
+ final RecordSchemaValidator recordSchemaValidator ) {
116
+ this (jobId , attempt , source , mapper , destination , messageTracker , recordSchemaValidator , null );
117
+ }
118
+
101
119
/**
102
120
* Run executes two threads. The first pipes data from STDOUT of the source to STDIN of the
103
121
* destination. The second listen on STDOUT of the destination. The goal of this second thread is to
@@ -111,7 +129,7 @@ public DefaultReplicationWorker(final String jobId,
111
129
* @throws WorkerException
112
130
*/
113
131
@ Override
114
- public ReplicationOutput run (final StandardSyncInput syncInput , final Path jobRoot ) throws WorkerException {
132
+ public final ReplicationOutput run (final StandardSyncInput syncInput , final Path jobRoot ) throws WorkerException {
115
133
LOGGER .info ("start sync worker. job id: {} attempt id: {}" , jobId , attempt );
116
134
117
135
// todo (cgardens) - this should not be happening in the worker. this is configuration information
@@ -153,7 +171,7 @@ public ReplicationOutput run(final StandardSyncInput syncInput, final Path jobRo
153
171
});
154
172
155
173
final CompletableFuture <?> replicationThreadFuture = CompletableFuture .runAsync (
156
- getReplicationRunnable (source , destination , cancelled , mapper , messageTracker , mdc , recordSchemaValidator ),
174
+ getReplicationRunnable (source , destination , cancelled , mapper , messageTracker , mdc , recordSchemaValidator , configs ),
157
175
executors ).whenComplete ((msg , ex ) -> {
158
176
if (ex != null ) {
159
177
if (ex .getCause () instanceof SourceException ) {
@@ -292,7 +310,8 @@ private static Runnable getReplicationRunnable(final AirbyteSource source,
292
310
final AirbyteMapper mapper ,
293
311
final MessageTracker messageTracker ,
294
312
final Map <String , String > mdc ,
295
- final RecordSchemaValidator recordSchemaValidator ) {
313
+ final RecordSchemaValidator recordSchemaValidator ,
314
+ final Configs configs ) {
296
315
return () -> {
297
316
MDC .setContextMap (mdc );
298
317
LOGGER .info ("Replication thread started." );
@@ -354,8 +373,15 @@ private static Runnable getReplicationRunnable(final AirbyteSource source,
354
373
}
355
374
LOGGER .info ("Total records read: {} ({})" , recordsRead , FileUtils .byteCountToDisplaySize (messageTracker .getTotalBytesEmitted ()));
356
375
if (!validationErrors .isEmpty ()) {
376
+ DogStatsDMetricSingleton .initialize (MetricEmittingApps .WORKER , new DatadogClientConfiguration (configs ));
357
377
validationErrors .forEach ((stream , errorPair ) -> {
358
378
LOGGER .warn ("Schema validation errors found for stream {}. Error messages: {}" , stream , errorPair .getLeft ());
379
+ final String [] validationErrorMetadata = {
380
+ "docker_repo:airbyte/test" , // dockerImage.split(":")[0]
381
+ "docker_version:0.0.0" , // dockerImage.split(":")[1]
382
+ "stream:" + stream
383
+ };
384
+ DogStatsDMetricSingleton .count (OssMetricsRegistry .NUM_RECORD_SCHEMA_VALIDATION_ERRORS , 1 , validationErrorMetadata );
359
385
});
360
386
}
361
387
0 commit comments