common

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CalleeNamespace SystemMetricName.
	CalleeNamespace = "callee_namespace"
	CalleeService   = "callee_service"
	CalleeSubset    = "callee_subset"
	CalleeInstance  = "callee_instance"
	CalleeRetCode   = "callee_result_code"
	CalleeMethod    = "callee_method"
	CalleeResult    = "callee_result"
	CalleeLabels    = "callee_labels"
	CallerNamespace = "caller_namespace"
	CallerService   = "caller_service"
	CallerIP        = "caller_ip"
	CallerLabels    = "caller_labels"
	MetricNameLabel = "metric_name"
	RuleName        = "rule_name"

	// MetricsNameUpstreamRequestTotal 与路由、请求相关的指标信息.
	MetricsNameUpstreamRequestTotal      = "upstream_rq_total"
	MetricsNameUpstreamRequestSuccess    = "upstream_rq_success"
	MetricsNameUpstreamRequestTimeout    = "upstream_rq_timeout"
	MetricsNameUpstreamRequestMaxTimeout = "upstream_rq_max_timeout"
	MetricsNameUpstreamRequestDelay      = "upstream_rq_delay"

	// 限流相关指标信息.
	MetricsNameRateLimitRequestTotal = "ratelimit_rq_total"
	MetricsNameRateLimitRequestPass  = "ratelimit_rq_pass"
	MetricsNameRateLimitRequestLimit = "ratelimit_rq_limit"

	// 熔断相关指标信息.
	MetricsNameCircuitBreakerOpen     = "circuitbreaker_open"
	MetricsNameCircuitBreakerHalfOpen = "circuitbreaker_halfopen"

	// SystemMetricValue.
	NilValue = "__NULL__"
)
View Source
const (
	RevisionMaxScope = 2
)

Variables

View Source
var (
	// InstanceGaugeLabelOrder 实例监控指标的label顺序
	InstanceGaugeLabelOrder map[string]LabelValueSupplier = map[string]LabelValueSupplier{

		CalleeNamespace: func(args interface{}) string {
			val := args.(*model.ServiceCallResult)
			return val.GetCalledInstance().GetNamespace()
		},
		CalleeService: func(args interface{}) string {
			val := args.(*model.ServiceCallResult)
			return val.GetCalledInstance().GetService()
		},
		CalleeSubset: func(args interface{}) string {
			val := args.(*model.ServiceCallResult)
			return val.CalledInstance.GetLogicSet()
		},
		CalleeInstance: func(args interface{}) string {
			val := args.(*model.ServiceCallResult)
			return fmt.Sprintf("%s:%d", val.GetCalledInstance().GetHost(), val.GetCalledInstance().GetPort())
		},
		CalleeRetCode: func(args interface{}) string {
			val := args.(*model.ServiceCallResult)
			if val.GetRetCode() == nil {
				return NilValue
			}
			return fmt.Sprintf("%d", *val.GetRetCode())
		},
		CalleeMethod: func(args interface{}) string {
			val := args.(*model.ServiceCallResult)
			return val.GetMethod()
		},
		CalleeResult: func(args interface{}) string {
			val := args.(*model.ServiceCallResult)
			retStatus := string(val.GetRetStatus())
			if retStatus != "" {
				return retStatus
			}
			return NilValue
		},
		CalleeLabels: func(args interface{}) string {
			val := args.(*model.ServiceCallResult)
			fmt.Println("fwfwfwf")
			if len(val.GetCalledInstance().GetMetadata()) == 0 {
				return ""
			}
			fmt.Println("GetMetadata")
			labels := val.GetCalledInstance().GetMetadata()
			fmt.Println(labels)
			var ret []string
			for k, v := range labels {
				ret = append(ret, fmt.Sprintf("%s=%s", k, v))
			}
			sort.Strings(ret)
			fmt.Println(ret)
			return strings.Join(ret, "|")
		},

		CallerLabels: func(args interface{}) string {
			val := args.(*model.ServiceCallResult)
			if val.SourceService == nil || len(val.SourceService.Metadata) == 0 {
				return ""
			}
			labels := val.SourceService.Metadata
			var ret []string
			for k, v := range labels {
				ret = append(ret, fmt.Sprintf("%s=%s", k, v))
			}
			sort.Strings(ret)
			return strings.Join(ret, "|")
		},
		CallerNamespace: func(args interface{}) string {
			val := args.(*model.ServiceCallResult)
			namespace := val.GetCallerNamespace()
			if namespace != "" {
				return namespace
			}
			return NilValue
		},
		CallerService: func(args interface{}) string {
			val := args.(*model.ServiceCallResult)
			service := val.GetCallerService()
			if service != "" {
				return service
			}
			return NilValue
		},
		CallerIP: func(args interface{}) string {
			val := args.(*model.ServiceCallResult)
			return val.SourceService.Instance
		},
		RuleName: func(args interface{}) string {
			return NilValue
		},
	}

	RateLimitGaugeLabelOrder map[string]LabelValueSupplier = map[string]LabelValueSupplier{
		CalleeNamespace: func(args interface{}) string {
			val := args.(*model.RateLimitGauge)
			return val.GetNamespace()
		},
		CalleeService: func(args interface{}) string {
			val := args.(*model.RateLimitGauge)
			return val.GetService()
		},
		CalleeMethod: func(args interface{}) string {
			val := args.(*model.RateLimitGauge)
			return val.Method
		},
		CallerLabels: func(args interface{}) string {
			val := args.(*model.RateLimitGauge)
			return formatLabelsToStr(val.Arguments)
		},
		RuleName: func(args interface{}) string {
			val := args.(*model.RateLimitGauge)
			if val.RuleName != "" {
				return val.RuleName
			}
			return NilValue
		},
	}

	CircuitBreakerGaugeLabelOrder map[string]LabelValueSupplier = map[string]LabelValueSupplier{
		CalleeNamespace: func(args interface{}) string {
			val := args.(*model.CircuitBreakGauge)
			return val.GetCalledInstance().GetNamespace()
		},
		CalleeService: func(args interface{}) string {
			val := args.(*model.CircuitBreakGauge)
			return val.GetCalledInstance().GetService()
		},
		CalleeMethod: func(args interface{}) string {
			val := args.(*model.CircuitBreakGauge)
			return val.Method
		},
		CalleeSubset: func(args interface{}) string {
			val := args.(*model.CircuitBreakGauge)
			return val.GetCalledInstance().GetLogicSet()
		},
		CalleeInstance: func(args interface{}) string {
			val := args.(*model.CircuitBreakGauge)
			return fmt.Sprintf("%s:%d", val.GetCalledInstance().GetHost(), val.GetCalledInstance().GetPort())
		},
		CallerNamespace: func(args interface{}) string {
			val := args.(*model.CircuitBreakGauge)
			return val.GetNamespace()
		},
		CallerService: func(args interface{}) string {
			val := args.(*model.CircuitBreakGauge)
			return val.GetService()
		},
	}
)

