plugins

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDestinationConfig

func CreateDestinationConfig(options ...DestinationOption) map[string]interface{}

CreateDestinationConfig creates a configuration map for a destination

Types

type Backend

type Backend interface {
	// Write writes a log entry to the backend
	Write(entry []byte) (int, error)

	// Flush ensures all buffered data is written
	Flush() error

	// Close closes the backend
	Close() error

	// SupportsAtomic returns whether the backend supports atomic writes
	SupportsAtomic() bool

	// Name returns the plugin name
	Name() string

	// Version returns the plugin version
	Version() string

	// Configure configures the plugin with options
	Configure(options map[string]interface{}) error
}

Backend interface for plugin-based log backends

type BackendFactory

type BackendFactory func(config map[string]interface{}) (Backend, error)

Factory interfaces for creating plugin instances

type BackendPlugin

type BackendPlugin interface {
	Plugin
	Backend

	// CreateBackend creates a new backend instance
	CreateBackend(uri string, config map[string]interface{}) (Backend, error)

	// SupportedSchemes returns URI schemes this plugin supports
	SupportedSchemes() []string
}

BackendPlugin interface for backend plugins

type DestinationOption

type DestinationOption func(map[string]interface{})

DestinationOption is a function that configures a destination

func WithBatchSize

func WithBatchSize(size int) DestinationOption

WithBatchSize sets the batch size for a destination

func WithCustomConfig

func WithCustomConfig(key string, value interface{}) DestinationOption

WithCustomConfig adds custom configuration to a destination

func WithFlushInterval

func WithFlushInterval(seconds int) DestinationOption

WithFlushInterval sets the flush interval for a destination

func WithRetryAttempts

func WithRetryAttempts(attempts int) DestinationOption

WithRetryAttempts sets the retry attempts for a destination

func WithTimeout

func WithTimeout(seconds int) DestinationOption

WithTimeout sets the timeout for a destination

type Discovery

type Discovery interface {
	// DiscoverPlugins discovers plugins in the specified paths
	DiscoverPlugins(paths []string) ([]PluginInfo, error)

	// LoadPlugin loads a plugin from a file
	LoadPlugin(path string) (Plugin, error)

	// ValidatePlugin validates a plugin before loading
	ValidatePlugin(path string) error
}

Discovery interface for plugin discovery

type DiscoveryImpl

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

DiscoveryImpl handles automatic plugin discovery and loading

func NewDiscovery

func NewDiscovery(manager *Manager) *DiscoveryImpl

NewDiscovery creates a new plugin discovery instance

func (*DiscoveryImpl) AddSearchPath

func (d *DiscoveryImpl) AddSearchPath(path string)

AddSearchPath adds a search path

func (*DiscoveryImpl) DiscoverPlugins

func (d *DiscoveryImpl) DiscoverPlugins() ([]string, error)

DiscoverPlugins discovers plugins in search paths

func (*DiscoveryImpl) LoadDiscoveredPlugins

func (d *DiscoveryImpl) LoadDiscoveredPlugins() error

LoadDiscoveredPlugins discovers and loads all plugins

func (*DiscoveryImpl) LoadPluginConfig

func (d *DiscoveryImpl) LoadPluginConfig(configPath string) error

LoadPluginConfig loads plugin specifications from a JSON file

func (*DiscoveryImpl) LoadPluginSpecs

func (d *DiscoveryImpl) LoadPluginSpecs(specs []PluginSpec) error

LoadPluginSpecs loads plugins from specifications

func (*DiscoveryImpl) SetPattern

func (d *DiscoveryImpl) SetPattern(pattern string)

SetPattern sets the file pattern for plugin files

func (*DiscoveryImpl) SetSearchPaths

func (d *DiscoveryImpl) SetSearchPaths(paths []string)

SetSearchPaths sets custom search paths

func (*DiscoveryImpl) WatchPluginDirectory

func (d *DiscoveryImpl) WatchPluginDirectory(dir string, interval time.Duration)

WatchPluginDirectory watches a directory for new plugins

type Filter

type Filter interface {
	// ShouldLog determines if a message should be logged
	ShouldLog(level int, message string, fields map[string]interface{}) bool

	// Name returns the filter name
	Name() string

	// Configure configures the filter with options
	Configure(options map[string]interface{}) error
}

Filter interface for plugin-based log filters

type FilterFactory

type FilterFactory func(config map[string]interface{}) (Filter, error)

