From a2e7b218143dade04e0704c24abc32eebdc01a08 Mon Sep 17 00:00:00 2001 From: cui fliter Date: Fri, 21 Apr 2023 16:24:22 +0800 Subject: [PATCH] fix some comments Signed-off-by: cui fliter --- api/api.go | 2 +- core/base/slot_chain.go | 2 +- core/circuitbreaker/circuit_breaker.go | 35 +++++++++---------- core/system_metric/sys_metric_stat.go | 2 +- ext/datasource/hotspot_rule_converter.go | 2 +- pkg/adapters/micro/options.go | 8 ++--- .../controllers/hotspotrules_controller.go | 2 +- util/time.go | 2 +- 8 files changed, 27 insertions(+), 28 deletions(-) diff --git a/api/api.go b/api/api.go index ea3e445b8..529fb327a 100644 --- a/api/api.go +++ b/api/api.go @@ -117,7 +117,7 @@ func WithAttachment(key interface{}, value interface{}) EntryOption { } } -// WithAttachment set the resource entry with the given k-v pairs +// WithAttachments set the resource entry with the given k-v pairs func WithAttachments(data map[interface{}]interface{}) EntryOption { return func(opts *EntryOptions) { if opts.attachments == nil { diff --git a/core/base/slot_chain.go b/core/base/slot_chain.go index 184e04db8..f4a4ad0b1 100644 --- a/core/base/slot_chain.go +++ b/core/base/slot_chain.go @@ -110,7 +110,7 @@ func NewSlotChain() *SlotChain { } } -// Get a EntryContext from EntryContext ctxPool, if ctxPool doesn't have enough EntryContext then new one. +// Get an EntryContext from EntryContext ctxPool, if ctxPool doesn't have enough EntryContext then new one. func (sc *SlotChain) GetPooledContext() *EntryContext { ctx := sc.ctxPool.Get().(*EntryContext) ctx.startTime = util.CurrentTimeMillis() diff --git a/core/circuitbreaker/circuit_breaker.go b/core/circuitbreaker/circuit_breaker.go index 171482a61..99b9e6260 100644 --- a/core/circuitbreaker/circuit_breaker.go +++ b/core/circuitbreaker/circuit_breaker.go @@ -26,20 +26,19 @@ import ( "github.com/pkg/errors" ) +// Circuit Breaker State Machine: // -// Circuit Breaker State Machine: -// -// switch to open based on rule -// +-----------------------------------------------------------------------+ -// | | -// | v -// +----------------+ +----------------+ Probe +----------------+ -// | | | |<----------------| | -// | | Probe succeed | | | | -// | Closed |<------------------| HalfOpen | | Open | -// | | | | Probe failed | | -// | | | +---------------->| | -// +----------------+ +----------------+ +----------------+ +// switch to open based on rule +// +-----------------------------------------------------------------------+ +// | | +// | v +// +----------------+ +----------------+ Probe +----------------+ +// | | | |<----------------| | +// | | Probe succeed | | | | +// | Closed |<------------------| HalfOpen | | Open | +// | | | | Probe failed | | +// | | | +---------------->| | +// +----------------+ +----------------+ +----------------+ type State int32 const ( @@ -126,7 +125,7 @@ type CircuitBreaker interface { OnRequestComplete(rtt uint64, err error) } -//================================= circuitBreakerBase ==================================== +// ================================= circuitBreakerBase ==================================== // circuitBreakerBase encompasses the common fields of circuit breaker. type circuitBreakerBase struct { rule *Rule @@ -230,7 +229,7 @@ func (b *circuitBreakerBase) fromHalfOpenToOpen(snapshot interface{}) bool { return false } -// fromHalfOpenToOpen updates circuit breaker state machine from half-open to closed +// fromHalfOpenToClosed updates circuit breaker state machine from half-open to closed // Return true only if current goroutine successfully accomplished the transformation. func (b *circuitBreakerBase) fromHalfOpenToClosed() bool { if b.state.cas(HalfOpen, Closed) { @@ -245,7 +244,7 @@ func (b *circuitBreakerBase) fromHalfOpenToClosed() bool { return false } -//================================= slowRtCircuitBreaker ==================================== +// ================================= slowRtCircuitBreaker ==================================== type slowRtCircuitBreaker struct { circuitBreakerBase stat *slowRequestLeapArray @@ -437,7 +436,7 @@ func (s *slowRequestLeapArray) allCounter() []*slowRequestCounter { return ret } -//================================= errorRatioCircuitBreaker ==================================== +// ================================= errorRatioCircuitBreaker ==================================== type errorRatioCircuitBreaker struct { circuitBreakerBase minRequestAmount uint64 @@ -622,7 +621,7 @@ func (s *errorCounterLeapArray) allCounter() []*errorCounter { return ret } -//================================= errorCountCircuitBreaker ==================================== +// ================================= errorCountCircuitBreaker ==================================== type errorCountCircuitBreaker struct { circuitBreakerBase minRequestAmount uint64 diff --git a/core/system_metric/sys_metric_stat.go b/core/system_metric/sys_metric_stat.go index c0efeaed2..8459f2a63 100644 --- a/core/system_metric/sys_metric_stat.go +++ b/core/system_metric/sys_metric_stat.go @@ -78,7 +78,7 @@ func init() { metric_exporter.Register(processMemoryGauge) } -// getMemoryStat returns the current machine's memory statistic +// getTotalMemorySize returns the current machine's memory statistic func getTotalMemorySize() (total uint64) { stat, err := mem.VirtualMemory() if err != nil { diff --git a/ext/datasource/hotspot_rule_converter.go b/ext/datasource/hotspot_rule_converter.go index e09aeab65..68a6e44e1 100644 --- a/ext/datasource/hotspot_rule_converter.go +++ b/ext/datasource/hotspot_rule_converter.go @@ -93,7 +93,7 @@ func (s *SpecificValue) String() string { return fmt.Sprintf("SpecificValue: [ValKind: %+v, ValStr: %s]", s.ValKind, s.ValStr) } -// arseSpecificItems parses the SpecificValue as real value. +// parseSpecificItems parses the SpecificValue as real value. func parseSpecificItems(source []SpecificValue) map[interface{}]int64 { ret := make(map[interface{}]int64, len(source)) if len(source) == 0 { diff --git a/pkg/adapters/micro/options.go b/pkg/adapters/micro/options.go index 924b0bdc4..899a22608 100644 --- a/pkg/adapters/micro/options.go +++ b/pkg/adapters/micro/options.go @@ -26,7 +26,7 @@ type ( } ) -// WithUnaryClientResourceExtractor sets the resource extractor of unary client request. +// WithClientResourceExtractor sets the resource extractor of unary client request. // The second string parameter is the full method name of current invocation. func WithClientResourceExtractor(fn func(context.Context, client.Request) string) Option { return func(opts *options) { @@ -34,7 +34,7 @@ func WithClientResourceExtractor(fn func(context.Context, client.Request) string } } -// WithUnaryServerResourceExtractor sets the resource extractor of unary server request. +// WithServerResourceExtractor sets the resource extractor of unary server request. func WithServerResourceExtractor(fn func(context.Context, server.Request) string) Option { return func(opts *options) { opts.serverResourceExtract = fn @@ -55,7 +55,7 @@ func WithStreamServerResourceExtractor(fn func(server.Stream) string) Option { } } -// WithUnaryClientBlockFallback sets the block fallback handler of unary client request. +// WithClientBlockFallback sets the block fallback handler of unary client request. // The second string parameter is the full method name of current invocation. func WithClientBlockFallback(fn func(context.Context, client.Request, *base.BlockError) error) Option { return func(opts *options) { @@ -63,7 +63,7 @@ func WithClientBlockFallback(fn func(context.Context, client.Request, *base.Bloc } } -// WithUnaryServerBlockFallback sets the block fallback handler of unary server request. +// WithServerBlockFallback sets the block fallback handler of unary server request. func WithServerBlockFallback(fn func(context.Context, server.Request, *base.BlockError) error) Option { return func(opts *options) { opts.serverBlockFallback = fn diff --git a/pkg/datasource/k8s/controllers/hotspotrules_controller.go b/pkg/datasource/k8s/controllers/hotspotrules_controller.go index 07eecc3d7..dbc618c00 100644 --- a/pkg/datasource/k8s/controllers/hotspotrules_controller.go +++ b/pkg/datasource/k8s/controllers/hotspotrules_controller.go @@ -151,7 +151,7 @@ func (r *HotspotRulesReconciler) assembleHotspotRules(rs *datasourcev1.HotspotRu return ret } -// arseSpecificItems parses the SpecificValue as real value. +// parseSpecificItems parses the SpecificValue as real value. func parseSpecificItems(source []datasourcev1.SpecificValue) map[interface{}]int64 { ret := make(map[interface{}]int64) if len(source) == 0 { diff --git a/util/time.go b/util/time.go index ef594d216..42835667a 100644 --- a/util/time.go +++ b/util/time.go @@ -255,7 +255,7 @@ func CurrentClock() Clock { return currentClock.Load().(*clockWrapper).clock } -// SetClock sets the ticker creator used by util package. +// SetTickerCreator sets the ticker creator used by util package. // In general, no need to set it. It is usually used for testing. func SetTickerCreator(tc TickerCreator) { currentTickerCreator.Store(&tickerCreatorWrapper{tc})