Rendering service - add optional RenderingSession (#44098)
* rendering service changes: - make node-renderer request timeout configurable - introduce optional RenderingSession providing a long-lived session key * remove console logs * added comment explaining empty "afterRequest" method * fix compilation error * update imports formatting * Update pkg/services/rendering/interface.go Co-authored-by: Agnès Toulet <35176601+AgnesToulet@users.noreply.github.com> * Update pkg/services/rendering/rendering.go Co-authored-by: Agnès Toulet <35176601+AgnesToulet@users.noreply.github.com> * review fix: extract renderKey related functions/structs to auth.go * #44449: private'd `rendering.getRequestTimeout` Co-authored-by: Agnès Toulet <35176601+AgnesToulet@users.noreply.github.com>
This commit is contained in:
co-authored by
Agnès Toulet
parent
3c334cd8ba
commit
5148250366
@@ -26,13 +26,30 @@ const (
|
||||
ThemeDark Theme = "dark"
|
||||
)
|
||||
|
||||
type TimeoutOpts struct {
|
||||
Timeout time.Duration // Timeout param passed to image-renderer service
|
||||
RequestTimeoutMultiplier time.Duration // RequestTimeoutMultiplier used for plugin/HTTP request context timeout
|
||||
}
|
||||
|
||||
type AuthOpts struct {
|
||||
OrgID int64
|
||||
UserID int64
|
||||
OrgRole models.RoleType
|
||||
}
|
||||
|
||||
func getRequestTimeout(opt TimeoutOpts) time.Duration {
|
||||
if opt.RequestTimeoutMultiplier == 0 {
|
||||
return opt.Timeout * 2 // default
|
||||
}
|
||||
|
||||
return opt.Timeout * opt.RequestTimeoutMultiplier
|
||||
}
|
||||
|
||||
type Opts struct {
|
||||
TimeoutOpts
|
||||
AuthOpts
|
||||
Width int
|
||||
Height int
|
||||
Timeout time.Duration
|
||||
OrgID int64
|
||||
UserID int64
|
||||
OrgRole models.RoleType
|
||||
Path string
|
||||
Encoding string
|
||||
Timezone string
|
||||
@@ -43,10 +60,8 @@ type Opts struct {
|
||||
}
|
||||
|
||||
type CSVOpts struct {
|
||||
Timeout time.Duration
|
||||
OrgID int64
|
||||
UserID int64
|
||||
OrgRole models.RoleType
|
||||
TimeoutOpts
|
||||
AuthOpts
|
||||
Path string
|
||||
Encoding string
|
||||
Timezone string
|
||||
@@ -66,11 +81,27 @@ type RenderCSVResult struct {
|
||||
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 renderKeyProvider interface {
|
||||
get(ctx context.Context, opts AuthOpts) (string, error)
|
||||
afterRequest(ctx context.Context, opts AuthOpts, renderKey string)
|
||||
}
|
||||
|
||||
type SessionOpts struct {
|
||||
Expiry time.Duration
|
||||
RefreshExpiryOnEachRequest bool
|
||||
}
|
||||
|
||||
type Session interface {
|
||||
renderKeyProvider
|
||||
Dispose(ctx context.Context)
|
||||
}
|
||||
|
||||
type Service interface {
|
||||
IsAvailable() bool
|
||||
Version() string
|
||||
Render(ctx context.Context, opts Opts) (*RenderResult, error)
|
||||
RenderCSV(ctx context.Context, opts CSVOpts) (*RenderCSVResult, error)
|
||||
Render(ctx context.Context, opts Opts, session Session) (*RenderResult, error)
|
||||
RenderCSV(ctx context.Context, opts CSVOpts, session Session) (*RenderCSVResult, error)
|
||||
RenderErrorImage(theme Theme, error error) (*RenderResult, error)
|
||||
GetRenderUser(ctx context.Context, key string) (*RenderUser, bool)
|
||||
CreateRenderingSession(ctx context.Context, authOpts AuthOpts, sessionOpts SessionOpts) (Session, error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user