Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unify logging content style #293

Merged
merged 2 commits into from
Oct 23, 2020
Merged

Conversation

binbin0325
Copy link
Collaborator

@binbin0325 binbin0325 commented Oct 15, 2020

Describe what this PR does / why we need it

unify logging content style

Does this pull request fix one issue?

Fixes:#280

Describe how you did it

对项目中的四种日志类型统一风格,统一的标准如下:

Error:

  1. error 描述小写字母开头
  2. message 大写字母开头
  3. message 结尾声明错误在哪一个func()
  4. 输出参数使用keysAndValues(key不要用空格)
    例如:logging.Error(errors.New("bucket data type error"), "Bucket data type error in errorCounterLeapArray.allCounter()","param","paramValue")

Info:

  1. 日志以[$module]开头
  2. message 大写字母开头
  3. 输出参数使用keysAndValues(key不要用空格)
    例如:logging.Info("[Config] Print effective global config", "globalConfig", *globalCfg)

Warn:

  1. 日志以[$module $func]开头
  2. message 大写字母开头
  3. 输出参数使用keysAndValues(key不要用空格)
    例如:logging.Warn("[HotSpot onRuleUpdate] Ignoring the frequent param flow rule due to unsupported control behavior", "rule", r)

Debug:

  1. 日志以[$module $func]开头
  2. message 大写字母开头
  3. 输出参数使用keysAndValues(key不要用空格)
    例如:logging.Debug("[HotSpot onRuleUpdate] Ignoring the frequent param flow rule due to bad generated traffic controller", "rule", r)

Describe how to verify it

Special notes for reviews

@louyuting louyuting added the area/logging Issue related to logging of Sentinel label Oct 15, 2020
@louyuting louyuting added this to the 1.0.0 milestone Oct 15, 2020
@louyuting louyuting linked an issue Oct 15, 2020 that may be closed by this pull request
@sczyh30 sczyh30 added kind/enhancement Category issues or PRs related to enhancement to-review PRs to review labels Oct 15, 2020
@binbin0325 binbin0325 force-pushed the logging_style branch 3 times, most recently from a8bd638 to f6a4123 Compare October 17, 2020 01:27
@codecov-io
Copy link

codecov-io commented Oct 17, 2020

Codecov Report

Merging #293 into master will decrease coverage by 0.02%.
The diff coverage is 21.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #293      +/-   ##
==========================================
- Coverage   51.52%   51.49%   -0.03%     
==========================================
  Files          81       81              
  Lines        4101     4107       +6     
==========================================
+ Hits         2113     2115       +2     
- Misses       1701     1706       +5     
+ Partials      287      286       -1     
Impacted Files Coverage Δ
api/tracer.go 28.57% <0.00%> (ø)
core/base/entry.go 50.00% <0.00%> (ø)
core/circuitbreaker/circuit_breaker.go 68.15% <0.00%> (ø)
core/flow/slot.go 44.82% <0.00%> (ø)
core/flow/standalone_stat_slot.go 71.42% <0.00%> (ø)
core/hotspot/cache/lru.go 50.58% <0.00%> (ø)
core/hotspot/concurrency_stat_slot.go 3.70% <0.00%> (ø)
core/hotspot/slot.go 25.71% <0.00%> (ø)
core/hotspot/traffic_shaping.go 58.21% <0.00%> (ø)
core/isolation/slot.go 0.00% <0.00%> (ø)
... and 22 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 89bc23b...b650dad. Read the comment docs.