Functions

func ConvertCircuitBreakGaugeToLabels

func ConvertCircuitBreakGaugeToLabels(val *model.CircuitBreakGauge) map[string]string

func ConvertInsGaugeToLabels

func ConvertInsGaugeToLabels(val *model.ServiceCallResult, bindIP string) map[string]string

func ConvertRateLimitGaugeToLabels

func ConvertRateLimitGaugeToLabels(val *model.RateLimitGauge) map[string]string

func Fnv32

func Fnv32(key string) int64

func NewAvgStatMetricWithSignature

func NewAvgStatMetricWithSignature(metricName string, labels map[string]string, signature int64) *avgStatMetric

func NewStatMetricWithSignature

func NewStatMetricWithSignature(metricName string, labels map[string]string, signature int64) *statMetric

func PutDataFromContainerInOrder

func PutDataFromContainerInOrder(metricVecCaches map[string]*prometheus.GaugeVec, collector StatCollector,
	currentRevision int64)

Types

type AvgMetricValueAggregationStrategy

type AvgMetricValueAggregationStrategy interface {
	MetricValueAggregationStrategy
	NeedAvg() bool
}

type CircuitBreakerHalfOpenStrategy

type CircuitBreakerHalfOpenStrategy struct {
}

func (*CircuitBreakerHalfOpenStrategy) GetStrategyDescription

func (us *CircuitBreakerHalfOpenStrategy) GetStrategyDescription() string

返回策略的描述信息

func (*CircuitBreakerHalfOpenStrategy) GetStrategyName

func (us *CircuitBreakerHalfOpenStrategy) GetStrategyName() string

返回策略名称,通常该名称用作metricName

func (*CircuitBreakerHalfOpenStrategy) InitMetricValue

func (us *CircuitBreakerHalfOpenStrategy) InitMetricValue(dataSource interface{}) float64

根据数据源的内容获取第一次创建metric的时候的初始值

func (*CircuitBreakerHalfOpenStrategy) UpdateMetricValue

func (us *CircuitBreakerHalfOpenStrategy) UpdateMetricValue(targetValue StatMetric, dataSource interface{})

根据metric自身的value值和聚合数据源T的值来更新metric的value

type CircuitBreakerOpenStrategy

