mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 05:29:42 -06:00
a025109647
* add SQL migrations * dashboard previews from sql: poc * added todos * refactor: use the same enums where possible * use useEffect, always return json * added todo * refactor + delete files after use * refactor + fix manual thumbnail upload * refactor: move all interactions with sqlStore to thumbnail repo * refactor: remove file operations in thumb crawler/service * refactor: fix dashboard_thumbs sql store * refactor: extracted thumbnail fetching/updating to a hook * refactor: store thumbnails in redux store * refactor: store thumbnails in redux store * refactor: private'd repo methods * removed redux storage, saving images as blobs * allow for configurable rendering timeouts * added 1) query for dashboards with stale thumbnails, 2) command for marking thumbnails as stale * use sql-based queue in crawler * ui for marking thumbnails as stale * replaced `stale` boolean prop with `state` enum * introduce rendering session * compilation errors * fix crawler stop button * rename thumbnail state frozen to locked * #44449: fix merge conflicts * #44449: remove thumb methods from `Store` interface * #44449: clean filepath, defer file closing * #44449: fix rendering.Theme cyclic import * #44449: linting * #44449: linting * #44449: mutex'd crawlerStatus access * #44449: added integration tests for `sqlstore.dashboard_thumbs` * #44449: added comments to explain the `ThumbnailState` enum * #44449: use os.ReadFile rather then os.Open * #44449: always enable dashboardPreviews feature during integration tests * #44449: remove sleep time, adjust number of threads * #44449: review fix: add `orgId` to `DashboardThumbnailMeta` * #44449: review fix: automatic parsing of thumbnailState * #44449: lint fixes * #44449: review fix: prefer `WithDbSession` over `WithTransactionalDbSession` * #44449: review fix: add a comment explaining source of the filepath * #44449: review fix: added filepath validation * #44449: review fixes https://github.com/grafana/grafana/pull/45063/files @fzambia Co-authored-by: Ryan McKinley <ryantxu@gmail.com> Co-authored-by: Alexander Emelin <frvzmb@gmail.com>
107 lines
2.7 KiB
Go
107 lines
2.7 KiB
Go
package rendering
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
)
|
|
|
|
var ErrTimeout = errors.New("timeout error - you can set timeout in seconds with &timeout url parameter")
|
|
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 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
|
|
Path string
|
|
Encoding string
|
|
Timezone string
|
|
ConcurrentLimit int
|
|
DeviceScaleFactor float64
|
|
Headers map[string][]string
|
|
Theme models.Theme
|
|
}
|
|
|
|
type CSVOpts struct {
|
|
TimeoutOpts
|
|
AuthOpts
|
|
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 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 CapabilitySupportRequestResult struct {
|
|
IsSupported bool
|
|
SemverConstraint string
|
|
}
|
|
|
|
type Service interface {
|
|
IsAvailable() bool
|
|
Version() string
|
|
Render(ctx context.Context, opts Opts, session Session) (*RenderResult, error)
|
|
RenderCSV(ctx context.Context, opts CSVOpts, session Session) (*RenderCSVResult, error)
|
|
RenderErrorImage(theme models.Theme, error error) (*RenderResult, error)
|
|
GetRenderUser(ctx context.Context, key string) (*RenderUser, bool)
|
|
HasCapability(capability CapabilityName) (CapabilitySupportRequestResult, error)
|
|
CreateRenderingSession(ctx context.Context, authOpts AuthOpts, sessionOpts SessionOpts) (Session, error)
|
|
}
|