Skip to content

Commit

Permalink
x-pack/metricbeat/module/sql: Add debug queries when `merge_results: …
Browse files Browse the repository at this point in the history
…true` (#42271)

(cherry picked from commit d288e54)
  • Loading branch information
shmsr authored and mergify[bot] committed Jan 10, 2025
1 parent 5c94629 commit 6efe7f6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
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

0 comments on commit 6efe7f6

Please sign in to comment.