-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add innodb_read_rows as vttablet metric #7520
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,7 @@ type Engine struct { | |
|
||
tableFileSizeGauge *stats.GaugesWithSingleLabel | ||
tableAllocatedSizeGauge *stats.GaugesWithSingleLabel | ||
innoDbReadRowsGauge *stats.GaugesWithSingleLabel | ||
} | ||
|
||
// NewEngine creates a new Engine. | ||
|
@@ -99,6 +100,7 @@ func NewEngine(env tabletenv.Env) *Engine { | |
_ = env.Exporter().NewGaugeDurationFunc("SchemaReloadTime", "vttablet keeps table schemas in its own memory and periodically refreshes it from MySQL. This config controls the reload time.", se.ticks.Interval) | ||
se.tableFileSizeGauge = env.Exporter().NewGaugesWithSingleLabel("TableFileSize", "tracks table file size", "Table") | ||
se.tableAllocatedSizeGauge = env.Exporter().NewGaugesWithSingleLabel("TableAllocatedSize", "tracks table allocated size", "Table") | ||
se.innoDbReadRowsGauge = env.Exporter().NewGaugesWithSingleLabel("InnodbRowsRead", "number of rows read by mysql", "Database") | ||
|
||
env.Exporter().HandleFunc("/debug/schema", se.handleDebugSchema) | ||
env.Exporter().HandleFunc("/schemaz", func(w http.ResponseWriter, r *http.Request) { | ||
|
@@ -290,9 +292,7 @@ func (se *Engine) ReloadAt(ctx context.Context, pos mysql.Position) error { | |
|
||
// reload reloads the schema. It can also be used to initialize it. | ||
func (se *Engine) reload(ctx context.Context) error { | ||
//start := time.Now() | ||
defer func() { | ||
//log.Infof("Time taken to load the schema: %v", time.Since(start)) | ||
se.env.LogError() | ||
}() | ||
|
||
|
@@ -316,6 +316,11 @@ func (se *Engine) reload(ctx context.Context) error { | |
return err | ||
} | ||
|
||
err = se.updateInnoDBRowsRead(ctx, conn) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
rec := concurrency.AllErrorRecorder{} | ||
// curTables keeps track of tables in the new snapshot so we can detect what was dropped. | ||
curTables := map[string]bool{"dual": true} | ||
|
@@ -388,6 +393,23 @@ func (se *Engine) reload(ctx context.Context) error { | |
return nil | ||
} | ||
|
||
func (se *Engine) updateInnoDBRowsRead(ctx context.Context, conn *connpool.DBConn) error { | ||
readRowsData, err := conn.Exec(ctx, "show status like 'Innodb_rows_read'", 10, false) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(readRowsData.Rows) == 1 && len(readRowsData.Rows[0]) == 2 { | ||
value, err := evalengine.ToInt64(readRowsData.Rows[0][1]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
se.innoDbReadRowsGauge.Set("read_rows", value) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should log a message or return an error if the condition is not met. |
||
return nil | ||
} | ||
|
||
func (se *Engine) mysqlTime(ctx context.Context, conn *connpool.DBConn) (int64, error) { | ||
// Keep `SELECT UNIX_TIMESTAMP` is in uppercase because binlog server queries are case sensitive and expect it to be so. | ||
tm, err := conn.Exec(ctx, "SELECT UNIX_TIMESTAMP()", 1, false) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a label? Why can't we simply use
NewGauge
?