go: sqle/dprocedures: Implement operational inspection hook, dolt_thread_dump stored procedure.

This commit is contained in:
Aaron Son
2025-04-01 14:14:10 -07:00
parent 11703eaa67
commit a20f97458a
4 changed files with 69 additions and 0 deletions
@@ -0,0 +1,29 @@
// Copyright 2025 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package dprocedures
import (
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/dolt/go/libraries/utils/goroutinedump"
)
func doltThreadDump(ctx *sql.Context, args ...string) (sql.RowIter, error) {
dump, err := goroutinedump.DumpGoRoutines()
if err != nil {
return nil, err
}
return rowToIter(dump), nil
}
@@ -37,6 +37,7 @@ var DoltProcedures = []sql.ExternalStoredProcedureDetails{
{Name: "dolt_rebase", Schema: doltRebaseProcedureSchema, Function: doltRebase},
{Name: "dolt_gc", Schema: int64Schema("status"), Function: doltGC, ReadOnly: true, AdminOnly: true},
{Name: "dolt_thread_dump", Schema: stringSchema("thread_dump"), Function: doltThreadDump, ReadOnly: true, AdminOnly: true},
{Name: "dolt_merge", Schema: doltMergeSchema, Function: doltMerge},
{Name: "dolt_pull", Schema: doltPullSchema, Function: doltPull, AdminOnly: true},
@@ -0,0 +1,32 @@
// Copyright 2025 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package goroutinedump
import (
"bytes"
"runtime/pprof"
)
// Returns a potentially-large string containing stack traces of all
// the goroutines in the running program. Relies on `runtime/pprof` to
// get the stack traces.
func DumpGoRoutines() (string, error) {
var buf bytes.Buffer
err := pprof.Lookup("goroutine").WriteTo(&buf, 2)
if err != nil {
return "", err
}
return buf.String(), nil
}
+7
View File
@@ -1001,3 +1001,10 @@ send -- "quit;\r"
expect eof
'
}
@test "sql-shell: dolt_thread_dump" {
run dolt sql <<< "call dolt_thread_dump();"
[ $status -eq 0 ]
[[ "$output" =~ "github.com/dolthub/dolt/go" ]] || false
[[ "$output" =~ "github.com/dolthub/go-mysql-server" ]] || false
}