monitoring

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

README

Configuring Monitoring

Our packages export metrics, logs and traces depending on your configuration. To activate monitoring, set the monitoring.active flag to true.

Logs

Logs are written to the standard output using logrus.

Metrics

We support two ways of exposing metrics:

Prometheus

If you want to pull Prometheus metrics, set monitoring.exporter to prometheus. When using Prometheus, you should also set monitoring.metrics.port. Your metrics can then be pulled at {baseURL}:{port}/metrics.

Elastic APM

If you want to use Elastic APM, set monitoring.exporter to elastic.

All the Elastic APM configuration options should be passed as environment variables. Please see the Elastic APM documentation for reference.

The following configuration options are mandatory:

  • ELASTIC_APM_SERVICE_NAME
  • ELASTIC_APM_SERVER_URL
  • ELASTIC_APM_SECRET_TOKEN

We recommend setting the following configuration options too:

  • ELASTIC_APM_ENVIRONMENT (staging/production)
  • ELASTIC_APM_METRICS_INTERVAL if the default 30 seconds doesn't suit you

Traces

Distributed traces are only available when choosing the elastic exporter.

If you use distributed tracing, don't forget to set ELASTIC_APM_TRANSACTION_SAMPLE_RATE to less than 1.0 in production. Distributed tracing is expensive, if you have a lot of requests you can't afford to trace them all.

Documentation

Index

Constants

View Source
const (
	PrometheusExporter = "prometheus"
	ElasticExporter    = "elastic"
)

Available exporters.

View Source
const (
	Stratumn            = "stratumn"
	ErrorLabel          = "error"
	ErrorCodeLabel      = "error_code"
	ErrorComponentLabel = "error_component"
)

Metrics and labels available to all packages.

View Source
const (
	SpanTypeIncomingRequest = "app.request.incoming"
	SpanTypeOutgoingRequest = "app.request.outgoing"
	SpanTypeProcessing      = "app.processing"
)

Span types.

Variables

View Source
var (
	DefaultLatencyBuckets = []float64{0, 1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, 80, 100, 130, 160, 200, 250, 300, 400, 500, 650, 800, 1000, 2000, 5000, 10000, 20000, 50000, 100000}
)

Default buckets used by histograms.

View Source
var (
	ErrInvalidExporter = errors.New("exporter should be 'prometheus' or 'elastic'")
)

Errors used by the configuration module.

Functions

func Configure

func Configure(config *Config, serviceName string) (http.Handler, error)

Configure configures metrics and trace monitoring. If metrics need to be exposed on an http route ('/metrics'), this function returns an http.Handler. It returns nil otherwise.

func LogEntry added in v0.3.1

func LogEntry() *log.Entry

LogEntry creates a new log entry with some default fields set.

func NewFossilizerAdapter

func NewFossilizerAdapter(f fossilizer.Adapter, name string) fossilizer.Adapter

NewFossilizerAdapter decorates an existing fossilizer.

func RegisterFlags

func RegisterFlags()

RegisterFlags registers the command-line monitoring flags.

func SetSpanStatus added in v0.3.1

func SetSpanStatus(span *apm.Span, err error)

SetSpanStatus sets the status of the span depending on the error.

func SetSpanStatusAndEnd

func SetSpanStatusAndEnd(span *apm.Span, err error)

SetSpanStatusAndEnd sets the status of the span depending on the error and ends it. You should usually call:

defer func() {
    SetSpanStatusAndEnd(span, err)
}()

func SetVersion added in v0.3.1

func SetVersion(v, c string)

SetVersion sets the current code's version and commit.

func SpanLogEntry added in v0.3.1

func SpanLogEntry(span *apm.Span) *log.Entry

SpanLogEntry creates a new log entry with the transaction ID set. This makes it easier to correlate transactions/spans with logs.

func StartSpanIncomingRequest added in v0.3.1

func StartSpanIncomingRequest(ctx context.Context, name string) (*apm.Span, context.Context)

StartSpanIncomingRequest starts a new span for an incoming request and fills some common flags.

func StartSpanOutgoingRequest added in v0.3.1

func StartSpanOutgoingRequest(ctx context.Context, name string) (*apm.Span, context.Context)

StartSpanOutgoingRequest starts a new span for an outgoing request and fills some common flags.

func StartSpanProcessing added in v0.3.1

func StartSpanProcessing(ctx context.Context, name string) (*apm.Span, context.Context)

StartSpanProcessing starts a new span for an internal processing task and fills some common flags.

func TxLogEntry added in v0.3.1

func TxLogEntry(ctx context.Context) *log.Entry

TxLogEntry creates a new log entry with the transaction ID set. This makes it easier to correlate transactions/spans with logs.

