middleware

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const PrometheusNamespace = "hystrix_go"

PrometheusNamespace namespace for hystrix metrics

Variables

View Source
var DefaultCBConfig = hystrix.CommandConfig{
	Timeout:                5000,
	MaxConcurrentRequests:  500,
	ErrorPercentThreshold:  50,
	SleepWindow:            5000,
	RequestVolumeThreshold: 20,
}

DefaultCBConfig provides default circuitbreak setting

Functions

func CircuitBreaker

func CircuitBreaker(commandName string, commandCfg hystrix.CommandConfig) endpoint.Middleware

CircuitBreaker provides hystrix circuitbreaker for HTTP calls.

func Cleanup

func Cleanup() endpoint.Middleware

Cleanup is a middleware guarding the call and doing some cleanup

func CleanupEndpoint

func CleanupEndpoint(key string)

CleanupEndpoint cleans up endpoint info by given key(format: <addr>-<uri>-<method>)

func InitMetrics

func InitMetrics()

InitMetrics inits prometheus setting and starts server on given port

func IsCircuitOpen

func IsCircuitOpen(key string) (open, ok bool)

IsCircuitOpen return whether circuit of given key(format: <addr>-<uri>-<method>) is open

func Metrics

func Metrics(src, tgt, uri, method string) endpoint.Middleware

Metrics returns a middleware to export metrics to prometheus

func Tracing

func Tracing(uri string) endpoint.Middleware

Tracing adds opentracing support for outgoing calls

Types

type PrometheusCollector

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

PrometheusCollector struct contains the metrics for prometheus. The handling of the values is completely done by the prometheus client library. The function `Collector` can be registered to the metricsCollector.Registry. If one want to use a custom registry it can be given via the reg parameter. If reg is nil, the prometheus default registry is used. The RunDuration is observed via a prometheus histogram ( https://prometheus.io/docs/concepts/metric_types/#histogram ). If the duration_buckets slice is nil, the "github.com/prometheus/client_golang/prometheus".DefBuckets are used. As stated by the prometheus documentation, one should tailor the buckets to the response times of your application.

Example use

package main

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

func main() {
	pc := plugins.NewPrometheusCollector(nil, nil)
	metricCollector.Registry.Register(pc.Collector)
}

func NewPrometheusCollector

func NewPrometheusCollector(reg prometheus.Registerer, durationBuckets []float64) PrometheusCollector

NewPrometheusCollector creates collector

func (*PrometheusCollector) Collector

Collector returns collector for a given command

Jump to

Keyboard shortcuts

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