Skip to content
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

Generic SQL join results of multiple queries #32394

Merged
1 change: 0 additions & 1 deletion metricbeat/docs/modules/sql.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ This creates a combined event as below, where `blks_hit`, `blks_read`, `checkpoi
"address": "localhost"
},
"sql": {
"query": "",
"metrics": {
"blks_read": 21,
"checkpoints_req": 1,
Expand Down
1 change: 0 additions & 1 deletion x-pack/metricbeat/module/sql/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,6 @@ This creates a combined event as below, where `blks_hit`, `blks_read`, `checkpoi
"address": "localhost"
},
"sql": {
"query": "",
"metrics": {
"blks_read": 21,
"checkpoints_req": 1,
Expand Down
36 changes: 24 additions & 12 deletions x-pack/metricbeat/module/sql/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,32 @@ func (m *MetricSet) Fetch(ctx context.Context, reporter mb.ReporterV2) error {
func (m *MetricSet) reportEvent(ms mapstr.M, reporter mb.ReporterV2, qry string) {
if m.Config.RawData.Enabled {

Copy link
Member

@jsoriano jsoriano Jul 21, 2022

Choose a reason for hiding this comment

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

Another way to do this would be:

moduleFields := mapstr.M{
	"metrics": ms, // Individual metric
	"driver":  m.Config.Driver,
}
if qry != "" {
	moduleFields["query"] = qry
}
reporter.Event(mb.Event{
	ModuleFields: moduleFields,
})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I hope we can stay with the current structure.

Copy link
Member

Choose a reason for hiding this comment

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

I mean, you can do it this way in case you feel it complicates less the code 🙂 #32394 (comment)

reporter.Event(mb.Event{
// New usage.
// Only driver & query field mapped.
// metrics to be mapped by end user.
ModuleFields: mapstr.M{
"metrics": ms, // Individual metric
"driver": m.Config.Driver,
"query": qry,
},
})
// New usage.
// Only driver & query field mapped.
// metrics to be mapped by end user.
if len(qry) > 0 {
// set query.
reporter.Event(mb.Event{
ModuleFields: mapstr.M{
"metrics": ms, // Individual metric
"driver": m.Config.Driver,
"query": qry,
},
})
} else {
reporter.Event(mb.Event{
// Do not set query.
ModuleFields: mapstr.M{
"metrics": ms, // Individual metric
"driver": m.Config.Driver,
},
})

}
} else {
// Previous usage. Backword compartibility.
// Supports field mapping.
reporter.Event(mb.Event{
// Previous usage. Backword compartibility.
// Supports field mapping.
ModuleFields: mapstr.M{
"driver": m.Config.Driver,
"query": qry,
Expand Down