type FilterPlugin

type FilterPlugin interface {
	Plugin
	Filter

	// CreateFilter creates a new filter instance
	CreateFilter(config map[string]interface{}) (types.FilterFunc, error)

	// FilterType returns the filter type name
	FilterType() string
}

FilterPlugin interface for filter plugins

type Formatter

type Formatter interface {
	// Format formats a log message
	Format(msg types.LogMessage) ([]byte, error)

	// Name returns the formatter name
	Name() string

	// Configure configures the formatter with options
	Configure(options map[string]interface{}) error
}

Formatter interface for plugin-based log formatters

type FormatterFactory

type FormatterFactory func(config map[string]interface{}) (Formatter, error)

type FormatterPlugin

type FormatterPlugin interface {
	Plugin
	Formatter

	// CreateFormatter creates a new formatter instance
	CreateFormatter(config map[string]interface{}) (Formatter, error)

	// FormatName returns the format name (e.g., "xml", "protobuf")
	FormatName() string
}

FormatterPlugin interface for formatter plugins

type HealthStatus

type HealthStatus struct {
	Healthy bool
	Message string
	Details map[string]interface{}
}

HealthStatus represents the health status of a plugin

type Integration

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

Integration provides helpers for integrating plugins with Omni

func NewIntegration

func NewIntegration(manager *Manager) *Integration

NewIntegration creates a new plugin integration helper

func (*Integration) CreateBackendFromURI

func (i *Integration) CreateBackendFromURI(uri string) (Backend, error)

CreateBackendFromURI creates a backend instance from a URI using plugins

func (*Integration) CreateFilterByType

func (i *Integration) CreateFilterByType(filterType string, config map[string]interface{}) (types.FilterFunc, error)

CreateFilterByType creates a filter instance by type using plugins

func (*Integration) CreateFormatterByName

func (i *Integration) CreateFormatterByName(name string, config map[string]interface{}) (Formatter, error)

CreateFormatterByName creates a formatter instance by name using plugins

func (*Integration) GetAvailableBackends

func (i *Integration) GetAvailableBackends() []string

GetAvailableBackends returns a list of available backend schemes

func (*Integration) GetAvailableFilters

func (i *Integration) GetAvailableFilters() []string

GetAvailableFilters returns a list of available filter types

func (*Integration) GetAvailableFormatters

func (i *Integration) GetAvailableFormatters() []string

GetAvailableFormatters returns a list of available formatter names

func (*Integration) GetCapabilities

func (i *Integration) GetCapabilities() PluginCapabilities

GetCapabilities returns the capabilities of all loaded plugins

func (*Integration) IsBackendSupported

func (i *Integration) IsBackendSupported(scheme string) bool

IsBackendSupported checks if a backend scheme is supported by any plugin

func (*Integration) IsFilterSupported

func (i *Integration) IsFilterSupported(filterType string) bool

IsFilterSupported checks if a filter type is supported by any plugin

func (*Integration) IsFormatterSupported

func (i *Integration) IsFormatterSupported(name string) bool

IsFormatterSupported checks if a formatter name is supported by any plugin

func (*Integration) ShutdownAll

func (i *Integration) ShutdownAll(ctx context.Context) error

ShutdownAll shuts down all loaded plugins

func (*Integration) ValidatePluginHealth

func (i *Integration) ValidatePluginHealth() error

ValidatePluginHealth performs health checks on all loaded plugins

type Manager

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

Manager manages loaded plugins

func NewManager

func NewManager() *Manager

NewManager creates a new plugin manager

func (*Manager) GetBackendPlugin

func (m *Manager) GetBackendPlugin(scheme string) (BackendPlugin, bool)

GetBackendPlugin returns a backend plugin for the given scheme

func (*Manager) GetFilterPlugin

func (m *Manager) GetFilterPlugin(filterType string) (FilterPlugin, bool)

GetFilterPlugin returns a filter plugin for the given type

func (*Manager) GetFormatterPlugin

func (m *Manager) GetFormatterPlugin(format string) (FormatterPlugin, bool)

GetFormatterPlugin returns a formatter plugin for the given format

func (*Manager) GetPluginInfo

func (m *Manager) GetPluginInfo() []PluginInfo

GetPluginInfo returns information about loaded plugins

func (*Manager) InitializePlugin

func (m *Manager) InitializePlugin(name string, config map[string]interface{}) error

InitializePlugin initializes a plugin with configuration