type CircuitBreakerOpenStrategy struct {
}

func (*CircuitBreakerOpenStrategy) GetStrategyDescription

func (us *CircuitBreakerOpenStrategy) GetStrategyDescription() string

返回策略的描述信息

func (*CircuitBreakerOpenStrategy) GetStrategyName

func (us *CircuitBreakerOpenStrategy) GetStrategyName() string

返回策略名称,通常该名称用作metricName

func (*CircuitBreakerOpenStrategy) InitMetricValue

func (us *CircuitBreakerOpenStrategy) InitMetricValue(dataSource interface{}) float64

根据数据源的内容获取第一次创建metric的时候的初始值

func (*CircuitBreakerOpenStrategy) UpdateMetricValue

func (us *CircuitBreakerOpenStrategy) UpdateMetricValue(targetValue StatMetric, dataSource interface{})

根据metric自身的value值和聚合数据源T的值来更新metric的value

type LabelValueSupplier

type LabelValueSupplier func(val interface{}) string

type MarkedContainer

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

func (*MarkedContainer) DelValue

func (mc *MarkedContainer) DelValue(signature int64)

func (*MarkedContainer) GetValue

func (mc *MarkedContainer) GetValue(signature int64) StatMetric

func (*MarkedContainer) GetValues

func (mc *MarkedContainer) GetValues() []StatMetric

func (*MarkedContainer) PutValue

func (mc *MarkedContainer) PutValue(signature int64, info StatMetric)

type MarkedViewContainer

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

func NewMarkedViewContainer

func NewMarkedViewContainer() *MarkedViewContainer

type MetricValueAggregationStrategy

type MetricValueAggregationStrategy interface {
	// 返回策略的描述信息
	GetStrategyDescription() string
	// 返回策略名称,通常该名称用作metricName
	GetStrategyName() string
	// 根据数据源的内容获取第一次创建metric的时候的初始值
	InitMetricValue(dataSource interface{}) float64
	// 根据metric自身的value值和聚合数据源T的值来更新metric的value
	UpdateMetricValue(targetValue StatMetric, dataSource interface{})
}

type MetricsType

type MetricsType int

MetricsType 指标类型,对应 Prometheus 提供的 Collector 类型.

const (
	// TypeForCounterVec metric type.
	TypeForCounterVec MetricsType = iota
	TypeForGaugeVec
	TypeForGauge
	TypeForHistogramVec
	TypeForMaxGaugeVec
)

type RateLimitRequestLimitStrategy

type RateLimitRequestLimitStrategy struct {
}

func (*RateLimitRequestLimitStrategy) GetStrategyDescription

func (us *RateLimitRequestLimitStrategy) GetStrategyDescription() string

返回策略的描述信息

func (*RateLimitRequestLimitStrategy) GetStrategyName

func (us *RateLimitRequestLimitStrategy) GetStrategyName() string

返回策略名称,通常该名称用作metricName

func (*RateLimitRequestLimitStrategy) InitMetricValue

func (us *RateLimitRequestLimitStrategy) InitMetricValue(dataSource interface{}) float64

根据数据源的内容获取第一次创建metric的时候的初始值

func (*RateLimitRequestLimitStrategy) UpdateMetricValue

func (us *RateLimitRequestLimitStrategy) UpdateMetricValue(targetValue StatMetric, dataSource interface{})

根据metric自身的value值和聚合数据源T的值来更新metric的value

type RateLimitRequestPassStrategy

type RateLimitRequestPassStrategy struct {
}

func (*RateLimitRequestPassStrategy) GetStrategyDescription

func (us *RateLimitRequestPassStrategy) GetStrategyDescription() string

返回策略的描述信息

func (*RateLimitRequestPassStrategy) GetStrategyName

func (us *RateLimitRequestPassStrategy) GetStrategyName() string

返回策略名称,通常该名称用作metricName

func (*RateLimitRequestPassStrategy) InitMetricValue

func (us *RateLimitRequestPassStrategy) InitMetricValue(dataSource interface{}) float64

根据数据源的内容获取第一次创建metric的时候的初始值

func (*RateLimitRequestPassStrategy) UpdateMetricValue

func (us *RateLimitRequestPassStrategy) UpdateMetricValue(targetValue StatMetric, dataSource interface{})

根据metric自身的value值和聚合数据源T的值来更新metric的value

type RateLimitRequestTotalStrategy

type RateLimitRequestTotalStrategy struct {
}

func (*RateLimitRequestTotalStrategy) GetStrategyDescription

func (us *RateLimitRequestTotalStrategy) GetStrategyDescription() string

返回策略的描述信息

