这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Conversation

@johnewing1
Copy link
Contributor


Description

Fixes panic when an IP address without a scheme was used as the graphite host.
E.g.

[GraphiteConf]
	Host = "127.0.0.1:80"

Results in

2020/06/30 17:45:29 enabling syslog
2020/06/30 17:45:29 info: migrate.go:138: checking migrations
2020/06/30 17:45:29 info: search.go:208: Loading last datapoints from redis
2020/06/30 17:45:29 info: search.go:215: Done
2020/06/30 17:45:29 info: check.go:562: check alert example.graphite start with now set to 2020-06-30 16:45:29.095031
2020/06/30 17:45:29 info: check.go:562: check alert example.opentsdb.os.high.cpu start with now set to 2020-06-30 16:45:29.095031
2020/06/30 17:45:29 info: check.go:562: check alert example.opentsdb.cpu.lookup start with now set to 2020-06-30 16:45:29.095031
<nil>2020/06/30 17:45:29 error: expr.go:148: Error: runtime error: invalid memory address or nil pointer dereference. Origin: Schedule: Alert Name: example.graphite. Expression: avg(graphite("*.cpu.*.cpu.user", "5m", "", "host..cpu")) > 1, Stack: goroutine 92 [running]:
runtime/debug.Stack(0x2271b60, 0x2254880, 0x35f4ba0)
	/usr/local/Cellar/go/1.13.7/libexec/src/runtime/debug/stack.go:24 +0x9d
bosun.org/cmd/bosun/expr.errRecover(0xc000169e58, 0xc000290f20)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How has this been tested?

  • Unit test added which reproduces panic edge case.

Checklist:

  • [x ] This contribution follows the project's code of conduct
  • This contribution follows the project's contributing guidelines
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

if u, _ := url.Parse(host); u.Scheme != "" && u.Host != "" {

u, err := url.Parse(host)
if err== nil && u.Scheme != "" && u.Host != "" {
Copy link
Member

@muffix muffix Jul 2, 2020

Choose a reason for hiding this comment

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

Worth adding the missing space here?

Suggested change
if err== nil && u.Scheme != "" && u.Host != "" {
if err == nil && u.Scheme != "" && u.Host != "" {

Maybe we should also add the style check to the GitHub action. Not sure why it's not complaining. It should. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the style issues

}
}

func TestUrlParsePanic(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Nice, great to see more test coverage. 👍

@johnewing1 johnewing1 merged commit 90760f8 into bosun-monitor:master Oct 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants