Skip to content
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

Runtime: Debug logs for identifying intermittent query failure #3722

Merged
merged 4 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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: 4 additions & 0 deletions runtime/reconcilers/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ func (r *ModelReconciler) Reconcile(ctx context.Context, n *runtimev1.ResourceNa
createErr := r.createModel(ctx, self, stagingTableName, !materialize)
if createErr != nil {
createErr = fmt.Errorf("failed to create model: %w", createErr)
} else if !r.C.Runtime.AllowHostAccess() {
// temporarily for debugging
logTableNameAndType(ctx, r.C, connector, stagingTableName)
}

if createErr == nil && stage {
// Rename the staging table to main view/table
err = olapForceRenameTable(ctx, r.C, connector, stagingTableName, !materialize, tableName)
Expand Down
4 changes: 4 additions & 0 deletions runtime/reconcilers/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ func (r *SourceReconciler) Reconcile(ctx context.Context, n *runtimev1.ResourceN
ingestErr := r.ingestSource(ctx, src.Spec, stagingTableName)
if ingestErr != nil {
ingestErr = fmt.Errorf("failed to ingest source: %w", ingestErr)
} else if !r.C.Runtime.AllowHostAccess() {
// temporarily for debugging
logTableNameAndType(ctx, r.C, connector, stagingTableName)
}

if ingestErr == nil && src.Spec.StageChanges {
// Rename staging table to main table
err = olapForceRenameTable(ctx, r.C, connector, stagingTableName, false, tableName)
Expand Down
30 changes: 30 additions & 0 deletions runtime/reconcilers/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/rilldata/rill/runtime"
"github.com/rilldata/rill/runtime/drivers"
"github.com/robfig/cron/v3"
"golang.org/x/exp/slog"
)

// checkRefs checks that all refs exist, are idle, and have no errors.
Expand Down Expand Up @@ -154,3 +155,32 @@ func safeSQLName(name string) string {
}
return fmt.Sprintf("\"%s\"", strings.ReplaceAll(name, "\"", "\"\""))
}

func logTableNameAndType(ctx context.Context, c *runtime.Controller, connector, name string) {
olap, release, err := c.AcquireOLAP(ctx, connector)
if err != nil {
c.Logger.Error("LogTableNameAndType: failed to acquire OLAP", slog.Any("err", err))
return
}
defer release()

res, err := olap.Execute(context.Background(), &drivers.Statement{Query: "SELECT column_name, data_type FROM information_schema.columns WHERE table_name=? ORDER BY column_name ASC", Args: []any{name}})
if err != nil {
c.Logger.Error("LogTableNameAndType: failed information_schema.columns", slog.Any("err", err))
return
}
defer res.Close()

colTyp := make([]string, 0)
var col, typ string
for res.Next() {
err = res.Scan(&col, &typ)
if err != nil {
c.Logger.Error("LogTableNameAndType: failed scan", slog.Any("err", err))
return
}
colTyp = append(colTyp, fmt.Sprintf("%s:%s", col, typ))
}

c.Logger.Info("LogTableNameAndType: ", slog.String("name", name), slog.String("schema", strings.Join(colTyp, ", ")))
}