func (*RateLimitRequestTotalStrategy) GetStrategyName

func (us *RateLimitRequestTotalStrategy) GetStrategyName() string

返回策略名称,通常该名称用作metricName

func (*RateLimitRequestTotalStrategy) InitMetricValue

func (us *RateLimitRequestTotalStrategy) InitMetricValue(dataSource interface{}) float64

根据数据源的内容获取第一次创建metric的时候的初始值

func (*RateLimitRequestTotalStrategy) UpdateMetricValue

func (us *RateLimitRequestTotalStrategy) UpdateMetricValue(targetValue StatMetric, dataSource interface{})

根据metric自身的value值和聚合数据源T的值来更新metric的value

type StatCollector

type StatCollector interface {
	// CollectStatInfo
	CollectStatInfo(info interface{}, metricLabels map[string]string,
		strategies []MetricValueAggregationStrategy, order []string)
	// CollectValues
	CollectValues() []StatMetric
	// RemoveStatMetric
	RemoveStatMetric(signature int64)
}

type StatInfoCollector

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

func NewStatInfoCollector

func NewStatInfoCollector() *StatInfoCollector

func (*StatInfoCollector) CollectValues

func (sc *StatInfoCollector) CollectValues() []StatMetric

CollectValues

func (*StatInfoCollector) GetSignature

func (sc *StatInfoCollector) GetSignature(metricsName string, labels map[string]string, order []string) int64

func (*StatInfoCollector) RemoveStatMetric

func (sc *StatInfoCollector) RemoveStatMetric(signature int64)

RemoveStatMetric

type StatInfoRevisionCollector

type StatInfoRevisionCollector struct {
	*StatInfoCollector
	// contains filtered or unexported fields
}

func NewStatInfoRevisionCollector

func NewStatInfoRevisionCollector() *StatInfoRevisionCollector

func (*StatInfoRevisionCollector) CollectStatInfo

func (src *StatInfoRevisionCollector) CollectStatInfo(info interface{}, metricLabels map[string]string,
	strategies []MetricValueAggregationStrategy, order []string)

func (*StatInfoRevisionCollector) GetCurrentRevision

func (src *StatInfoRevisionCollector) GetCurrentRevision() int64

type StatInfoStatefulCollector

type StatInfoStatefulCollector struct {
	*StatInfoCollector
	// contains filtered or unexported fields
}

func NewStatInfoStatefulCollector

func NewStatInfoStatefulCollector() *StatInfoStatefulCollector

func (*StatInfoStatefulCollector) CollectStatInfo

func (src *StatInfoStatefulCollector) CollectStatInfo(info interface{}, metricLabels map[string]string,
	strategies []MetricValueAggregationStrategy, order []string)

type StatMetric

type StatMetric interface {
	MetricName() string
	Inc()
	GetValue() float64
	Add(v int64)
	Dec()
	Set(v int64)
	CompareAndSwap(oldV, newV int64) bool
	GetLabels() map[string]string
	GetSignature() int64
}

type StatRevisionMetric

type StatRevisionMetric struct {
	StatMetric
	Revision int64
}

func NewAvgStatRevisionMetric

func NewAvgStatRevisionMetric(metricName string, labels map[string]string,
	signature, revision int64) *StatRevisionMetric

func NewStatRevisionMetric

func NewStatRevisionMetric(metricName string, labels map[string]string,
	signature, revision int64) *StatRevisionMetric

func (*StatRevisionMetric) GetRevision

func (sm *StatRevisionMetric) GetRevision() int64

func (*StatRevisionMetric) UpdateRevision

func (sm *StatRevisionMetric) UpdateRevision(r int64)

type StatStatefulMetric

type StatStatefulMetric struct {
	MarkedViewContainer *MarkedViewContainer
	// contains filtered or unexported fields
}

func NewStatStatefulMetric

func NewStatStatefulMetric(metricName string, labels map[string]string, signature int64) *StatStatefulMetric

func NewStatStatefulMetricWithMarkedContainer

func NewStatStatefulMetricWithMarkedContainer(metricName string, labels map[string]string, markedContainer *MarkedViewContainer,
	signature int64) *StatStatefulMetric

func (StatStatefulMetric) Add

func (s StatStatefulMetric) Add(v int64)

func (StatStatefulMetric) CompareAndSwap

func (s StatStatefulMetric) CompareAndSwap(oldV, newV int64) bool

func (StatStatefulMetric) Dec

func (s StatStatefulMetric) Dec()

func (StatStatefulMetric) GetLabels

func (s StatStatefulMetric) GetLabels() map[string]string

func (StatStatefulMetric) GetSignature

func (s StatStatefulMetric) GetSignature() int64

