plugins

package
v0.0.0-...-20e29d6 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Plugins allows users to operate on statistics recorded for each circuit operation. Plugins should be careful to be lightweight as they will be called frequently.

Index

Constants

View Source
const (
	// DM = Datadog Metric
	DM_CircuitOpen       = "hystrix.circuitOpen"
	DM_Attempts          = "hystrix.attempts"
	DM_Errors            = "hystrix.errors"
	DM_Successes         = "hystrix.successes"
	DM_Failures          = "hystrix.failures"
	DM_Rejects           = "hystrix.rejects"
	DM_ShortCircuits     = "hystrix.shortCircuits"
	DM_Timeouts          = "hystrix.timeouts"
	DM_FallbackSuccesses = "hystrix.fallbackSuccesses"
	DM_FallbackFailures  = "hystrix.fallbackFailures"
	DM_TotalDuration     = "hystrix.totalDuration"
	DM_RunDuration       = "hystrix.runDuration"
)

These metrics are constants because we're leveraging the Datadog tagging extension to statsd.

They only apply to the DatadogCollector and are only useful if providing your own implemenation of DatadogClient

View Source
const (
	// DM = OT Metric
	OT_CircuitOpen       = "hystrix.circuitOpen"
	OT_Attempts          = "hystrix.attempts"
	OT_Errors            = "hystrix.errors"
	OT_Successes         = "hystrix.successes"
	OT_Failures          = "hystrix.failures"
	OT_Rejects           = "hystrix.rejects"
	OT_ShortCircuits     = "hystrix.shortCircuits"
	OT_Timeouts          = "hystrix.timeouts"
	OT_FallbackSuccesses = "hystrix.fallbackSuccesses"
	OT_FallbackFailures  = "hystrix.fallbackFailures"
	OT_TotalDuration     = "hystrix.totalDuration"
	OT_RunDuration       = "hystrix.runDuration"
)

These metrics are constants because we're leveraging the RG tagging extension to statsd.

They only apply to the OtelCollector and are only useful if providing your own implementation of OtelClient

View Source
const (
	WANStatsdFlushBytes     = 512
	LANStatsdFlushBytes     = 1432
	GigabitStatsdFlushBytes = 8932
)

https://github.com/etsy/statsd/blob/master/docs/metric_types.md#multi-metric-packets

Variables

This section is empty.

Functions

func InitializeGraphiteCollector

func InitializeGraphiteCollector(config *GraphiteCollectorConfig)

InitializeGraphiteCollector creates the connection to the graphite server and should be called before any metrics are recorded.

func NewDatadogCollector

func NewDatadogCollector(addr, prefix string) (func(string) metricCollector.MetricCollector, error)

NewDatadogCollector creates a collector for a specific circuit with a "github.com/DataDog/datadog-go/statsd".(*Client).

addr is in the format "<host>:<port>" (e.g. "localhost:8125")

prefix may be an empty string

Example use

package main

import (
	"github.com/ruang-guru/hystrix-go/plugins"
	"github.com/ruang-guru/hystrix-go/hystrix/metric_collector"
)

func main() {
	collector, err := plugins.NewDatadogCollector("localhost:8125", "")
	if err != nil {
		panic(err)
	}
	metricCollector.Registry.Register(collector)
}

func NewDatadogCollectorWithClient

func NewDatadogCollectorWithClient(client DatadogClient) func(string) metricCollector.MetricCollector

NewDatadogCollectorWithClient accepts an interface which allows you to provide your own implementation of a statsd client, alter configuration on "github.com/DataDog/datadog-go/statsd".(*Client), provide additional tags per circuit-metric tuple, and add logging if you need it.

func NewGraphiteCollector

func NewGraphiteCollector(name string) metricCollector.MetricCollector

NewGraphiteCollector creates a collector for a specific circuit. The prefix given to this circuit will be {config.Prefix}.{circuit_name}.{metric}. Circuits with "/" in their names will have them replaced with ".".

func NewOtelCollector

func NewOtelCollector() (func(string) metricCollector.MetricCollector, error)

NewOtelCollector creates a collector for a specific circuit with a otel client

prefix may be an empty string

Example use

package main

import (
	"github.com/ruang-guru/hystrix-go/plugins"
	"github.com/ruang-guru/hystrix-go/hystrix/metric_collector"
)

func main() {
	collector, err := plugins.NewOtelCollector()
	if err != nil {
		panic(err)
	}
	metricCollector.Registry.Register(collector)
}

func NewOtelCollectorWithInstrument

func NewOtelCollectorWithInstrument(inst metric.Instrument) (func(string) metricCollector.MetricCollector, error)

Types

type DatadogClient

type DatadogClient interface {
	Count(name string, value int64, tags []string, rate float64) error
	Gauge(name string, value float64, tags []string, rate float64) error
	TimeInMilliseconds(name string, value float64, tags []string, rate float64) error
}

DatadogClient is the minimum interface needed by NewDatadogCollectorWithClient

type DatadogCollector

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

DatadogCollector fulfills the metricCollector interface allowing users to ship circuit stats to Datadog.

This Collector, by default, uses github.com/DataDog/datadog-go/statsd for transport. The main advantage of this over statsd is building graphs and multi-alert monitors around single metrics (constantized above) and adding tag dimensions. You can set up a single monitor to rule them all across services and geographies. Graphs become much simpler to setup by allowing you to create queries like the following

