Adding the debug bar logic in the server (#22410)
* Adding debugbar layer * Adding sql debugbar info * Make duration consistent across the debugbar lines * Adding the debugbar/systeminfo endpoint * Adding logs to the debugbar * Improve the debugbar logger fields info * Improving the debug bar architecture * Allow to enable/disable debugbar in the backend * Exposing the Debug Bar enable in the client config * Adding more system information to the debugbar * Adding params info to the store layer * Organizing a bit the debugbar code in the server and adding some extra data to the system info api * Adding debugbar email traces * Changing the socket event name to 'debugbar' * Adding explain support for the debugbar * Adding missed file * Omitting data related to the debugbar itself * Removing unneeded functions * Avoid arbitrary execution in explain api * Moving debugbar inside the platform directory * Replacing debugbar logger with a new logger Target * Removed uneeded changes * Fixing some linter errors * Adding a debugbar log level to use it later for log events strictly related to the debug bar * Fixing linter errors * Fixing tests * Adding i18n strings
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ebb160b081
Коммит
280bc7f97e
@@ -64,15 +64,17 @@ var namedParamRegex = regexp.MustCompile(`:\w+`)
|
||||
|
||||
type sqlxDBWrapper struct {
|
||||
*sqlx.DB
|
||||
queryTimeout time.Duration
|
||||
trace bool
|
||||
queryTimeout time.Duration
|
||||
trace bool
|
||||
debugbarPublish func(string, float64, ...any)
|
||||
}
|
||||
|
||||
func newSqlxDBWrapper(db *sqlx.DB, timeout time.Duration, trace bool) *sqlxDBWrapper {
|
||||
func newSqlxDBWrapper(db *sqlx.DB, timeout time.Duration, trace bool, debugbarPublish func(string, float64, ...any)) *sqlxDBWrapper {
|
||||
return &sqlxDBWrapper{
|
||||
DB: db,
|
||||
queryTimeout: timeout,
|
||||
trace: trace,
|
||||
DB: db,
|
||||
queryTimeout: timeout,
|
||||
trace: trace,
|
||||
debugbarPublish: debugbarPublish,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +88,7 @@ func (w *sqlxDBWrapper) Beginx() (*sqlxTxWrapper, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return newSqlxTxWrapper(tx, w.queryTimeout, w.trace), nil
|
||||
return newSqlxTxWrapper(tx, w.queryTimeout, w.trace, w.debugbarPublish), nil
|
||||
}
|
||||
|
||||
func (w *sqlxDBWrapper) BeginXWithIsolation(opts *sql.TxOptions) (*sqlxTxWrapper, error) {
|
||||
@@ -95,7 +97,7 @@ func (w *sqlxDBWrapper) BeginXWithIsolation(opts *sql.TxOptions) (*sqlxTxWrapper
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return newSqlxTxWrapper(tx, w.queryTimeout, w.trace), nil
|
||||
return newSqlxTxWrapper(tx, w.queryTimeout, w.trace, w.debugbarPublish), nil
|
||||
}
|
||||
|
||||
func (w *sqlxDBWrapper) Get(dest any, query string, args ...any) error {
|
||||
@@ -108,6 +110,11 @@ func (w *sqlxDBWrapper) Get(dest any, query string, args ...any) error {
|
||||
printArgs(query, time.Since(then), args)
|
||||
}(time.Now())
|
||||
}
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.DB.GetContext(ctx, dest, query, args...)
|
||||
}
|
||||
@@ -134,6 +141,12 @@ func (w *sqlxDBWrapper) NamedExec(query string, arg any) (sql.Result, error) {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), arg)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.DB.NamedExecContext(ctx, query, arg)
|
||||
}
|
||||
|
||||
@@ -161,6 +174,12 @@ func (w *sqlxDBWrapper) ExecNoTimeout(query string, args ...any) (sql.Result, er
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.DB.ExecContext(context.Background(), query, args...)
|
||||
}
|
||||
|
||||
@@ -176,6 +195,12 @@ func (w *sqlxDBWrapper) ExecRaw(query string, args ...any) (sql.Result, error) {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.DB.ExecContext(ctx, query, args...)
|
||||
}
|
||||
|
||||
@@ -192,6 +217,12 @@ func (w *sqlxDBWrapper) NamedQuery(query string, arg any) (*sqlx.Rows, error) {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), arg)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.DB.NamedQueryContext(ctx, query, arg)
|
||||
}
|
||||
|
||||
@@ -206,6 +237,12 @@ func (w *sqlxDBWrapper) QueryRowX(query string, args ...any) *sqlx.Row {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.DB.QueryRowxContext(ctx, query, args...)
|
||||
}
|
||||
|
||||
@@ -220,6 +257,12 @@ func (w *sqlxDBWrapper) QueryX(query string, args ...any) (*sqlx.Rows, error) {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.DB.QueryxContext(ctx, query, args)
|
||||
}
|
||||
|
||||
@@ -238,6 +281,12 @@ func (w *sqlxDBWrapper) SelectCtx(ctx context.Context, dest any, query string, a
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.DB.SelectContext(ctx, dest, query, args...)
|
||||
}
|
||||
|
||||
@@ -252,15 +301,17 @@ func (w *sqlxDBWrapper) SelectBuilder(dest any, builder Builder) error {
|
||||
|
||||
type sqlxTxWrapper struct {
|
||||
*sqlx.Tx
|
||||
queryTimeout time.Duration
|
||||
trace bool
|
||||
queryTimeout time.Duration
|
||||
trace bool
|
||||
debugbarPublish func(string, float64, ...any)
|
||||
}
|
||||
|
||||
func newSqlxTxWrapper(tx *sqlx.Tx, timeout time.Duration, trace bool) *sqlxTxWrapper {
|
||||
func newSqlxTxWrapper(tx *sqlx.Tx, timeout time.Duration, trace bool, debugbarPublish func(string, float64, ...any)) *sqlxTxWrapper {
|
||||
return &sqlxTxWrapper{
|
||||
Tx: tx,
|
||||
queryTimeout: timeout,
|
||||
trace: trace,
|
||||
Tx: tx,
|
||||
queryTimeout: timeout,
|
||||
trace: trace,
|
||||
debugbarPublish: debugbarPublish,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,6 +326,12 @@ func (w *sqlxTxWrapper) Get(dest any, query string, args ...any) error {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.Tx.GetContext(ctx, dest, query, args...)
|
||||
}
|
||||
|
||||
@@ -302,6 +359,12 @@ func (w *sqlxTxWrapper) ExecNoTimeout(query string, args ...any) (sql.Result, er
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.Tx.ExecContext(context.Background(), query, args...)
|
||||
}
|
||||
|
||||
@@ -326,6 +389,12 @@ func (w *sqlxTxWrapper) ExecRaw(query string, args ...any) (sql.Result, error) {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.Tx.ExecContext(ctx, query, args...)
|
||||
}
|
||||
|
||||
@@ -342,6 +411,12 @@ func (w *sqlxTxWrapper) NamedExec(query string, arg any) (sql.Result, error) {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), arg)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.Tx.NamedExecContext(ctx, query, arg)
|
||||
}
|
||||
|
||||
@@ -358,6 +433,12 @@ func (w *sqlxTxWrapper) NamedQuery(query string, arg any) (*sqlx.Rows, error) {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), arg)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
// There is no tx.NamedQueryContext support in the sqlx API. (https://github.com/jmoiron/sqlx/issues/447)
|
||||
// So we need to implement this ourselves.
|
||||
type result struct {
|
||||
@@ -400,6 +481,12 @@ func (w *sqlxTxWrapper) QueryRowX(query string, args ...any) *sqlx.Row {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.Tx.QueryRowxContext(ctx, query, args...)
|
||||
}
|
||||
|
||||
@@ -414,6 +501,12 @@ func (w *sqlxTxWrapper) QueryX(query string, args ...any) (*sqlx.Rows, error) {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.Tx.QueryxContext(ctx, query, args)
|
||||
}
|
||||
|
||||
@@ -428,6 +521,12 @@ func (w *sqlxTxWrapper) Select(dest any, query string, args ...any) error {
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
if w.debugbarPublish != nil {
|
||||
defer func(then time.Time) {
|
||||
w.debugbarPublish(query, float64(time.Since(then))/float64(time.Second), args...)
|
||||
}(time.Now())
|
||||
}
|
||||
|
||||
return w.Tx.SelectContext(ctx, dest, query, args...)
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user