return nil
}
counter, ok := mb.(*slowRequestCounter)
if !ok {
logging.Error(errors.New("Bucket data type error"), "")
logging.Error(errors.New("bucket data type error"), "Bucket data type error in slowRequestLeapArray.currentCounter()")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might need to indicate "type assert failed, expect *slowRequestCounter"

continue
}
counter, ok := mb.(*slowRequestCounter)
if !ok {
logging.Error(errors.New("Bucket data type error"), "")
logging.Error(errors.New("bucket data type error"), "Bucket data type error in slowRequestLeapArray.allCounter()")
Copy link
Collaborator

@louyuting louyuting Oct 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with upon

return nil
}
counter, ok := mb.(*errorCounter)
if !ok {
logging.Error(errors.New("Bucket data type error"), "")
logging.Error(errors.New("bucket data type error"), "Bucket data type error in errorCounterLeapArray.currentCounter()")
Copy link
Collaborator

@louyuting louyuting Oct 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with upon

continue
}
counter, ok := mb.(*errorCounter)
if !ok {
logging.Error(errors.New("Bucket data type error"), "")
logging.Error(errors.New("bucket data type error"), "Bucket data type error in errorCounterLeapArray.allCounter()")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with upon

@@ -90,7 +90,7 @@ func loadFromYamlFile(filePath string) error {
if err != nil {
return err
}
logging.Info("Resolving Sentinel config from file", "file", filePath)
logging.Info("[Config] Resolving sentinel config from file", "file", filePath)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep "Sentinel", it's a brand.

continue
}
b, ok := mb.(*MetricBucket)
if !ok {
logging.Error(errors.New("fail to type assert, expect MetricBucket"), "fail to get current MetricBucket")
logging.Error(errors.New("fail to type assert, expect MetricBucket"), "Fail to get current MetricBucket in BucketLeapArray.CountWithTime()")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: "expect *MetricBucket"

return
}
b, ok := mb.(*MetricBucket)
if !ok {
logging.Error(errors.New("fail to type assert, expect MetricBucket"), "Failed to add count: bucket data type error")
logging.Error(errors.New("fail to type assert, expect MetricBucket"), "Bucket data type error in BucketLeapArray.addCountWithTime()")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo "expect *MetricBucket"

continue
}
b, ok := mb.(*MetricBucket)
if !ok {
logging.Error(errors.New("fail to type assert, expect MetricBucket"), "fail to get current MetricBucket")
logging.Error(errors.New("fail to type assert, expect MetricBucket"), "Fail to get current MetricBucket in BucketLeapArray.MinRt()")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo "expect *MetricBucket"

continue
}
counter, ok := mb.(*MetricBucket)
if !ok {
logging.Error(errors.New("type assert failed"), "Fail to do type assert, expect: MetricBucket", "type", reflect.TypeOf(mb).Name())
logging.Error(errors.New("type assert failed"), "Fail to do type assert, expect: MetricBucket in SlidingWindowMetric.GetMaxOfSingleBucket()", "type", reflect.TypeOf(mb).Name())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo "expect *MetricBucket"

continue
}
counter, ok := mb.(*MetricBucket)
if !ok {
logging.Error(errors.New("type assert failed"), "Fail to do type assert, expect: MetricBucket", "type", reflect.TypeOf(mb).Name())
logging.Error(errors.New("type assert failed"), "Fail to do type assert, expect: MetricBucket in SlidingWindowMetric.MinRT()", "type", reflect.TypeOf(mb).Name())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo "expect *MetricBucket"

return nil
}
mb, ok := mi.(*MetricBucket)
if !ok {
logging.Error(errors.New("type assert failed"), "Fail to do type assert, expect: MetricBucket", "bucketStartTime", w.BucketStart, "type", reflect.TypeOf(mb).Name())
logging.Error(errors.New("type assert failed"), "Fail to do type assert, expect: MetricBucket in SlidingWindowMetric.metricItemFromBuckets()", "bucketStartTime", w.BucketStart, "type", reflect.TypeOf(mb).Name())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo "expect *MetricBucket"

return nil
}
mb, ok := mi.(*MetricBucket)
if !ok {
logging.Error(errors.New("type assert failed"), "Fail to do type assert, expect: MetricBucket", "type", reflect.TypeOf(mb).Name())
logging.Error(errors.New("type assert failed"), "Fail to do type assert, expect: MetricBucket in SlidingWindowMetric.metricItemFromBucket()", "type", reflect.TypeOf(mb).Name())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo "expect *MetricBucket"

@@ -41,12 +40,12 @@ func main() {
go func() {
node := stat.GetOrCreateResourceNode("abc", base.ResTypeCommon)
for {
logging.Info(fmt.Sprintf("current concurrency:%d", node.CurrentConcurrency()))
logging.Info("[HotSpot Concurrency] Current concurrency", "current concurrency", node.CurrentConcurrency())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key shouldn't contain blank, might: "currentConcurrency"?

louyuting
louyuting previously approved these changes Oct 23, 2020
Copy link
Collaborator

@louyuting louyuting left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work

@louyuting louyuting merged commit c40258e into alibaba:master Oct 23, 2020
@sczyh30 sczyh30 removed the to-review PRs to review label Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/logging Issue related to logging of Sentinel kind/enhancement Category issues or PRs related to enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unify logging content style
5 participants