-
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
Added 'query' parameter to metricbeats global configuration #8292
Added 'query' parameter to metricbeats global configuration #8292
Conversation
67a9524
to
272c74b
Compare
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.
Thanks for identifying and fixing this issue, it mostly LGTM, could you add a test case to TestURLHostParserBuilder
test in url_test.go
that would have failed without this change?
Oh, and add a reference to this setting in |
Nice! this looks like the right solution 🎉 Please add also a changelog entry. I'm adding the |
I have been digging into the code and I found a way to implement it within the HTTP helper instead that on the What do you think? |
@sayden but is the |
In this function, https://github.com/elastic/beats/blob/master/metricbeat/helper/http.go#L102 the I really don't have a strong preference so... as you wish. |
Ok, after a quick chat with @jsoriano I'm going with the base Metricset option |
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 revisited this code now, I'm wondering if this could get fixed from NewHostDataFromURL
, as there you get access to the url.URL
object, which contains the RawQuery
metricbeat/mb/mb.go
Outdated
func (q QueryParams) String() (s string) { | ||
for k, v := range q { | ||
if v == nil { | ||
v = "null" |
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 setting null
?, I think URL params support empty values
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 wasn't sure I have to admit but Go was setting literally <nil>
so I thought that null
was a bit more universal.
I have just checked it and it seems that empty values are supported. Thanks for the thumbs up!
// String returns the values in common query params format (key=value&key2=value2) which is the way that the url | ||
// package expects this params (without the initial '?') | ||
func (q QueryParams) String() (s string) { | ||
for k, v := range q { |
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.
You could also use url.Values
for this
metricbeat/_meta/fields.common.yml
Outdated
@@ -38,3 +38,7 @@ | |||
example: elasticsearch | |||
description: > | |||
Name of the service metricbeat fetches the data from. | |||
|
|||
- name: query |
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.
fields.yml
spec is used to define the index template for the data we push: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html
I believe we are not reporting the query
as for this change, so we don't need to configure a mapping for it
Ok, as requested by @exekias I'm gonna improve the code with the suggestions. I have also checked that the contents of a url query param can also be an array (with syntax I have also checked that the implementation can't be done in Edit: Added a one more common way to set array in the query. It seems it's not standarized at all |
I was actually wondering if it is better to proceed with a string value for the metricbeat.modules:
- module: http
metricsets:
- json
- server
period: 1s
hosts: ["localhost:8080"]
namespace: "json_namespace"
path: "/home"
query:
key: value
key2: 11
key3: 12.3
key4: true
key5: -4
ar:
- ar1
- ar2
- ar3
ar2:
- 13
- -14.3
- -15
- 33
output.console:
pretty: true Instead of query: "ar=ar1&ar=ar2&ar=ar3&ar2=13&ar2=-14.300000&ar2=-15&ar2=33&key=value&key2=11&key3=12.300000&key4=true&key5=-4" |
That looks better to me, wdyt @jsoriano? |
It looks good to me too. |
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package add_process_metadata |
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.
don't use an underscore in package name
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package add_process_metadata |
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.
don't use an underscore in package name
|
||
// +build ignore | ||
|
||
package add_process_metadata |
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.
don't use an underscore in package name
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package add_process_metadata |
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.
don't use an underscore in package name
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package add_process_metadata |
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.
don't use an underscore in package name
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package add_process_metadata |
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.
don't use an underscore in package name
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package add_process_metadata |
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.
don't use an underscore in package name
libbeat/monitoring/report/report.go
Outdated
type Reporter interface { | ||
Stop() | ||
} | ||
|
||
type ReporterFactory func(beat.Info, *common.Config) (Reporter, error) | ||
type ReporterFactory func(beat.Info, Settings, *common.Config) (Reporter, 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.
exported type ReporterFactory should have comment or be unexported
libbeat/monitoring/report/report.go
Outdated
@@ -30,11 +30,15 @@ type config struct { | |||
Reporter common.ConfigNamespace `config:",inline"` | |||
} | |||
|
|||
type Settings struct { |
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.
exported type Settings should have comment or be unexported
…of params. Added tests Updated Changelog and fields.
20d672c
to
e0a17eb
Compare
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, just a minor detail about a function name.
Oh, @sayden, and don't forget about adding a reference to this new setting in |
metricbeat/mb/mb.go
Outdated
} | ||
|
||
byt, _ := json.MarshalIndent(u, "", " ") | ||
fmt.Println(string(byt), u.Encode()) |
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 guess you want to remove 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.
OMG, yes, sorry about this.
Documentation added aaaand conflict in Changelog solved. |
[float] | ||
==== `query` | ||
|
||
An optional value to pass common query params in YAML. Instead of setting the query params within hosts values using the syntax `?key=value&key2&value2`, you can set it here like 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.
This line could be wrapped with similar length as the others in the file.
list: | ||
- 1.1 | ||
- 2.95 | ||
- -15 |
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.
----
missing after the code snippet?
CHANGELOG.asciidoc
Outdated
@@ -136,6 +136,7 @@ https://github.com/elastic/beats/compare/v6.4.0...master[Check the HEAD diff] | |||
- Allow TCP helper to support delimiters and graphite module to accept multiple metrics in a single payload. {pull}8278[8278] | |||
- Added 'died' PID state to process_system metricset on system module{pull}8275[8275] | |||
- Added `ccr` metricset to Elasticsearch module. {pull}8335[8335] | |||
- Added support for query params in configuration {pull}8286[8286] |
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.
Oh, the referenced issue here is the bug report, but the tag is for pull
. You can reference any of them here, or both, but use pull
for the pull request and issue
for the issue. Usually the PR is always referenced and sometimes also the issue.
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, thanks for addressing all requested changes. Take a look to failures in CI builds.
Travis error seems like a couchbase error. I think we are fine
|
Initial PR on
mb
package which fixes issue #8286 but I guess it will be better to implement in the HTTP helper. The thing is that the URI parsing of a metricbeat occurs in themb
package so to implement it outside of it could lead to ugly-and-not-so-predictable codeI've tested in local successfully but I haven't found a test that already covers
Build()
method.Ideas welcome :)