screenshot

package
v0.0.0-...-fb7f86c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2023 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package screenshot is a generated GoMock package.

Package screenshot is a generated GoMock package.

Package screenshot is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultHeight  = 500
	DefaultWidth   = 1000
	DefaultTheme   = models.ThemeDark
	DefaultTimeout = 15 * time.Second
)
View Source
var (
	ErrScreenshotsUnavailable = errors.New("screenshots unavailable")
)

Functions

This section is empty.

Types

type CacheService

type CacheService interface {
	// Get returns the screenshot for the options or false if a screenshot with these
	// options does not exist.
	Get(ctx context.Context, opts ScreenshotOptions) (*Screenshot, bool)
	// Set the screenshot for the options. If another screenshot exists with these
	// options then it will be replaced.
	Set(ctx context.Context, opts ScreenshotOptions, screenshot *Screenshot) error
}

CacheService caches screenshots.

func NewInmemCacheService

func NewInmemCacheService(expiration time.Duration, r prometheus.Registerer) CacheService

type HeadlessScreenshotService

type HeadlessScreenshotService struct {
	// contains filtered or unexported fields
}

HeadlessScreenshotService takes screenshots using a headless browser.

func (*HeadlessScreenshotService) Take

Take returns a screenshot of the panel. It returns an error if either the panel, or the dashboard that contains the panel, does not exist, or the screenshot could not be taken due to an error. It uses both the context and the timeout in ScreenshotOptions, however the same context is used for both database queries and the request to the rendering service, while the timeout in ScreenshotOptions is passed to the rendering service where it is used as a client timeout. It is not recommended to pass a context without a deadline and the context deadline should be at least as long as the timeout in ScreenshotOptions.

type InmemCacheService

type InmemCacheService struct {
	// contains filtered or unexported fields
}

InmemCacheService is an in-mem screenshot cache.

func (*InmemCacheService) Get

func (*InmemCacheService) Set

func (s *InmemCacheService) Set(_ context.Context, opts ScreenshotOptions, screenshot *Screenshot) error

type MockCacheService

type MockCacheService struct {
	// contains filtered or unexported fields
}

MockCacheService is a mock of CacheService interface.

func NewMockCacheService

func NewMockCacheService(ctrl *gomock.Controller) *MockCacheService

NewMockCacheService creates a new mock instance.

func (*MockCacheService) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockCacheService) Get

Get mocks base method.

func (*MockCacheService) Set

Set mocks base method.

type MockCacheServiceMockRecorder

type MockCacheServiceMockRecorder struct {
	// contains filtered or unexported fields
}

MockCacheServiceMockRecorder is the mock recorder for MockCacheService.

func (*MockCacheServiceMockRecorder) Get

func (mr *MockCacheServiceMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call

Get indicates an expected call of Get.

func (*MockCacheServiceMockRecorder) Set

func (mr *MockCacheServiceMockRecorder) Set(arg0, arg1, arg2 interface{}) *gomock.Call

Set indicates an expected call of Set.

type MockRateLimiter

type MockRateLimiter struct {
	// contains filtered or unexported fields
}

MockRateLimiter is a mock of RateLimiter interface.

func NewMockRateLimiter

func NewMockRateLimiter(ctrl *gomock.Controller) *MockRateLimiter

NewMockRateLimiter creates a new mock instance.

func (*MockRateLimiter) Do

func (m *MockRateLimiter) Do(arg0 context.Context, arg1 ScreenshotOptions, arg2 screenshotFunc) (*Screenshot, error)

Do mocks base method.

func (*MockRateLimiter) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

type MockRateLimiterMockRecorder

type MockRateLimiterMockRecorder struct {
	// contains filtered or unexported fields
}

MockRateLimiterMockRecorder is the mock recorder for MockRateLimiter.

func (*MockRateLimiterMockRecorder) Do

func (mr *MockRateLimiterMockRecorder) Do(arg0, arg1, arg2 interface{}) *gomock.Call

Do indicates an expected call of Do.

type MockScreenshotService

type MockScreenshotService struct {
	// contains filtered or unexported fields
}

MockScreenshotService is a mock of ScreenshotService interface.

func NewMockScreenshotService

func NewMockScreenshotService(ctrl *gomock.Controller) *MockScreenshotService

NewMockScreenshotService creates a new mock instance.

func (*MockScreenshotService) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockScreenshotService) Take

