Rendering: add CSV support (#33729)

* Rendering: add CSV rendering support

* Rendering: save csv files into a separate folder

* add missing field

* Renderer: get filename from renderer plugin

* apply PR suggestions

* Rendering: remove old PhantomJS error

* Rendering: separate RenderCSV and Render functions

* fix alerting test

* Rendering: fix handling error in HTTP mode

* apply PR feedback

* Update pkg/services/rendering/http_mode.go

Co-authored-by: Joan López de la Franca Beltran <joanjan14@gmail.com>

* apply PR feedback

* Update rendering metrics with type label

* Rendering: return error if not able to parse header

* Rendering: update grpc generated file

* Rendering: use context.WithTimeout to render CSV too

Co-authored-by: Joan López de la Franca Beltran <joanjan14@gmail.com>
This commit is contained in:
Agnès Toulet
2021-05-12 17:16:57 +02:00
committed by GitHub
parent 81ad9769fa
commit ec71919e7b
12 changed files with 579 additions and 112 deletions

View File

@ -9,14 +9,22 @@ import (
)
var ErrTimeout = errors.New("timeout error - you can set timeout in seconds with &timeout url parameter")
var ErrPhantomJSNotInstalled = errors.New("PhantomJS executable not found")
var ErrConcurrentLimitReached = errors.New("rendering concurrent limit reached")
var ErrRenderUnavailable = errors.New("rendering plugin not available")
type RenderType string
const (
RenderCSV RenderType = "csv"
RenderPNG RenderType = "png"
)
type Opts struct {
Width int
Height int
Timeout time.Duration
OrgId int64
UserId int64
OrgID int64
UserID int64
OrgRole models.RoleType
Path string
Encoding string
@ -26,15 +34,34 @@ type Opts struct {
Headers map[string][]string
}
type CSVOpts struct {
Timeout time.Duration
OrgID int64
UserID int64
OrgRole models.RoleType
Path string
Encoding string
Timezone string
ConcurrentLimit int
Headers map[string][]string
}
type RenderResult struct {
FilePath string
}
type RenderCSVResult struct {
FilePath string
FileName string
}
type renderFunc func(ctx context.Context, renderKey string, options Opts) (*RenderResult, error)
type renderCSVFunc func(ctx context.Context, renderKey string, options CSVOpts) (*RenderCSVResult, error)
type Service interface {
IsAvailable() bool
Render(ctx context.Context, opts Opts) (*RenderResult, error)
RenderCSV(ctx context.Context, opts CSVOpts) (*RenderCSVResult, error)
RenderErrorImage(error error) (*RenderResult, error)
GetRenderUser(key string) (*RenderUser, bool)
}