-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
haproxy http stats #5819
haproxy http stats #5819
Conversation
Can one of the admins verify this patch? |
e1a5538
to
381455f
Compare
@jsoriano Thanks a lot for you contribution. Any chance we could separate the PR into 2 PR's. One with the changes to the testing / Makefile and the other one with the Stat change. So we can discuss these changes seperately and one does not hold back the other. |
@ruflin sure |
} | ||
|
||
func (p *httpProto) Info() (*bytes.Buffer, error) { | ||
return nil, errors.New("not supported") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is interesting. So http does not support the info
request? We should probably state that in the docs somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems so :/ I couldn't find a way to do it (apart of parsing the human stats html), and according to the code the dump info function is only called when executing the show info
command https://github.com/haproxy/haproxy/blob/master/src/stats.c#L3130.
Ok, I'll review docs in the repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc and line to changelog added.
"hosts": self.get_hosts(), | ||
"period": "5s" | ||
}]) | ||
def _test_info(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you add an _
in front and remove the intergration part line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved common code to "internal" functions so it can be reused for multiple cases. At the end this test has only the tcp socket case (it could maybe have also another case for a unix socket file), but the stat test has multiple cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. The diff tricked me here :-)
381455f
to
d485360
Compare
Changes on tests moved to #5820 |
Thanks a lot for taking this. Only had a quick look so far but that looks really promising. Will have a deeper look later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a line to the CHANGELOG.asciidoc and also update the docs file probably best the one on the module level that http and socket are supported, but only socket works for both metricsets?
func (p *httpProto) Stat() (*bytes.Buffer, error) { | ||
url := p.URL.String() | ||
// Force csv format | ||
if !strings.HasSuffix(url, ";csv") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What other formats do we have available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only human-oriented html, so csv is the only reasonable one to parse :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON has been added to haproxy 1.8, but we may continue using CSV for backwards compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like something we should probably add more details about to the docs.
metricbeat/module/haproxy/haproxy.go
Outdated
return nil, fmt.Errorf("invalid response: %s", resp.Status) | ||
} | ||
|
||
d, err := ioutil.ReadAll(resp.Body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we need here afterwards resp.Body.Close()
to not leak the resource?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch, you are right, good catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Close added
"hosts": self.get_hosts(), | ||
"period": "5s" | ||
}]) | ||
def _test_info(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. The diff tricked me here :-)
d485360
to
b788c74
Compare
case "tcp": | ||
return &Client{&unixProto{Network: u.Scheme, Address: u.Host}}, nil | ||
case "unix": | ||
return &Client{&unixProto{Network: u.Scheme, Address: u.Path}}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have modified this, before the url was parsed just splitting protocol and address, and the addres obtained this way was fine both for tcp and unix sockets. But now after the change to use url
package for url parsing the address is Host
for tcp, but Path
for unix.
In any case, even if seems to be supported, there was no test coverage for unix socket, this will have to be revisited, as a volume in the docker would be needed to test this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are you saying is "this should still work the same but we don't have any tests and we didn't have any before"? :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some last minor comments. PR looks good to me.
For example, to enable stats reporting via any local IP on port 14567, place | ||
this statement under the `global` or `default` section of the haproxy config: | ||
|
||
stats socket 127.0.0.1:14567 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add ticks
around this to make sure it shows up as code in the docs.
be added. For example, to open this frontend to any IP on port 14567 with | ||
required authentication add this to the haproxy config: | ||
|
||
listen stats |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a code block here:
["source","sh",subs="attributes"]
----
your code
----
I don't know what source
type would work best here. @dedemorton perhaps knows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is rendered by github as code just leaving spaces before, the same with the previous snippet. Should I better use code blocks in any case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please use code blocks as for our docs build Github is not really the one which counts in the end. We use code block in hopefully most other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have set haproxy
as "language", if empty, make docs
fails.
case "tcp": | ||
return &Client{&unixProto{Network: u.Scheme, Address: u.Host}}, nil | ||
case "unix": | ||
return &Client{&unixProto{Network: u.Scheme, Address: u.Path}}, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are you saying is "this should still work the same but we don't have any tests and we didn't have any before"? :-)
} | ||
|
||
if p.URL.User != nil { | ||
password, _ := p.URL.User.Password() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should check this error here? Is no password = error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ignored value is a boolean telling if the password was set, I don't know if there are cases where basic authentication would work with an empty password... In any case I think it can be fine as is, if the credentials are wrong, the request will fail and this error is checked.
metricbeat/module/haproxy/haproxy.go
Outdated
if err != nil { | ||
return response, err | ||
return nil, errors.New("invalid url") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use errors.Wrap so that the original error message is not lost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
metricbeat/module/haproxy/haproxy.go
Outdated
case "http", "https": | ||
return &Client{&httpProto{URL: u}}, nil | ||
default: | ||
return nil, errors.New("invalid protocol scheme") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include the invalid value in the error message with errors.Errorf.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, using errors.Errorf
in the rest of the file too.
b788c74
to
9e7a37e
Compare
jenkins, test it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Only change needs is the code blocks in the docs.
9e7a37e
to
b259c12
Compare
jenkins, test it |
@jsoriano Can you run |
d6e73f2
to
5013a93
Compare
Pushed changes after |
jenkins, test it |
9fa6980
to
b1e246a
Compare
b1e246a
to
d2876f2
Compare
jenkins, test it |
@jsoriano Merged. Thanks for all your work on this one. |
Adds support for haproxy http stats endpoint with support with basic authentication (what fixes #5178).