func (*Manager) ListPlugins

func (m *Manager) ListPlugins() []Plugin

ListPlugins returns all loaded plugins

func (*Manager) LoadPlugin

func (m *Manager) LoadPlugin(path string) error

LoadPlugin loads a plugin from a shared library file

func (*Manager) RegisterBackendPlugin

func (m *Manager) RegisterBackendPlugin(plugin BackendPlugin) error

RegisterBackendPlugin registers a backend plugin directly (for built-in plugins)

func (*Manager) RegisterFilterPlugin

func (m *Manager) RegisterFilterPlugin(plugin FilterPlugin) error

RegisterFilterPlugin registers a filter plugin directly

func (*Manager) RegisterFormatterPlugin

func (m *Manager) RegisterFormatterPlugin(plugin FormatterPlugin) error

RegisterFormatterPlugin registers a formatter plugin directly

func (*Manager) UnloadPlugin

func (m *Manager) UnloadPlugin(name string) error

UnloadPlugin unloads a plugin by name

type ManagerInterface

type ManagerInterface interface {
	// RegisterBackend registers a backend plugin
	RegisterBackend(name string, factory BackendFactory) error

	// RegisterFilter registers a filter plugin
	RegisterFilter(name string, factory FilterFactory) error

	// RegisterFormatter registers a formatter plugin
	RegisterFormatter(name string, factory FormatterFactory) error

	// GetBackend gets a backend plugin by name
	GetBackend(name string) (Backend, error)

	// GetFilter gets a filter plugin by name
	GetFilter(name string) (Filter, error)

	// GetFormatter gets a formatter plugin by name
	GetFormatter(name string) (Formatter, error)

	// ListPlugins returns a list of all registered plugins
	ListPlugins() []PluginInfo

	// LoadFromDirectory loads plugins from a directory
	LoadFromDirectory(dir string) error

	// UnloadPlugin unloads a plugin by name
	UnloadPlugin(name string) error
}

ManagerInterface manages plugin lifecycle and discovery

type Plugin

type Plugin interface {
	// Name returns the plugin name
	Name() string

	// Version returns the plugin version
	Version() string

	// Description returns a description of what the plugin does
	Description() string

	// Initialize initializes the plugin
	Initialize(config map[string]interface{}) error

	// Shutdown gracefully shuts down the plugin
	Shutdown(ctx context.Context) error

	// Health returns the health status of the plugin
	Health() HealthStatus
}

Plugin represents a general plugin

type PluginCapabilities

type PluginCapabilities struct {
	BackendSchemes []string `json:"backend_schemes"`
	FormatNames    []string `json:"format_names"`
	FilterTypes    []string `json:"filter_types"`
	PluginCount    int      `json:"plugin_count"`
}

PluginCapabilities represents the capabilities of loaded plugins

type PluginInfo

type PluginInfo struct {
	Name        string                 `json:"name"`
	Version     string                 `json:"version"`
	Type        string                 `json:"type"` // "backend", "filter", "formatter"
	Description string                 `json:"description"`
	Status      string                 `json:"status"` // "loaded", "unloaded", "error"
	Details     map[string]interface{} `json:"details,omitempty"`
}

PluginInfo contains information about a plugin

type PluginMetadata

type PluginMetadata struct {
	Name         string   `json:"name"`
	Version      string   `json:"version"`
	Description  string   `json:"description"`
	Author       string   `json:"author"`
	License      string   `json:"license"`
	Homepage     string   `json:"homepage"`
	Type         string   `json:"type"`                  // backend, formatter, filter
	Schemes      []string `json:"schemes,omitempty"`     // For backend plugins
	FormatName   string   `json:"format_name,omitempty"` // For formatter plugins
	FilterType   string   `json:"filter_type,omitempty"` // For filter plugins
	Dependencies []string `json:"dependencies,omitempty"`
}

PluginMetadata represents plugin metadata from a plugin.json file

func LoadPluginMetadata

func LoadPluginMetadata(metadataPath string) (*PluginMetadata, error)

LoadPluginMetadata loads plugin metadata from a JSON file

type PluginSpec

type PluginSpec struct {
	Name   string                 `json:"name"`
	Path   string                 `json:"path,omitempty"`
	URL    string                 `json:"url,omitempty"`
	Config map[string]interface{} `json:"config,omitempty"`
}

PluginSpec represents a plugin specification for automatic loading

Jump to

Keyboard shortcuts

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