-
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
Changes from 5 commits
a6f81ce
78659f5
d5fba18
e0a17eb
f28834d
d0a3c28
3890c8a
46681c1
48c9177
71f29dd
d51257b
d31ff72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,9 @@ to implement Modules and their associated MetricSets. | |
package mb | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/url" | ||
"time" | ||
|
||
"github.com/elastic/beats/libbeat/common" | ||
|
@@ -306,17 +308,49 @@ type ModuleConfig struct { | |
MetricSets []string `config:"metricsets"` | ||
Enabled bool `config:"enabled"` | ||
Raw bool `config:"raw"` | ||
Query QueryParams `config:"query"` | ||
} | ||
|
||
func (c ModuleConfig) String() string { | ||
return fmt.Sprintf(`{Module:"%v", MetricSets:%v, Enabled:%v, `+ | ||
`Hosts:[%v hosts], Period:"%v", Timeout:"%v", Raw:%v}`, | ||
`Hosts:[%v hosts], Period:"%v", Timeout:"%v", Raw:%v, Query:%v}`, | ||
c.Module, c.MetricSets, c.Enabled, len(c.Hosts), c.Period, c.Timeout, | ||
c.Raw) | ||
c.Raw, c.Query) | ||
} | ||
|
||
func (c ModuleConfig) GoString() string { return c.String() } | ||
|
||
// QueryParams is a convenient map[string]interface{} wrapper to implement the String interface which 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 '?') | ||
type QueryParams map[string]interface{} | ||
|
||
// 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) { | ||
u := url.Values{} | ||
|
||
for k, v := range q { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could also use |
||
if values, ok := v.([]interface{}); ok { | ||
for _, innerValue := range values { | ||
u.Add(k, fmt.Sprintf("%v", innerValue)) | ||
} | ||
} else { | ||
//nil values in YAML shouldn't be stringified anyhow | ||
if v == nil { | ||
u.Add(k, "") | ||
} else { | ||
u.Add(k, fmt.Sprintf("%v", v)) | ||
sayden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
|
||
byt, _ := json.MarshalIndent(u, "", " ") | ||
fmt.Println(string(byt), u.Encode()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. OMG, yes, sorry about this. |
||
|
||
return u.Encode() | ||
} | ||
|
||
// defaultModuleConfig contains the default values for ModuleConfig instances. | ||
var defaultModuleConfig = ModuleConfig{ | ||
Enabled: true, | ||
|
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 usepull
for the pull request andissue
for the issue. Usually the PR is always referenced and sometimes also the issue.