Skip to content

Commit

Permalink
Merge pull request #46 from newrelic/lockup
Browse files Browse the repository at this point in the history
Collect tablespace size concurrently
  • Loading branch information
camdencheek authored Nov 8, 2019
2 parents 89065d8 + 2e8f425 commit 3bd8ff3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 2.1.6 - 2019-11-08
### Fixed
- Run all DB queries concurrently to avoid deadlock

## 2.1.5 - 2019-11-07
### Fixed
- Avoid panicking or blocking when inventory connection fails.
Expand Down
12 changes: 7 additions & 5 deletions src/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ func collectMetrics(db *sql.DB, populaterWg *sync.WaitGroup, i *integration.Inte
var collectorWg sync.WaitGroup
metricChan := make(chan newrelicMetricSender, 100) // large buffer for speed

// Separate logic is needed to see if we should even collect tablespaces
// Collect tablespaces first so the list query completes before other queries are run
collectorWg.Add(25)
go collectTableSpaces(db, &collectorWg, metricChan)

// Create a goroutine for each of the metric groups to collect
collectorWg.Add(24)
go oracleCDBDatafilesOffline.Collect(db, &collectorWg, metricChan)
go oraclePDBDatafilesOffline.Collect(db, &collectorWg, metricChan)
go oraclePDBNonWrite.Collect(db, &collectorWg, metricChan)
Expand All @@ -46,9 +50,6 @@ func collectMetrics(db *sql.DB, populaterWg *sync.WaitGroup, i *integration.Inte
go oracleRollbackSegments.Collect(db, &collectorWg, metricChan)
go oracleRedoLogWaits.Collect(db, &collectorWg, metricChan)

// Separate logic is needed to see if we should even collect tablespaces
collectTableSpaces(db, &collectorWg, metricChan)

// When the metric groups are finished collecting, close the channel
go func() {
collectorWg.Wait()
Expand Down Expand Up @@ -142,6 +143,8 @@ const maxTablespaces = 200
const tablespaceCountQuery = `SELECT count(1) FROM DBA_TABLESPACES WHERE TABLESPACE_NAME <> 'TEMP'`

func collectTableSpaces(db *sql.DB, wg *sync.WaitGroup, metricChan chan<- newrelicMetricSender) {
defer wg.Done()

// Get count from database
if tablespaceWhiteList == nil {
tablespaceCount, err := queryNumTablespaces(db)
Expand Down Expand Up @@ -187,7 +190,6 @@ func queryNumTablespaces(db *sql.DB) (int, error) {
if err != nil {
return 0, err
}

}

return count, nil
Expand Down
3 changes: 2 additions & 1 deletion src/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ func Test_collectTableSpaces_NoWhitelist_Ok(t *testing.T) {
metricChan := make(chan newrelicMetricSender, 10)
var collectorWg sync.WaitGroup

collectTableSpaces(db, &collectorWg, metricChan)
collectorWg.Add(1)
go collectTableSpaces(db, &collectorWg, metricChan)

collectorWg.Wait()

Expand Down
12 changes: 5 additions & 7 deletions src/oracledb.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type argumentList struct {

const (
integrationName = "com.newrelic.oracledb"
integrationVersion = "2.1.4"
integrationVersion = "2.1.6"
)

var (
Expand Down Expand Up @@ -70,14 +70,12 @@ func main() {
instanceLookUp, err := createInstanceIDLookup(db)
exitOnErr(err)

if args.All() {
populaterWg.Add(2)
go collectMetrics(db, &populaterWg, i, instanceLookUp)
go collectInventory(db, &populaterWg, i, instanceLookUp)
} else if args.Metrics {
if args.HasMetrics() {
populaterWg.Add(1)
go collectMetrics(db, &populaterWg, i, instanceLookUp)
} else if args.Inventory {
}

if args.HasInventory() {
populaterWg.Add(1)
go collectInventory(db, &populaterWg, i, instanceLookUp)
}
Expand Down

0 comments on commit 3bd8ff3

Please sign in to comment.