store

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package store manages the configurations in the database.

Index

Constants

View Source
const (
	// Cluster scope collectors should only run on one node of the cluster.
	Cluster = Scope("cluster")
	// Node scope collectors run on all the nodes in the cluster.
	Node = Scope("node")
)
View Source
const (
	// Counter is a metric value which can only increase or reset.
	Counter = Kind("counter")
	// Gauge is a number which can either go up or down.
	Gauge = Kind("gauge")
)
View Source
const (
	// CRDBV2 is the format of the cockroach log.
	CRDBV2 = LogFormat("crdb-v2")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

type Collection struct {
	Enabled      bool             // Enabled is true if the metrics needs to be collected.
	Frequency    pgtype.Interval  // Frequency determines how often the metrics are collected.
	Labels       []string         // Labels provide dimensions to the metrics.
	LastModified pgtype.Timestamp // LastModified the last time the collection was updated in the database.
	MaxResult    int              // Maximun number of results to be retrieved from the database.
	Metrics      []Metric         // Metrics available in this collection
	Name         string           // Name of the collection
	Query        string           // Query is the SQL query used to retrieve the metric values.
	Scope        Scope            // Scope of the collection (global vs local)
}

Collection is a set of metrics that evaluated at the same time. This struct defines the configuration for the collection.

func (*Collection) String

func (c *Collection) String() string

String implements fmt.Stringer

type Histogram

type Histogram struct {
	Enabled      bool             // Enabled is true if the histograms needs to be translated.
	Name         string           // Name of the config rule
	Bins         int              // Bins is the number of linear bins with a logarithm bucket.
	Start        int              // Start is the minimun value in the histogram
	End          int              // End is the maximum value in the histogram
	Regex        string           // Regex to match for incoming histograms to be converted.
	LastModified pgtype.Timestamp // LastModified when the definition was updated.
}

Histogram stores the properties for a histogram definition. Matching histograms will be converted into linear log10 histograms.

type Kind

type Kind string

Kind is the type of the metric.

type LogFormat added in v0.3.0

type LogFormat string

LogFormat defines of the log.

type Memory added in v0.3.0

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

Memory stores the configuration in memory. Used for testing.

func (*Memory) DeleteCollection added in v0.3.0

func (m *Memory) DeleteCollection(_ context.Context, name string) error

DeleteCollection implements store.Store.

func (*Memory) DeleteHistogram added in v0.3.0

func (m *Memory) DeleteHistogram(_ context.Context, name string) error

DeleteHistogram implements store.Store.

func (*Memory) DeleteScan added in v0.3.0

func (m *Memory) DeleteScan(_ context.Context, name string) error

DeleteScan implements store.Store.

func (*Memory) Error added in v0.3.0

func (m *Memory) Error() error

Error returns the injected error

func (*Memory) GetCollection added in v0.3.0

func (m *Memory) GetCollection(_ context.Context, name string) (*Collection, error)

GetCollection implements store.Store.

func (*Memory) GetCollectionNames added in v0.3.0

func (m *Memory) GetCollectionNames(_ context.Context) ([]string, error)

GetCollectionNames implements store.Store.

func (*Memory) GetHistogram added in v0.3.0

func (m *Memory) GetHistogram(_ context.Context, name string) (*Histogram, error)

GetHistogram implements store.Store.

func (*Memory) GetHistogramNames added in v0.3.0

func (m *Memory) GetHistogramNames(_ context.Context) ([]string, error)

GetHistogramNames implements store.Store.

func (*Memory) GetMetrics added in v0.3.0

func (m *Memory) GetMetrics(ctx context.Context, name string) ([]Metric, error)

GetMetrics implements store.Store.

func (*Memory) GetScan added in v0.3.0

func (m *Memory) GetScan(_ context.Context, name string) (*Scan, error)

GetScan implements store.Store.

func (*Memory) GetScanNames added in v0.3.0

func (m *Memory) GetScanNames(_ context.Context) ([]string, error)

GetScanNames implements store.Store.

func (*Memory) GetScanPatterns added in v0.3.0

func (m *Memory) GetScanPatterns(ctx context.Context, name string) ([]Pattern, error)

GetScanPatterns implements store.Store.

func (*Memory) Init added in v0.3.0

func (m *Memory) Init(_ context.Context) error

Init implements store.Store.

func (*Memory) InjectError added in v0.3.0

func (m *Memory) InjectError(err error)

InjectError sets the error that will be returned on each subsequent call.

func (*Memory) IsMainNode added in v0.3.0

func (m *Memory) IsMainNode(_ context.Context, lastUpdated time.Time) (bool, error)

IsMainNode implements store.Store.

func (*Memory) PutCollection added in v0.3.0

func (m *Memory) PutCollection(_ context.Context, collection *Collection) error

PutCollection implements store.Store.

func (*Memory) PutHistogram added in v0.3.0

func (m *Memory) PutHistogram(_ context.Context, histogram *Histogram) error

PutHistogram implements store.Store.

func (*Memory) PutScan added in v0.3.0

func (m *Memory) PutScan(_ context.Context, scan *Scan) error

PutScan implements store.Store.

func (*Memory) SetMainNode added in v0.3.0

func (m *Memory) SetMainNode(main bool)

SetMainNode sets this store as the main node.

type Metric

type Metric struct {
	Name string // Name of the metric, which represents the property being measured.
	Kind Kind   // Kind is the type of the metric.
	Help string // Help to used to describe the metric.
}

A Metric represents a measurement for a specific property.

type Pattern added in v0.3.0

type Pattern struct {
	Help  string // Help to used to describe the pattern.
	Name  string // Name of the pattern, which represents the property being measured.
	Regex string // Kind is the type of the pattern.
}

A Pattern defines the regular expression to match to increase the pattern counter

type Scan added in v0.3.0

type Scan struct {
	Enabled      bool             // Enabled is true if the patterns needs to be collected.
	Format       LogFormat        // Format of the log.
	LastModified pgtype.Timestamp // LastModified the last time the log was updated in the database.
	Name         string           // Name of the log
	Path         string           // Location of the log file
	Patterns     []Pattern        // The patterns to look for
}

Scan defines the list of patterns that used to scan a log file. This struct defines the configuration for the log.

func (*Scan) String added in v0.3.0

func (c *Scan) String() string

String implements fmt.Stringer

type Scope

type Scope string

Scope of the collector.

type Store

type Store interface {
	// DeleteCollection deletes the collection with the given name from the store.
	DeleteCollection(ctx context.Context, name string) error
	// DeleteHistogram deletes the histogram with the given name from the store.
	DeleteHistogram(ctx context.Context, regex string) error
	// DeleteScan deletes the log target with the given name from the store.
	DeleteScan(ctx context.Context, name string) error
	// GetCollection returns the collection with the given name.
	GetCollection(ctx context.Context, name string) (*Collection, error)
	// GetCollectionNames returns the collection names present in the store.
	GetCollectionNames(ctx context.Context) ([]string, error)
	// GetHistogram returns the histogram with the given name.
	GetHistogram(ctx context.Context, name string) (*Histogram, error)
	// GetHistogramNames returns the histogram names present in the store.
	GetHistogramNames(ctx context.Context) ([]string, error)
	// GetMetrics returns the metrics associated to a collection.
	GetMetrics(ctx context.Context, name string) ([]Metric, error)
	// GetScan returns the log target with the given name.
	GetScan(ctx context.Context, name string) (*Scan, error)
	// GetScanNames returns the log target names present in the store.
	GetScanNames(ctx context.Context) ([]string, error)
	// GetScanPatterns returns the patterns associated to a log target.
	GetScanPatterns(ctx context.Context, name string) ([]Pattern, error)
	// Init initializes the schema in the database
	Init(ctx context.Context) error
	// IsMainNode returns true if the current node is the main node.
	// A main node is a node with max(id) in the cluster.
	IsMainNode(ctx context.Context, lastUpdated time.Time) (bool, error)
	// PutCollection adds a collection configuration to the database.
	PutCollection(ctx context.Context, collection *Collection) error
	// PutHistogram adds a histogram configuration to the database.
	PutHistogram(ctx context.Context, histogram *Histogram) error
	// PutScan adds a log target configuration to the database.
	PutScan(ctx context.Context, scan *Scan) error
}

Store provides the CRUD function to manage collection, histogram and scanner configurations.

func New

func New(conn database.Connection) Store

New create a store

Jump to

Keyboard shortcuts

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