@@ -279,19 +279,19 @@ func (s *BrowserService) Render(ctx context.Context, url string, printer Printer
279279// You may be thinking: what the hell are we doing? Why are we using a browser for this?
280280// The CSV endpoint just returns HTML. The actual query is done by the browser, and then a script _in the webpage_ downloads it as a CSV file.
281281// This SHOULD be replaced at some point, such that the Grafana server does all the work; this is just not acceptable behaviour...
282- func (s * BrowserService ) RenderCSV (ctx context.Context , url , renderKey , domain , acceptLanguage string ) ([]byte , error ) {
282+ func (s * BrowserService ) RenderCSV (ctx context.Context , url , renderKey , domain , acceptLanguage string ) ([]byte , string , error ) {
283283 tracer := tracer (ctx )
284284 ctx , span := tracer .Start (ctx , "BrowserService.RenderCSV" )
285285 defer span .End ()
286286 start := time .Now ()
287287
288288 if url == "" {
289- return nil , fmt .Errorf ("url must not be empty" )
289+ return nil , "" , fmt .Errorf ("url must not be empty" )
290290 }
291291
292292 allocatorOptions , err := s .createAllocatorOptions (s .cfg )
293293 if err != nil {
294- return nil , fmt .Errorf ("failed to create allocator options: %w" , err )
294+ return nil , "" , fmt .Errorf ("failed to create allocator options: %w" , err )
295295 }
296296 allocatorCtx , cancelAllocator := chromedp .NewExecAllocator (ctx , allocatorOptions ... )
297297 defer cancelAllocator ()
@@ -301,7 +301,7 @@ func (s *BrowserService) RenderCSV(ctx context.Context, url, renderKey, domain,
301301
302302 tmpDir , err := os .MkdirTemp ("" , "gir-csv-*" )
303303 if err != nil {
304- return nil , fmt .Errorf ("failed to create temporary directory: %w" , err )
304+ return nil , "" , fmt .Errorf ("failed to create temporary directory: %w" , err )
305305 }
306306 defer func () {
307307 if err := os .RemoveAll (tmpDir ); err != nil {
@@ -337,15 +337,15 @@ func (s *BrowserService) RenderCSV(ctx context.Context, url, renderKey, domain,
337337 MetricBrowserInstancesActive .Inc ()
338338 defer MetricBrowserInstancesActive .Dec ()
339339 if err := chromedp .Run (browserCtx , actions ... ); err != nil {
340- return nil , fmt .Errorf ("failed to run browser: %w" , err )
340+ return nil , "" , fmt .Errorf ("failed to run browser: %w" , err )
341341 }
342342 span .AddEvent ("actions completed" )
343343
344344 // Wait for the file to be downloaded.
345345 var entries []os.DirEntry
346346 for {
347347 if err := ctx .Err (); err != nil {
348- return nil , err
348+ return nil , "" , err
349349 }
350350
351351 entries , err = os .ReadDir (tmpDir )
@@ -355,7 +355,7 @@ func (s *BrowserService) RenderCSV(ctx context.Context, url, renderKey, domain,
355355
356356 select {
357357 case <- ctx .Done ():
358- return nil , ctx .Err ()
358+ return nil , "" , ctx .Err ()
359359 case <- time .After (100 * time .Millisecond ):
360360 // try again
361361 }
@@ -364,11 +364,11 @@ func (s *BrowserService) RenderCSV(ctx context.Context, url, renderKey, domain,
364364
365365 fileContents , err := os .ReadFile (filepath .Join (tmpDir , entries [0 ].Name ()))
366366 if err != nil {
367- return nil , fmt .Errorf ("failed to read temporary file: %w" , err )
367+ return nil , "" , fmt .Errorf ("failed to read temporary file: %w" , err )
368368 }
369369
370370 MetricBrowserRenderCSVDuration .Observe (time .Since (start ).Seconds ())
371- return fileContents , nil
371+ return fileContents , filepath . Base ( entries [ 0 ]. Name ()), nil
372372}
373373
374374func (s * BrowserService ) createAllocatorOptions (cfg config.BrowserConfig ) ([]chromedp.ExecAllocatorOption , error ) {
0 commit comments