Take mocks base method.

type MockScreenshotServiceMockRecorder

type MockScreenshotServiceMockRecorder struct {
	// contains filtered or unexported fields
}

MockScreenshotServiceMockRecorder is the mock recorder for MockScreenshotService.

func (*MockScreenshotServiceMockRecorder) Take

func (mr *MockScreenshotServiceMockRecorder) Take(arg0, arg1 interface{}) *gomock.Call

Take indicates an expected call of Take.

type NoOpCacheService

type NoOpCacheService struct{}

func (*NoOpCacheService) Get

func (*NoOpCacheService) Set

type NoOpRateLimiter

type NoOpRateLimiter struct{}

NoOpRateLimiter is a no-op rate limiter that has no limits.

func (*NoOpRateLimiter) Do

func (b *NoOpRateLimiter) Do(ctx context.Context, opts ScreenshotOptions, fn screenshotFunc) (*Screenshot, error)

type NoOpScreenshotService

type NoOpScreenshotService struct{}

NoOpScreenshotService is a service that takes no-op screenshots.

func (*NoOpScreenshotService) Take

type RateLimiter

type RateLimiter interface {
	// Do restricts the rate at which screenshots can be taken in parallel via screenshotFunc.
	// It returns the result of screenshotFunc, or an error if either the context deadline
	// has been exceeded or the context has been canceled while waiting its turn to call
	// screenshotFunc.
	Do(ctx context.Context, opts ScreenshotOptions, fn screenshotFunc) (*Screenshot, error)
}

A rate limiter restricts the number of screenshots that can be taken in parallel.

func NewTokenRateLimiter

func NewTokenRateLimiter(n int64) RateLimiter

type Screenshot

type Screenshot struct {
	Path string
}

Screenshot represents a path to a screenshot on disk.

type ScreenshotOptions

type ScreenshotOptions struct {
	// OrgID, DashboardUID and PanelID are required.
	OrgID        int64
	DashboardUID string
	PanelID      int64

	// These are optional. From and To must both be set to take effect.
	// Width, Height, Theme and Timeout inherit their defaults from
	// DefaultWidth, DefaultHeight, DefaultTheme and DefaultTimeout.
	From    string
	To      string
	Width   int
	Height  int
	Theme   models.Theme
	Timeout time.Duration
}

ScreenshotOptions are the options for taking a screenshot.

func (ScreenshotOptions) Hash

func (s ScreenshotOptions) Hash() []byte

func (ScreenshotOptions) SetDefaults

func (s ScreenshotOptions) SetDefaults() ScreenshotOptions

SetDefaults sets default values for missing or invalid options.

type ScreenshotService

type ScreenshotService interface {
	Take(ctx context.Context, opts ScreenshotOptions) (*Screenshot, error)
}

ScreenshotService is an interface for taking screenshots.

type ScreenshotUnavailableService

type ScreenshotUnavailableService struct{}

ScreenshotUnavailableService is a service that returns ErrScreenshotsUnavailable.

func (*ScreenshotUnavailableService) Take

type TokenRateLimiter

type TokenRateLimiter struct {
	// contains filtered or unexported fields
}

TokenRateLimiter is a rate limiter that uses a token bucket of fixed size N.

func (*TokenRateLimiter) Do

func (s *TokenRateLimiter) Do(ctx context.Context, opts ScreenshotOptions, fn screenshotFunc) (*Screenshot, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL