Skip to content

Commit

Permalink
fix(): MSSQL database metric set
Browse files Browse the repository at this point in the history
  • Loading branch information
wilhuang committed Nov 7, 2024
1 parent 894640f commit 8f453b4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions x-pack/metricbeat/module/mssql/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ func init() {
// interface methods except for Fetch.
type MetricSet struct {
mb.BaseMetricSet
log *logp.Logger
db *sql.DB
log *logp.Logger
db *sql.DB
dbCountLimit int
}

// New creates a new instance of the MetricSet. New is responsible for unpacking
Expand Down Expand Up @@ -73,10 +74,16 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
return nil, fmt.Errorf("could not create connection to db %w", err)
}

dbCountLimit := 30
if limit, ok := rowConfig["dbCountLimit"].(int); ok {
dbCountLimit = limit
}

return &MetricSet{
BaseMetricSet: base,
log: logger,
db: db,
dbCountLimit: dbCountLimit,
}, nil
}

Expand Down Expand Up @@ -140,7 +147,6 @@ func (m *MetricSet) Fetch(reporter mb.ReporterV2) {
m.log.Error(fmt.Errorf("error applying table log schema %w", err))
}

const DbCount = 50
dbCount := 0
allDbs := m.fetchAllDbs(reporter)
for dbName := range allDbs {
Expand Down Expand Up @@ -169,7 +175,7 @@ func (m *MetricSet) Fetch(reporter mb.ReporterV2) {
}

dbCount += 1
if dbCount > DbCount {
if dbCount > m.dbCountLimit {
break
}
}
Expand Down

0 comments on commit 8f453b4

Please sign in to comment.