func (StatStatefulMetric) GetValue

func (s StatStatefulMetric) GetValue() float64

func (StatStatefulMetric) Inc

func (s StatStatefulMetric) Inc()

func (StatStatefulMetric) MetricName

func (s StatStatefulMetric) MetricName() string

func (StatStatefulMetric) Set

func (s StatStatefulMetric) Set(v int64)

type UpstreamRequestMaxTimeoutStrategy

type UpstreamRequestMaxTimeoutStrategy struct {
}

func (*UpstreamRequestMaxTimeoutStrategy) GetStrategyDescription

func (us *UpstreamRequestMaxTimeoutStrategy) GetStrategyDescription() string

返回策略的描述信息

func (*UpstreamRequestMaxTimeoutStrategy) GetStrategyName

func (us *UpstreamRequestMaxTimeoutStrategy) GetStrategyName() string

返回策略名称,通常该名称用作metricName

func (*UpstreamRequestMaxTimeoutStrategy) InitMetricValue

func (us *UpstreamRequestMaxTimeoutStrategy) InitMetricValue(dataSource interface{}) float64

根据数据源的内容获取第一次创建metric的时候的初始值

func (*UpstreamRequestMaxTimeoutStrategy) UpdateMetricValue

func (us *UpstreamRequestMaxTimeoutStrategy) UpdateMetricValue(targetValue StatMetric, dataSource interface{})

根据metric自身的value值和聚合数据源T的值来更新metric的value

type UpstreamRequestSuccessStrategy

type UpstreamRequestSuccessStrategy struct {
}

func (*UpstreamRequestSuccessStrategy) GetStrategyDescription

func (us *UpstreamRequestSuccessStrategy) GetStrategyDescription() string

返回策略的描述信息

func (*UpstreamRequestSuccessStrategy) GetStrategyName

func (us *UpstreamRequestSuccessStrategy) GetStrategyName() string

返回策略名称,通常该名称用作metricName

func (*UpstreamRequestSuccessStrategy) InitMetricValue

func (us *UpstreamRequestSuccessStrategy) InitMetricValue(dataSource interface{}) float64

根据数据源的内容获取第一次创建metric的时候的初始值

func (*UpstreamRequestSuccessStrategy) UpdateMetricValue

func (us *UpstreamRequestSuccessStrategy) UpdateMetricValue(targetValue StatMetric, dataSource interface{})

根据metric自身的value值和聚合数据源T的值来更新metric的value

type UpstreamRequestTimeoutStrategy

type UpstreamRequestTimeoutStrategy struct {
}

func (*UpstreamRequestTimeoutStrategy) GetStrategyDescription

func (us *UpstreamRequestTimeoutStrategy) GetStrategyDescription() string

返回策略的描述信息

func (*UpstreamRequestTimeoutStrategy) GetStrategyName

func (us *UpstreamRequestTimeoutStrategy) GetStrategyName() string

返回策略名称,通常该名称用作metricName

func (*UpstreamRequestTimeoutStrategy) InitMetricValue

func (us *UpstreamRequestTimeoutStrategy) InitMetricValue(dataSource interface{}) float64

根据数据源的内容获取第一次创建metric的时候的初始值

func (*UpstreamRequestTimeoutStrategy) NeedAvg

func (us *UpstreamRequestTimeoutStrategy) NeedAvg() bool

func (*UpstreamRequestTimeoutStrategy) UpdateMetricValue

func (us *UpstreamRequestTimeoutStrategy) UpdateMetricValue(targetValue StatMetric, dataSource interface{})

根据metric自身的value值和聚合数据源T的值来更新metric的value

type UpstreamRequestTotalStrategy

type UpstreamRequestTotalStrategy struct {
}

func (*UpstreamRequestTotalStrategy) GetStrategyDescription

func (us *UpstreamRequestTotalStrategy) GetStrategyDescription() string

返回策略的描述信息

func (*UpstreamRequestTotalStrategy) GetStrategyName

func (us *UpstreamRequestTotalStrategy) GetStrategyName() string

返回策略名称,通常该名称用作metricName

func (*UpstreamRequestTotalStrategy) InitMetricValue

func (us *UpstreamRequestTotalStrategy) InitMetricValue(dataSource interface{}) float64

根据数据源的内容获取第一次创建metric的时候的初始值

func (*UpstreamRequestTotalStrategy) UpdateMetricValue

func (us *UpstreamRequestTotalStrategy) UpdateMetricValue(targetValue StatMetric, dataSource interface{})

根据metric自身的value值和聚合数据源T的值来更新metric的value

Jump to

Keyboard shortcuts

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