-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add ability to set sql file as query source for postgresql_extensible input #6361
Add ability to set sql file as query source for postgresql_extensible input #6361
Conversation
@@ -129,8 +146,18 @@ func (p *Postgresql) Gather(acc telegraf.Accumulator) error { | |||
// We loop in order to process each query | |||
// Query is not run if Database version does not match the query version. | |||
for i := range p.Query { | |||
if p.Query[i].Sqlquery != "" && p.Query[i].Script != "" { | |||
return fmt.Errorf("both 'sqlquery' and 'script' specified, please choose one 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 would remove this and just document that sqlquery
takes preference if both are defined.
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 don't have a strong opinion on returning an error vs precedence, though if I was asked to choose I think an error is slightly less prone to mistakes. However, I would like the script loading to be done only once. The easiest way to do this is to move it into a new Init() function:
func (p *Postgresql) Init() error {
// load the file and save onto the Postgresql struct.
// return an error if the file is unreadable or configuration is invalid
}
} | ||
defer file.Close() | ||
|
||
qyery, err := ioutil.ReadAll(file) |
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.
s/qyery/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.
Spelling still needs fixed.
plugins/inputs/postgresql_extensible/postgresql_extensible_test.go
Outdated
Show resolved
Hide resolved
script
option to be able set a sql file as a query source@@ -129,8 +146,18 @@ func (p *Postgresql) Gather(acc telegraf.Accumulator) error { | |||
// We loop in order to process each query | |||
// Query is not run if Database version does not match the query version. | |||
for i := range p.Query { | |||
if p.Query[i].Sqlquery != "" && p.Query[i].Script != "" { | |||
return fmt.Errorf("both 'sqlquery' and 'script' specified, please choose one 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 don't have a strong opinion on returning an error vs precedence, though if I was asked to choose I think an error is slightly less prone to mistakes. However, I would like the script loading to be done only once. The easiest way to do this is to move it into a new Init() function:
func (p *Postgresql) Init() error {
// load the file and save onto the Postgresql struct.
// return an error if the file is unreadable or configuration is invalid
}
@@ -108,6 +111,20 @@ func (p *Postgresql) IgnoredColumns() map[string]bool { | |||
return ignoredColumns | |||
} | |||
|
|||
func (p *Postgresql) ReadQueryFromFile(filePath string) (string, 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.
Make this a non-member function.
@glinton PTAL |
} | ||
defer file.Close() | ||
|
||
qyery, err := ioutil.ReadAll(file) |
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.
Spelling still needs fixed.
plugins/inputs/postgresql_extensible/postgresql_extensible_test.go
Outdated
Show resolved
Hide resolved
@glinton Done, PTAL, again;) |
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
Required for all PRs:
Fixes #6242