Skip to content

feat(support-mysql-8): Added support for mysql version 8.0 and above #170

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ compile: bin/$(BINARY_NAME)

test:
@echo "=== $(INTEGRATION) === [ test ]: running unit tests..."
@go test -race ./... -count=1
@go test -v -race ./... -count=1

integration-test:
@echo "=== $(INTEGRATION) === [ test ]: running integration tests..."
@docker compose -f tests/integration/docker-compose.yml up -d --build
@go test -tags=integration ./tests/integration/. || (ret=$$?; docker compose -f tests/integration/docker-compose.yml down && exit $$ret)
@go test -v -tags=integration ./tests/integration/. || (ret=$$?; docker compose -f tests/integration/docker-compose.yml down && exit $$ret)
@docker compose -f tests/integration/docker-compose.yml down

install: bin/$(BINARY_NAME)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.23.4

require (
github.com/bitly/go-simplejson v0.5.1
github.com/blang/semver/v4 v4.0.0
github.com/go-sql-driver/mysql v1.8.1
github.com/newrelic/infra-integrations-sdk/v3 v3.9.1
github.com/sirupsen/logrus v1.9.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/bitly/go-simplejson v0.5.1 h1:xgwPbetQScXt1gh9BmoJ6j9JMr3TElvuIyjR8pgdoow=
github.com/bitly/go-simplejson v0.5.1/go.mod h1:YOPVLzCfwK14b4Sff3oP1AmGhI9T9Vsg84etUnlyp+Q=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
127 changes: 127 additions & 0 deletions src/default_metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package main

import (
"github.com/blang/semver/v4"
"github.com/newrelic/infra-integrations-sdk/v3/data/metric"
)

var defaultMetricsBase = map[string][]interface{}{
"net.abortedClientsPerSecond": {"Aborted_clients", metric.RATE},
"net.abortedConnectsPerSecond": {"Aborted_connects", metric.RATE},
"net.bytesReceivedPerSecond": {"Bytes_received", metric.RATE},
"net.bytesSentPerSecond": {"Bytes_sent", metric.RATE},
"net.connectionErrorsMaxConnectionsPerSecond": {"Connection_errors_max_connections", metric.RATE},
"net.connectionsPerSecond": {"Connections", metric.RATE},
"net.maxUsedConnections": {"Max_used_connections", metric.GAUGE},
"net.threadsConnected": {"Threads_connected", metric.GAUGE},
"net.threadsRunning": {"Threads_running", metric.GAUGE},
"query.comCommitPerSecond": {"Com_commit", metric.RATE},
"query.comDeletePerSecond": {"Com_delete", metric.RATE},
"query.comDeleteMultiPerSecond": {"Com_delete_multi", metric.RATE},
"query.comInsertPerSecond": {"Com_insert", metric.RATE},
"query.comInsertSelectPerSecond": {"Com_insert_select", metric.RATE},
"query.comReplaceSelectPerSecond": {"Com_replace_select", metric.RATE},
"query.comRollbackPerSecond": {"Com_rollback", metric.RATE},
"query.comSelectPerSecond": {"Com_select", metric.RATE},
"query.comUpdatePerSecond": {"Com_update", metric.RATE},
"query.comUpdateMultiPerSecond": {"Com_update_multi", metric.RATE},
"db.handlerRollbackPerSecond": {"Handler_rollback", metric.RATE},
"query.preparedStmtCountPerSecond": {"Prepared_stmt_count", metric.RATE},
"query.queriesPerSecond": {"Queries", metric.RATE},
"query.questionsPerSecond": {"Questions", metric.RATE},
"query.slowQueriesPerSecond": {"Slow_queries", metric.RATE},
"db.innodb.bufferPoolPagesData": {"Innodb_buffer_pool_pages_data", metric.GAUGE},
"db.innodb.bufferPoolPagesFree": {"Innodb_buffer_pool_pages_free", metric.GAUGE},
"db.innodb.bufferPoolPagesTotal": {"Innodb_buffer_pool_pages_total", metric.GAUGE},
"db.innodb.dataReadBytesPerSecond": {"Innodb_data_read", metric.RATE},
"db.innodb.dataWrittenBytesPerSecond": {"Innodb_data_written", metric.RATE},
"db.innodb.logWaitsPerSecond": {"Innodb_log_waits", metric.RATE},
"db.innodb.rowLockCurrentWaits": {"Innodb_row_lock_current_waits", metric.GAUGE},
"db.innodb.rowLockTimeAvg": {"Innodb_row_lock_time_avg", metric.GAUGE},
"db.innodb.rowLockWaitsPerSecond": {"Innodb_row_lock_waits", metric.RATE},
"db.openFiles": {"Open_files", metric.GAUGE},
"db.openTables": {"Open_tables", metric.GAUGE},
"db.openedTablesPerSecond": {"Opened_tables", metric.RATE},
"db.tablesLocksWaitedPerSecond": {"Table_locks_waited", metric.RATE},
"software.edition": {"version_comment", metric.ATTRIBUTE},
"software.version": {"version", metric.ATTRIBUTE},
"cluster.nodeType": {"node_type", metric.ATTRIBUTE},
}

var defaultMetrics560 = map[string][]interface{}{
"db.qCacheFreeMemoryBytes": {"Qcache_free_memory", metric.GAUGE},
"db.qCacheNotCachedPerSecond": {"Qcache_not_cached", metric.RATE},
"db.qCacheUtilization": {qCacheUtilization, metric.GAUGE},
"db.qCacheHitRatio": {qCacheHitRatio, metric.GAUGE},
// If a cluster instance is not a slave, then the metric cluster.slaveRunning will be removed.
"cluster.slaveRunning": {slaveRunningAsNumber, metric.GAUGE},
}

var defaultMetrics800 = map[string][]interface{}{
// If a cluster instance is not a slave, then the metric cluster.slaveRunning will be removed.
"cluster.slaveRunning": {slaveRunningAsNumber, metric.GAUGE},
}

func slaveRunningAsNumber(metrics map[string]interface{}, version *semver.Version) (int, bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this requires unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is already existing func just moved to diff file

Copy link
Contributor

Choose a reason for hiding this comment

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

If it is not possible to add unit test for this as part of this PR, please create a task for adding it later.

var prefix string
if version.GE(semver.Version{Major: 8, Minor: 0, Patch: 0}) {
prefix = "Replica"
} else {
prefix = "Slave"
}
slaveIORunning, okIO := metrics[prefix+"_IO_Running"].(string)
slaveSQLRunning, okSQL := metrics[prefix+"_SQL_Running"].(string)
if !okIO || !okSQL {
return 0, false
}
if slaveIORunning == "Yes" && slaveSQLRunning == "Yes" {
return 1, true
}
return 0, true
}

func qCacheUtilization(metrics map[string]interface{}) (float64, bool) {
// TODO compute the value within the interval
Copy link
Contributor

Choose a reason for hiding this comment

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

This TODO is not clear to me.

Copy link
Contributor Author

@sairaj18 sairaj18 Dec 30, 2024

Choose a reason for hiding this comment

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

this is already existing comment that just moved to different file

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to understand why it is there. If we think we don't need it, it can be removed.

qCacheFreeBlocks, ok1 := metrics["Qcache_free_blocks"].(int)
qCacheTotalBlocks, ok2 := metrics["Qcache_total_blocks"].(int)

if qCacheTotalBlocks == 0 {
return 0, true
} else if ok1 && ok2 {
return 1 - (float64(qCacheFreeBlocks) / float64(qCacheTotalBlocks)), true
}
return 0, false
}

func qCacheHitRatio(metrics map[string]interface{}) (float64, bool) {
qCacheHits, ok1 := metrics["Qcache_hits"].(int)
queries, ok2 := metrics["Queries"].(int)

if queries == 0 {
return 0, true
} else if ok1 && ok2 {
return float64(qCacheHits) / float64(queries), true
}
return 0, false
}

var defaultMetricsVersionDefinitions = []VersionDefinition{
{
minVersion: semver.MustParse("8.0.0"),
metricsDefinition: mergeMaps(defaultMetricsBase, defaultMetrics800),
},
{
minVersion: semver.MustParse("5.6.0"),
metricsDefinition: mergeMaps(defaultMetricsBase, defaultMetrics560),
},
}

func getDefaultMetrics(version *semver.Version) map[string][]interface{} {
// Find the first version definition that's applicable
for _, versionDef := range defaultMetricsVersionDefinitions {
if version.GE(versionDef.minVersion) {
return versionDef.metricsDefinition
}
}
return defaultMetricsBase
}
77 changes: 77 additions & 0 deletions src/extended_metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package main

import (
"github.com/blang/semver/v4"
"github.com/newrelic/infra-integrations-sdk/v3/data/metric"
)

var extendedMetricsBase = map[string][]interface{}{
"db.createdTmpDiskTablesPerSecond": {"Created_tmp_disk_tables", metric.RATE},
"db.createdTmpFilesPerSecond": {"Created_tmp_files", metric.RATE},
"db.createdTmpTablesPerSecond": {"Created_tmp_tables", metric.RATE},
"db.handlerDeletePerSecond": {"Handler_delete", metric.RATE},
"db.handlerReadFirstPerSecond": {"Handler_read_first", metric.RATE},
"db.handlerReadKeyPerSecond": {"Handler_read_key", metric.RATE},
"db.handlerReadRndPerSecond": {"Handler_read_rnd", metric.RATE},
"db.handlerReadRndNextPerSecond": {"Handler_read_rnd_next", metric.RATE},
"db.handlerUpdatePerSecond": {"Handler_update", metric.RATE},
"db.handlerWritePerSecond": {"Handler_write", metric.RATE},
"db.maxExecutionTimeExceededPerSecond": {"Max_execution_time_exceeded", metric.RATE},
"db.selectFullJoinPerSecond": {"Select_full_join", metric.RATE},
"db.selectFullJoinRangePerSecond": {"Select_full_range_join", metric.RATE},
"db.selectRangePerSecond": {"Select_range", metric.RATE},
"db.selectRangeCheckPerSecond": {"Select_range_check", metric.RATE},
"db.sortMergePassesPerSecond": {"Sort_merge_passes", metric.RATE},
"db.sortRangePerSecond": {"Sort_range", metric.RATE},
"db.sortRowsPerSecond": {"Sort_rows", metric.RATE},
"db.sortScanPerSecond": {"Sort_scan", metric.RATE},
"db.tableOpenCacheHitsPerSecond": {"Table_open_cache_hits", metric.RATE},
"db.tableOpenCacheMissesPerSecond": {"Table_open_cache_misses", metric.RATE},
"db.tableOpenCacheOverflowsPerSecond": {"Table_open_cache_overflows", metric.RATE},
"db.threadsCached": {"Threads_cached", metric.GAUGE},
"db.threadsCreatedPerSecond": {"Threads_created", metric.RATE},
"db.threadCacheMissRate": {threadCacheMissRate, metric.GAUGE},
}

var extendedMetrics560 = map[string][]interface{}{
"db.qCacheFreeBlocks": {"Qcache_free_blocks", metric.GAUGE},
"db.qCacheHitsPerSecond": {"Qcache_hits", metric.RATE},
"db.qCacheInserts": {"Qcache_inserts", metric.GAUGE},
"db.qCacheLowmemPrunesPerSecond": {"Qcache_lowmem_prunes", metric.RATE},
"db.qCacheQueriesInCachePerSecond": {"Qcache_queries_in_cache", metric.RATE},
"db.qCacheTotalBlocks": {"Qcache_total_blocks", metric.GAUGE},
}

func threadCacheMissRate(metrics map[string]interface{}) (float64, bool) {
// TODO compute the value within the interval
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't understand the TODO statement here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is already existing comment that just moved to different file

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to understand why it is there. If we think we don't need it, it can be removed.

threadsCreated, ok1 := metrics["Threads_created"].(int)
connections, ok2 := metrics["Connections"].(int)

if connections == 0 {
return 0, true
} else if ok1 && ok2 {
return float64(threadsCreated) / float64(connections), true
}
return 0, false
}

var extendedMetricsVersionDefinitions = []VersionDefinition{
{
minVersion: semver.MustParse("8.0.0"),
metricsDefinition: extendedMetricsBase,
},
{
minVersion: semver.MustParse("5.6.0"),
metricsDefinition: mergeMaps(extendedMetricsBase, extendedMetrics560),
},
}

func getExtendedMetrics(version *semver.Version) map[string][]interface{} {
// Find the first version definition that's applicable
for _, versionDef := range extendedMetricsVersionDefinitions {
if version.GE(versionDef.minVersion) {
return versionDef.metricsDefinition
}
}
return extendedMetricsBase
}
Loading
Loading