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

[8.x](backport #42271) x-pack/metricbeat/module/sql: Add debug queries when merge_results: true #42285

Open
wants to merge 1 commit into
base: 8.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Added `tier_preference`, `creation_date` and `version` fields to the `elasticsearch.index` metricset. {pull}41944[41944]
- Add new OpenAI (`openai`) module for tracking usage data. {pull}41516[41516]
- Add `use_performance_counters` to collect CPU metrics using performance counters on Windows for `system/cpu` and `system/core` {pull}41965[41965]
- Preserve queries for debugging when `merge_results: true` in SQL module {pull}42271[42271]

*Metricbeat*
- Add benchmark module {pull}41801[41801]
Expand Down
6 changes: 4 additions & 2 deletions x-pack/metricbeat/module/sql/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ func dbSelector(driver, dbName string) string {
func (m *MetricSet) fetch(ctx context.Context, db *sql.DbClient, reporter mb.ReporterV2, queries []query) (bool, error) {
var ok bool
merged := make(mapstr.M, 0)
storeQueries := make([]string, 0, len(queries))
for _, q := range queries {
storeQueries = append(storeQueries, q.Query)
if q.ResponseFormat == tableResponseFormat {
// Table format
mss, err := db.FetchTableMode(ctx, q.Query)
Expand Down Expand Up @@ -196,7 +198,7 @@ func (m *MetricSet) fetch(ctx context.Context, db *sql.DbClient, reporter mb.Rep

if m.Config.MergeResults {
// Report here for merged case.
ok = m.reportEvent(merged, reporter, "")
ok = m.reportEvent(merged, reporter, storeQueries...)
}

return ok, nil
Expand Down Expand Up @@ -296,7 +298,7 @@ func (m *MetricSet) Fetch(ctx context.Context, reporter mb.ReporterV2) error {

// reportEvent using 'user' mode with keys under `sql.metrics.*` or using Raw data mode (module and metricset key spaces
// provided by the user)
func (m *MetricSet) reportEvent(ms mapstr.M, reporter mb.ReporterV2, qry string) bool {
func (m *MetricSet) reportEvent(ms mapstr.M, reporter mb.ReporterV2, qry ...string) bool {
var ok bool
if m.Config.RawData.Enabled {
// New usage.
Expand Down
Loading