{
  "viz": "timeseries",
  "requests": [
    {
      "q": "max:hystrix.runDuration.95percentile{$region} by {hystrixcircuit}",
      "type": "line"
    }
  ]
}

As new circuits come online you get graphing and monitoring "for free".

func (*DatadogCollector) Reset

func (dc *DatadogCollector) Reset()

Reset is a noop operation in this collector.

func (*DatadogCollector) Update

func (dc *DatadogCollector) Update(r metricCollector.MetricResult)

type GraphiteCollector

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

GraphiteCollector fulfills the metricCollector interface allowing users to ship circuit stats to a graphite backend. To use users must call InitializeGraphiteCollector before circuits are started. Then register NewGraphiteCollector with metricCollector.Registry.Register(NewGraphiteCollector).

This Collector uses github.com/rcrowley/go-metrics for aggregation. See that repo for more details on how metrics are aggregated and expressed in graphite.

func (*GraphiteCollector) Reset

func (g *GraphiteCollector) Reset()

Reset is a noop operation in this collector.

func (*GraphiteCollector) Update

func (g *GraphiteCollector) Update(r metricCollector.MetricResult)

type GraphiteCollectorConfig

type GraphiteCollectorConfig struct {
	// GraphiteAddr is the tcp address of the graphite server
	GraphiteAddr *net.TCPAddr
	// Prefix is the prefix that will be prepended to all metrics sent from this collector.
	Prefix string
	// TickInterval spcifies the period that this collector will send metrics to the server.
	TickInterval time.Duration
}

GraphiteCollectorConfig provides configuration that the graphite client will need.

type OtelCollector

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

OtelCollector fulfills the metricCollector interface allowing users to ship circuit stats to Open Telemetery.

This Collector, by default, uses github.com/DataDog/datadog-go/statsd for transport. The main advantage of this over statsd is building graphs and multi-alert monitors around single metrics (constantized above) and adding tag dimensions. You can set up a single monitor to rule them all across services and geographies. Graphs become much simpler to setup by allowing you to create queries like the following

{
  "viz": "timeseries",
  "requests": [
    {
      "q": "max:hystrix.runDuration.95percentile{$region} by {hystrixcircuit}",
      "type": "line"
    }
  ]
}

As new circuits come online you get graphing and monitoring "for free".

func (*OtelCollector) Count

func (oc *OtelCollector) Count(name string, value int64, tags []string, rate float64) error

func (*OtelCollector) Gauge

func (oc *OtelCollector) Gauge(name string, value float64, tags []string, rate float64) error

func (*OtelCollector) Reset

func (oc *OtelCollector) Reset()

Reset is a noop operation in this collector.

func (*OtelCollector) TimeInMilliseconds

func (oc *OtelCollector) TimeInMilliseconds(name string, value float64, tags []string, rate float64) error

func (*OtelCollector) Update

func (oc *OtelCollector) Update(r metricCollector.MetricResult)

type OtelCounter

type OtelCounter interface {
	Add(ctx context.Context, value float64, labels ...metric.LabelKV) error
}

OtelClient is the minimum interface needed by NewOtelCollectorWithClient

type OtelUpDownCounter

type OtelUpDownCounter interface {
	Add(ctx context.Context, value float64, labels ...metric.LabelKV) error
}

type OtelValueRecorder

type OtelValueRecorder interface {
	Record(ctx context.Context, val float64, labels ...metric.LabelKV)
}

type StatsdCollector

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

StatsdCollector fulfills the metricCollector interface allowing users to ship circuit stats to a Statsd backend. To use users must call InitializeStatsdCollector before circuits are started. Then register NewStatsdCollector with metricCollector.Registry.Register(NewStatsdCollector).

This Collector uses https://github.com/cactus/go-statsd-client/ for transport.

func (*StatsdCollector) Reset

func (g *StatsdCollector) Reset()

Reset is a noop operation in this collector.

func (*StatsdCollector) Update

func (g *StatsdCollector) Update(r metricCollector.MetricResult)

type StatsdCollectorClient

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

func InitializeStatsdCollector

func InitializeStatsdCollector(config *StatsdCollectorConfig) (*StatsdCollectorClient, error)

InitializeStatsdCollector creates the connection to the Statsd server and should be called before any metrics are recorded.

Users should ensure to call Close() on the client.

func (*StatsdCollectorClient) NewStatsdCollector

func (s *StatsdCollectorClient) NewStatsdCollector(name string) metricCollector.MetricCollector

NewStatsdCollector creates a collector for a specific circuit. The prefix given to this circuit will be {config.Prefix}.{circuit_name}.{metric}. Circuits with "/" in their names will have them replaced with ".".

type StatsdCollectorConfig

type StatsdCollectorConfig struct {
	// StatsdAddr is the tcp address of the Statsd server
	StatsdAddr string
	// Prefix is the prefix that will be prepended to all metrics sent from this collector.
	Prefix string
	// StatsdSampleRate sets statsd sampling. If 0, defaults to 1.0. (no sampling)
	SampleRate float32
	// FlushBytes sets message size for statsd packets. If 0, defaults to LANFlushSize.
	FlushBytes int
}

StatsdCollectorConfig provides configuration that the Statsd client will need.

Jump to

Keyboard shortcuts

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