Skip to content

Commit

Permalink
database_observability: fix fetch table columns spec
Browse files Browse the repository at this point in the history
Fix nil pointer dereference by always returning the table object on
error.
  • Loading branch information
cristiangreco committed Feb 12, 2025
1 parent 77d7573 commit c3a6575
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,20 +320,20 @@ func (c *SchemaTable) fetchTableDefinitions(ctx context.Context, fullyQualifiedT
row := c.dbConnection.QueryRowContext(ctx, showCreateTable+" "+fullyQualifiedTable)
if err := row.Err(); err != nil {
level.Error(c.logger).Log("msg", "failed to show create table", "schema", table.schema, "table", table.tableName, "err", err)
return nil, row.Err()
return table, err
}

var tableName, createStmt, characterSetClient, collationConnection string
switch table.tableType {
case "BASE TABLE":
if err := row.Scan(&tableName, &createStmt); err != nil {
level.Error(c.logger).Log("msg", "failed to scan create table", "schema", table.schema, "table", table.tableName, "err", err)
return nil, err
return table, err
}
case "VIEW":
if err := row.Scan(&tableName, &createStmt, &characterSetClient, &collationConnection); err != nil {
level.Error(c.logger).Log("msg", "failed to scan create view", "schema", table.schema, "table", table.tableName, "err", err)
return nil, err
return table, err
}
default:
level.Error(c.logger).Log("msg", "unknown table type", append(logKVs, "table_type", table.tableType))

Check failure on line 339 in internal/component/database_observability/mysql/collector/schema_table.go

View workflow job for this annotation

GitHub Actions / Test (Mac) (macos-latest-xlarge)

undefined: logKVs

Check failure on line 339 in internal/component/database_observability/mysql/collector/schema_table.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: logKVs

Check failure on line 339 in internal/component/database_observability/mysql/collector/schema_table.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: logKVs

Check failure on line 339 in internal/component/database_observability/mysql/collector/schema_table.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: logKVs

Check failure on line 339 in internal/component/database_observability/mysql/collector/schema_table.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: logKVs

Check failure on line 339 in internal/component/database_observability/mysql/collector/schema_table.go

View workflow job for this annotation

GitHub Actions / run_tests

undefined: logKVs

Check failure on line 339 in internal/component/database_observability/mysql/collector/schema_table.go

View workflow job for this annotation

GitHub Actions / Test Linux

undefined: logKVs

Check failure on line 339 in internal/component/database_observability/mysql/collector/schema_table.go

View workflow job for this annotation

GitHub Actions / Build on Linux (linux, amd64)

undefined: logKVs

Check failure on line 339 in internal/component/database_observability/mysql/collector/schema_table.go

View workflow job for this annotation

GitHub Actions / Build on Linux (linux, arm64)

undefined: logKVs

Check failure on line 339 in internal/component/database_observability/mysql/collector/schema_table.go

View workflow job for this annotation

GitHub Actions / Build on Linux (linux, ppc64le)

undefined: logKVs

Check failure on line 339 in internal/component/database_observability/mysql/collector/schema_table.go

View workflow job for this annotation

GitHub Actions / Build on Linux (boringcrypto) (linux, amd64)

undefined: logKVs

Check failure on line 339 in internal/component/database_observability/mysql/collector/schema_table.go

View workflow job for this annotation

GitHub Actions / Build on Linux (linux, s390x)

undefined: logKVs

Check failure on line 339 in internal/component/database_observability/mysql/collector/schema_table.go

View workflow job for this annotation

GitHub Actions / Build on Linux (boringcrypto) (linux, arm64)

undefined: logKVs

Check failure on line 339 in internal/component/database_observability/mysql/collector/schema_table.go

View workflow job for this annotation

GitHub Actions / Build on MacOS (ARM)

undefined: logKVs

Check failure on line 339 in internal/component/database_observability/mysql/collector/schema_table.go

View workflow job for this annotation

GitHub Actions / Build on MacOS (Intel)

undefined: logKVs

Check failure on line 339 in internal/component/database_observability/mysql/collector/schema_table.go

View workflow job for this annotation

GitHub Actions / Build on FreeBSD (AMD64)

undefined: logKVs

Check failure on line 339 in internal/component/database_observability/mysql/collector/schema_table.go

View workflow job for this annotation

GitHub Actions / Build on Windows (AMD64)

undefined: logKVs
Expand All @@ -344,12 +344,12 @@ func (c *SchemaTable) fetchTableDefinitions(ctx context.Context, fullyQualifiedT
spec, err := c.fetchColumnsDefinitions(ctx, table.schema, table.tableName)
if err != nil {
level.Error(c.logger).Log("msg", "failed to analyze table spec", "schema", table.schema, "table", table.tableName, "err", err)
return nil, err
return table, err
}
jsonSpec, err := json.Marshal(spec)
if err != nil {
level.Error(c.logger).Log("msg", "failed to marshal table spec", "schema", table.schema, "table", table.tableName, "err", err)
return nil, err
return table, err
}
table.b64TableSpec = base64.StdEncoding.EncodeToString(jsonSpec)

Expand Down

0 comments on commit c3a6575

Please sign in to comment.