Skip to content

Commit

Permalink
add explanation for cache hit and if action is needed
Browse files Browse the repository at this point in the history
  • Loading branch information
encima committed Apr 10, 2024
1 parent 4a3e67c commit 4cbc384
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
18 changes: 16 additions & 2 deletions internal/inspect/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,23 @@ func Run(ctx context.Context, config pgconn.Config, fsys afero.Fs, options ...fu
return err
}
// TODO: implement a markdown table marshaller
table := "|Name|Ratio|\n|-|-|\n"
table := "|Name|Ratio|OK?|Explanation|\n|-|-|-|-|\n"
for _, r := range result {

Check failure on line 37 in internal/inspect/cache/cache.go

View workflow job for this annotation

GitHub Actions / Lint

unnecessary leading newline (whitespace)
table += fmt.Sprintf("|`%s`|`%.6f`|\n", r.Name, r.Ratio)

ok := "Yup!"
if r.Ratio < 0.94 {
ok = "Maybe not..."
}
var explanation string
if r.Name == "index hit rate" {
explanation = "This is the ratio of index hits to index scans. If this ratio is low, it means that the database is not using indexes effectively. Check the `index-usage` command for more info."
} else if r.Name == "table hit rate" {
explanation = "This is the ratio of table hits to table scans. If this ratio is low, it means that your queries are not finding the data effectively. Check your query performance and it might be worth increasing your compute."

}

Check failure on line 49 in internal/inspect/cache/cache.go

View workflow job for this annotation

GitHub Actions / Lint

unnecessary trailing newline (whitespace)

table += fmt.Sprintf("|`%s`|`%.6f`|`%s`|`%s`|\n", r.Name, r.Ratio, ok, explanation)

}

Check failure on line 53 in internal/inspect/cache/cache.go

View workflow job for this annotation

GitHub Actions / Lint

unnecessary trailing newline (whitespace)
return list.RenderTable(table)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Run(ctx context.Context, config pgconn.Config, fsys afero.Fs, options ...fu
if err != nil {
return err
}
rows, err := conn.Query(ctx, inspect.LONG_RUNNIN_QUERY)
rows, err := conn.Query(ctx, inspect.LONG_RUNNING_QUERY)
if err != nil {
return errors.Errorf("failed to query rows: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/inspect/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ AND pg_locks.pid=pg_stat_activity.pid
AND pg_locks.mode = 'ExclusiveLock'
ORDER BY query_start`

const LONG_RUNNIN_QUERY = `SELECT
const LONG_RUNNING_QUERY = `SELECT
pid,
now() - pg_stat_activity.query_start AS duration,
query AS query
Expand Down

0 comments on commit 4cbc384

Please sign in to comment.