instancemgmt

package
v0.283.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2025 License: Apache-2.0 Imports: 10 Imported by: 149

Documentation

Overview

Package instancemgmt provides utilities for managing plugin instances.

This package offers several instance manager implementations:

  1. Standard Instance Manager (New): Uses sync.Map for caching instances and disposes them when they need updates.

  2. TTL Instance Manager (NewTTLInstanceManager): Uses TTL-based caching that automatically evicts instances after a configurable time period.

  3. Instance Manager Wrapper (NewInstanceManagerWrapper): Dynamically selects between standard and TTL managers based on feature toggles from the Grafana config in the context.

The context-aware manager checks the "ttlPluginInstanceManager" feature toggle from the Grafana configuration and automatically uses the appropriate underlying implementation. This allows runtime switching without requiring plugin restarts or static configuration. Note: Both the standard and TTL instance managers maintain separate caches. If the feature toggle for TTL instance manager is changed at runtime, instances are not migrated between managers. This can result in duplicate instances for the same plugin context until the old ones are disposed or evicted.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CachedInstance

type CachedInstance struct {
	PluginContext backend.PluginContext
	// contains filtered or unexported fields
}

CachedInstance a cached Instance.

type Instance

type Instance interface{}

Instance is a marker interface for an instance.

type InstanceCallbackFunc

type InstanceCallbackFunc interface{}

InstanceCallbackFunc defines the callback function of the InstanceManager.Do method. The argument provided will of type Instance.

type InstanceDisposer

type InstanceDisposer interface {
	Dispose()
}

InstanceDisposer is implemented by an Instance that has a Dispose method, which defines that the instance is disposable.

InstanceManager will call the Dispose method before an Instance is replaced with a new Instance. This allows an Instance to clean up resources in use, if any.

type InstanceManager

type InstanceManager interface {
	// Get returns an Instance.
	//
	// If Instance is cached and not updated it's returned. If Instance is not cached or
	// updated, a new Instance is created and cached before returned.
	Get(ctx context.Context, pluginContext backend.PluginContext) (Instance, error)

	// Do provides an Instance as argument to fn.
	//
	// If Instance is cached and not updated provides as argument to fn. If Instance is not cached or
	// updated, a new Instance is created and cached before provided as argument to fn.
	Do(ctx context.Context, pluginContext backend.PluginContext, fn InstanceCallbackFunc) error
}

InstanceManager manages the lifecycle of instances.

func New

func New(provider InstanceProvider) InstanceManager

New create a new instance manager.

func NewInstanceManagerWrapper added in v0.282.0

func NewInstanceManagerWrapper(provider InstanceProvider) InstanceManager

NewInstanceManagerWrapper creates a new instance manager that dynamically selects between standard and TTL instance managers based on feature toggles from the Grafana config.

func NewTTLInstanceManager added in v0.282.0

func NewTTLInstanceManager(provider InstanceProvider) InstanceManager

NewTTLInstanceManager creates a new instance manager with TTL-based caching. Instances will be automatically evicted from the cache after the specified TTL.

type InstanceProvider

type InstanceProvider interface {
	// GetKey returns a cache key to be used for caching an Instance.
	GetKey(ctx context.Context, pluginContext backend.PluginContext) (interface{}, error)

	// NeedsUpdate returns whether a cached Instance have been updated.
	NeedsUpdate(ctx context.Context, pluginContext backend.PluginContext, cachedInstance CachedInstance) bool

	// NewInstance creates a new Instance.
	NewInstance(ctx context.Context, pluginContext backend.PluginContext) (Instance, error)
}

InstanceProvider defines an instance provider, providing instances.

Jump to

Keyboard shortcuts

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