func WrapKeyValueStore added in v0.3.1

func WrapKeyValueStore(s store.KeyValueStore, name string) store.KeyValueStore

WrapKeyValueStore wraps an existing key value store adapter to add monitoring.

func WrapStore added in v0.3.1

func WrapStore(s store.Adapter, name string) store.Adapter

WrapStore wraps an existing store adapter to add monitoring.

Types

type Config

type Config struct {
	// Set to true to monitor Stratumn components.
	Monitor bool

	// Port used to expose metrics.
	MetricsPort int

	// Exporter is the name of the metrics and traces exporter.
	Exporter string
}

Config contains options for monitoring.

func ConfigurationFromFlags

func ConfigurationFromFlags() *Config

ConfigurationFromFlags builds configuration from user-provided command-line flags.

type FossilizerAdapter

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

FossilizerAdapter is a decorator for the Fossilizer interface. It wraps a real Fossilizer implementation and adds instrumentation.

func (*FossilizerAdapter) AddFossilizerEventChan

func (a *FossilizerAdapter) AddFossilizerEventChan(c chan *fossilizer.Event)

AddFossilizerEventChan instruments the call and delegates to the underlying fossilizer.

func (*FossilizerAdapter) Fossilize

func (a *FossilizerAdapter) Fossilize(ctx context.Context, data []byte, meta []byte) (err error)

Fossilize instruments the call and delegates to the underlying fossilizer.

func (*FossilizerAdapter) GetInfo

func (a *FossilizerAdapter) GetInfo(ctx context.Context) (res interface{}, err error)

GetInfo instruments the call and delegates to the underlying fossilizer.

type KeyValueStoreAdapter

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

KeyValueStoreAdapter is a decorator for the store.KeyValueStore interface. It wraps a real store.KeyValueStore implementation and adds instrumentation.

func (*KeyValueStoreAdapter) DeleteValue

func (a *KeyValueStoreAdapter) DeleteValue(ctx context.Context, key []byte) (v []byte, err error)

DeleteValue instruments the call and delegates to the underlying store.

func (*KeyValueStoreAdapter) GetValue

func (a *KeyValueStoreAdapter) GetValue(ctx context.Context, key []byte) (v []byte, err error)

GetValue instruments the call and delegates to the underlying store.

func (*KeyValueStoreAdapter) SetValue

func (a *KeyValueStoreAdapter) SetValue(ctx context.Context, key []byte, value []byte) (err error)

SetValue instruments the call and delegates to the underlying store.

type StoreAdapter

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

StoreAdapter is a decorator for the store.Adapter interface. It wraps a real store.Adapter implementation and adds instrumentation.

func (*StoreAdapter) AddEvidence

func (a *StoreAdapter) AddEvidence(ctx context.Context, linkHash chainscript.LinkHash, evidence *chainscript.Evidence) (err error)

AddEvidence instruments the call and delegates to the underlying store.

func (*StoreAdapter) AddStoreEventChannel

func (a *StoreAdapter) AddStoreEventChannel(c chan *store.Event)

AddStoreEventChannel instruments the call and delegates to the underlying store.

func (a *StoreAdapter) CreateLink(ctx context.Context, link *chainscript.Link) (lh chainscript.LinkHash, err error)

CreateLink instruments the call and delegates to the underlying store.

func (*StoreAdapter) FindSegments

func (a *StoreAdapter) FindSegments(ctx context.Context, filter *store.SegmentFilter) (ss *types.PaginatedSegments, err error)

FindSegments instruments the call and delegates to the underlying store.

func (*StoreAdapter) GetEvidences

func (a *StoreAdapter) GetEvidences(ctx context.Context, linkHash chainscript.LinkHash) (e types.EvidenceSlice, err error)

GetEvidences instruments the call and delegates to the underlying store.

func (*StoreAdapter) GetInfo

func (a *StoreAdapter) GetInfo(ctx context.Context) (res interface{}, err error)

GetInfo instruments the call and delegates to the underlying store.

func (*StoreAdapter) GetMapIDs

func (a *StoreAdapter) GetMapIDs(ctx context.Context, filter *store.MapFilter) (mids []string, err error)

GetMapIDs instruments the call and delegates to the underlying store.

func (*StoreAdapter) GetSegment

func (a *StoreAdapter) GetSegment(ctx context.Context, linkHash chainscript.LinkHash) (s *chainscript.Segment, err error)

GetSegment instruments the call and delegates to the underlying store.

func (*StoreAdapter) NewBatch

func (a *StoreAdapter) NewBatch(ctx context.Context) (b store.Batch, err error)

NewBatch instruments the call and delegates to the underlying store.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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