Documentation ¶
Overview ¶
Package spool contains the implementation of a worker that extracts the spool directory path from the agent config and enables other workers to write and read metrics to and from a the spool directory using a writer and a reader.
Index ¶
- Constants
- func APIMetricBatch(batch MetricBatch) params.MetricBatchParam
- func IsMetricsDataError(err error) bool
- func Manifold(config ManifoldConfig) dependency.Manifold
- func NewPeriodicWorker(do jworker.PeriodicWorkerCall, period time.Duration, ...) worker.Worker
- func NewSocketListener(socketPath string, handler ConnectionHandler) (*socketListener, error)
- type ConnectionHandler
- type JSONMetricReader
- type JSONMetricRecorder
- type ManifoldConfig
- type MetricBatch
- type MetricFactory
- type MetricMetadata
- type MetricReader
- type MetricRecorder
- type MetricRecorderConfig
Constants ¶
const ( // DefaultTimeout specifies the default socket read and write timeout. DefaultTimeout = 3 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func APIMetricBatch ¶
func APIMetricBatch(batch MetricBatch) params.MetricBatchParam
APIMetricBatch converts the specified MetricBatch to a params.MetricBatch, which can then be sent to the controller.
func IsMetricsDataError ¶
IsMetricsDataError returns true if the error cause is errMetricsData.
func Manifold ¶
func Manifold(config ManifoldConfig) dependency.Manifold
Manifold returns a dependency.Manifold that extracts the metrics spool directory path from the agent.
func NewPeriodicWorker ¶
func NewPeriodicWorker(do jworker.PeriodicWorkerCall, period time.Duration, newTimer func(time.Duration) jworker.PeriodicTimer, stop func()) worker.Worker
NewPeriodicWorker returns a periodic worker, that will call a stop function when it is killed.
func NewSocketListener ¶
func NewSocketListener(socketPath string, handler ConnectionHandler) (*socketListener, error)
NewSocketListener returns a new socket listener struct.
Types ¶
type ConnectionHandler ¶
ConnectionHandler defines the method needed to handle socket connections.
type JSONMetricReader ¶
type JSONMetricReader struct {
// contains filtered or unexported fields
}
JSONMetricsReader reads metrics batches stored in the spool directory.
func NewJSONMetricReader ¶
func NewJSONMetricReader(spoolDir string) (*JSONMetricReader, error)
NewJSONMetricsReader creates a new JSON metrics reader for the specified spool directory.
func (*JSONMetricReader) Close ¶
func (r *JSONMetricReader) Close() error
Close implements the MetricsReader interface.
func (*JSONMetricReader) Read ¶
func (r *JSONMetricReader) Read() (_ []MetricBatch, err error)
Read implements the MetricsReader interface. Due to the way the batches are stored in the file system, they will be returned in an arbitrary order. This does not affect the behavior.
func (*JSONMetricReader) Remove ¶
func (r *JSONMetricReader) Remove(uuid string) error
Remove implements the MetricsReader interface.
type JSONMetricRecorder ¶
type JSONMetricRecorder struct {
// contains filtered or unexported fields
}
JSONMetricRecorder implements the MetricsRecorder interface and writes metrics to a spool directory for store-and-forward.
func NewJSONMetricRecorder ¶
func NewJSONMetricRecorder(config MetricRecorderConfig) (rec *JSONMetricRecorder, rErr error)
NewJSONMetricRecorder creates a new JSON metrics recorder.
func (*JSONMetricRecorder) AddMetric ¶
func (m *JSONMetricRecorder) AddMetric( key, value string, created time.Time, labels map[string]string) (err error)
AddMetric implements the MetricsRecorder interface.
func (*JSONMetricRecorder) Close ¶
func (m *JSONMetricRecorder) Close() error
Close implements the MetricsRecorder interface.
func (*JSONMetricRecorder) IsDeclaredMetric ¶
func (m *JSONMetricRecorder) IsDeclaredMetric(key string) bool
IsDeclaredMetric returns true if the metric recorder is permitted to store this metric. Returns false if the uniter using this recorder doesn't define this metric.
type ManifoldConfig ¶
type ManifoldConfig engine.AgentManifoldConfig
ManifoldConfig specifies names a spooldirectory manifold should use to address its dependencies.
type MetricBatch ¶
type MetricBatch struct { CharmURL string `json:"charmurl"` UUID string `json:"uuid"` Created time.Time `json:"created"` Metrics []jujuc.Metric `json:"metrics"` UnitTag string `json:"unit-tag"` }
MetricBatch stores the information relevant to a single metrics batch.
type MetricFactory ¶
type MetricFactory interface { // Recorder returns a new MetricRecorder. Recorder(metrics map[string]corecharm.Metric, charmURL, unitTag string) (MetricRecorder, error) // Reader returns a new MetricReader. Reader() (MetricReader, error) }
MetricFactory contains the metrics reader and recorder factories.
type MetricMetadata ¶
type MetricMetadata struct { CharmURL string `json:"charmurl"` UUID string `json:"uuid"` Created time.Time `json:"created"` UnitTag string `json:"unit-tag"` }
MetricMetadata is used to store metadata for the current metric batch.
type MetricReader ¶
type MetricReader interface { // Read returns all metric batches stored in the spool directory. Read() ([]MetricBatch, error) // Remove removes the metric batch with the specified uuid // from the spool directory. Remove(uuid string) error // Close implements io.Closer. Close() error }
MetricReader reads metrics from a spool directory.
type MetricRecorder ¶
type MetricRecorder interface { // AddMetric records a metric with the specified key, value, create time // and labels to a spool directory. AddMetric(key, value string, created time.Time, labels map[string]string) error // Close implements io.Closer. Close() error // IsDeclaredMetrics returns true if the metric recorder // is permitted to store metrics with the specified key. IsDeclaredMetric(key string) bool }
MetricRecorder records metrics to a spool directory.