@@ -14,17 +14,19 @@ import (
1414 "sync/atomic"
1515 "time"
1616
17- "cloud.google.com/go/storage"
17+ gcs "cloud.google.com/go/storage"
1818 "github.com/prometheus/client_golang/prometheus/promhttp"
1919
20- "github.com/m-lab/go/bqx"
2120 "github.com/m-lab/go/prometheusx"
2221 "github.com/m-lab/go/rtx"
2322
2423 "github.com/m-lab/etl/active"
2524 "github.com/m-lab/etl/bq"
2625 "github.com/m-lab/etl/etl"
26+ "github.com/m-lab/etl/factory"
2727 "github.com/m-lab/etl/metrics"
28+ "github.com/m-lab/etl/storage"
29+ "github.com/m-lab/etl/task"
2830 "github.com/m-lab/etl/worker"
2931
3032 // Enable profiling. For more background and usage information, see:
@@ -121,7 +123,7 @@ func handleRequest(rwr http.ResponseWriter, rq *http.Request) {
121123
122124 // Throttle by grabbing a semaphore from channel.
123125 if shouldThrottle () {
124- metrics .TaskCount .WithLabelValues ("unknown" , "worker" , " TooManyRequests" ).Inc ()
126+ metrics .TaskCount .WithLabelValues ("unknown" , "TooManyRequests" ).Inc ()
125127 rwr .WriteHeader (http .StatusTooManyRequests )
126128 fmt .Fprintf (rwr , `{"message": "Too many tasks."}` )
127129 return
@@ -177,7 +179,7 @@ func subworker(rawFileName string, executionCount, retryCount int, age time.Dura
177179 // This handles base64 encoding, and requires a gs:// prefix.
178180 fn , err := etl .GetFilename (rawFileName )
179181 if err != nil {
180- metrics .TaskCount .WithLabelValues ("unknown" , "worker" , " BadRequest" ).Inc ()
182+ metrics .TaskCount .WithLabelValues ("unknown" , "BadRequest" ).Inc ()
181183 log .Printf ("Invalid filename: %s\n " , fn )
182184 return http .StatusBadRequest , `{"message": "Invalid filename."}`
183185 }
@@ -217,36 +219,28 @@ func setMaxInFlight() {
217219}
218220
219221type runnable struct {
220- storage.ObjectAttrs
222+ tf task.Factory
223+ gcs.ObjectAttrs
221224}
222225
223226func (r * runnable ) Run () error {
224227 path := fmt .Sprintf ("gs://%s/%s" , r .Bucket , r .Name )
225- data , err := etl .ValidateTestPath (path )
228+ dp , err := etl .ValidateTestPath (path )
226229 if err != nil {
227230 log .Printf ("Invalid filename: %v\n " , err )
228231 return err
229232 }
230233
231- // TODO This is short term hack to fix the injection bug.
232- // It will be removed in the third PR that introduces Factories
233- dataType := data .GetDataType ()
234- pdt := bqx.PDT {Project : dataType .BigqueryProject (), Dataset : dataType .Dataset (), Table : dataType .Table ()}
235- client , err := bq .GetClient (pdt .Project )
236- if err != nil {
237- return err
238- }
239- up := client .Dataset (pdt .Dataset ).Table (pdt .Table ).Uploader ()
240- // This avoids problems when a single row of the insert has invalid
241- // data. We then have to carefully parse the returned error object.
242- up .SkipInvalidRows = true
243-
244234 start := time .Now ()
245235 log .Println ("Processing" , path )
246- // TODO pass in storage client, or pass in TestSource.
247- statusCode , err := worker .ProcessGKETask (path , up , nil ) // Use default uploader and annotator
236+
237+ statusCode := http .StatusOK
238+ pErr := worker .ProcessGKETask (dp , r .tf )
239+ if pErr != nil {
240+ statusCode = pErr .Code ()
241+ }
248242 metrics .DurationHistogram .WithLabelValues (
249- data .DataType , http .StatusText (statusCode )).Observe (
243+ dp .DataType , http .StatusText (statusCode )).Observe (
250244 time .Since (start ).Seconds ())
251245 return err
252246}
@@ -256,8 +250,17 @@ func (r *runnable) Info() string {
256250 return r .Name
257251}
258252
259- func toRunnable (obj * storage.ObjectAttrs ) active.Runnable {
260- return & runnable {* obj }
253+ func toRunnable (obj * gcs.ObjectAttrs ) active.Runnable {
254+ c , err := storage .GetStorageClient (false )
255+ if err != nil {
256+ return nil // TODO add an error?
257+ }
258+ taskFactory := worker.StandardTaskFactory {
259+ Annotator : factory .DefaultAnnotatorFactory (),
260+ Sink : bq .NewSinkFactory (),
261+ Source : storage .GCSSourceFactory (c ),
262+ }
263+ return & runnable {& taskFactory , * obj }
261264}
262265
263266func mustGardenerAPI (ctx context.Context , jobServer string ) * active.GardenerAPI {
0 commit comments