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

chore: Propose additional debug logging #2243

Merged
merged 4 commits into from
Dec 11, 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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ Some links that might help you:
- **If you are an enterprise customer**, reach out to your account team. This helps us prioritize issues.
- The [issues section](https://github.com/Snowflake-Labs/terraform-provider-snowflake/issues) might already have an issue addressing your question.

## Additional debug logs for `snowflake_grant_privileges_to_role` resource
Set environment variable `SF_TF_ADDITIONAL_DEBUG_LOGGING` to a non-empty value. Additional logs will be visible with `sf-tf-additional-debug` prefix, e.g.:
```text
2023/12/08 12:58:22.497078 sf-tf-additional-debug [DEBUG] Creating new client from db
```

## Contributing

Cf. [Contributing](./CONTRIBUTING.md).
20 changes: 20 additions & 0 deletions pkg/internal/logging/debug_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package logging

import (
"io"
"log"
"os"
)

func init() {
additionalDebugLoggingEnabled = os.Getenv("SF_TF_ADDITIONAL_DEBUG_LOGGING") != ""
DebugLogger = log.New(os.Stderr, "sf-tf-additional-debug ", log.LstdFlags|log.Lmsgprefix|log.LUTC|log.Lmicroseconds)
if !additionalDebugLoggingEnabled {
DebugLogger.SetOutput(io.Discard)
}
}

var (
additionalDebugLoggingEnabled bool
DebugLogger *log.Logger
)
58 changes: 57 additions & 1 deletion pkg/resources/grant_privileges_to_role.go

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions pkg/resources/schema_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import (
"strings"
"testing"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/terraform"

acc "github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/acceptance"
"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk"
"github.com/hashicorp/terraform-plugin-testing/config"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/hashicorp/terraform-plugin-testing/tfversion"
)

Expand Down
15 changes: 14 additions & 1 deletion pkg/sdk/grants_impl.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package sdk

import "context"
import (
"context"

"github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/internal/logging"
)

var _ Grants = (*grants)(nil)

Expand All @@ -9,22 +13,26 @@ type grants struct {
}

func (v *grants) GrantPrivilegesToAccountRole(ctx context.Context, privileges *AccountRoleGrantPrivileges, on *AccountRoleGrantOn, role AccountObjectIdentifier, opts *GrantPrivilegesToAccountRoleOptions) error {
logging.DebugLogger.Printf("[DEBUG] Grant privileges to account role")
if opts == nil {
opts = &GrantPrivilegesToAccountRoleOptions{}
}
opts.privileges = privileges
opts.on = on
opts.accountRole = role
logging.DebugLogger.Printf("[DEBUG] Grant privileges to account role: opts %+v", opts)
return validateAndExec(v.client, ctx, opts)
}

func (v *grants) RevokePrivilegesFromAccountRole(ctx context.Context, privileges *AccountRoleGrantPrivileges, on *AccountRoleGrantOn, role AccountObjectIdentifier, opts *RevokePrivilegesFromAccountRoleOptions) error {
logging.DebugLogger.Printf("[DEBUG] Revoke privileges from account role")
if opts == nil {
opts = &RevokePrivilegesFromAccountRoleOptions{}
}
opts.privileges = privileges
opts.on = on
opts.accountRole = role
logging.DebugLogger.Printf("[DEBUG] Revoke privileges from account role: opts %+v", opts)
return validateAndExec(v.client, ctx, opts)
}

Expand Down Expand Up @@ -76,14 +84,19 @@ func (v *grants) GrantOwnership(ctx context.Context, on OwnershipGrantOn, to Own
}

func (v *grants) Show(ctx context.Context, opts *ShowGrantOptions) ([]Grant, error) {
logging.DebugLogger.Printf("[DEBUG] Show grants")
if opts == nil {
opts = &ShowGrantOptions{}
}

logging.DebugLogger.Printf("[DEBUG] Show grants: opts %+v", opts)
dbRows, err := validateAndQuery[grantRow](v.client, ctx, opts)
logging.DebugLogger.Printf("[DEBUG] Show grants: query finished err = %v", err)
if err != nil {
return nil, err
}
logging.DebugLogger.Printf("[DEBUG] Show grants: converting rows")
resultList := convertRows[grantRow, Grant](dbRows)
logging.DebugLogger.Printf("[DEBUG] Show grants: rows converted")
return resultList, nil
}
2 changes: 1 addition & 1 deletion pkg/sdk/tables_dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ type TableExternalTableColumnRenameActionRequest struct {
}

type TableExternalTableColumnDropActionRequest struct {
Columns []string //required
Columns []string // required
IfExists *bool
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/sdk/tables_dto_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,20 +673,20 @@ func (s *DropTableRequest) WithRestrict(restrict *bool) *DropTableRequest {
}

func NewTableAddRowAccessPolicyRequest(
RowAccessPolicy SchemaObjectIdentifier,
On []string,
rowAccessPolicy SchemaObjectIdentifier,
on []string,
) *TableAddRowAccessPolicyRequest {
s := TableAddRowAccessPolicyRequest{}
s.RowAccessPolicy = RowAccessPolicy
s.On = On
s.RowAccessPolicy = rowAccessPolicy
s.On = on
return &s
}

func NewTableDropRowAccessPolicyRequest(
RowAccessPolicy SchemaObjectIdentifier,
rowAccessPolicy SchemaObjectIdentifier,
) *TableDropRowAccessPolicyRequest {
s := TableDropRowAccessPolicyRequest{}
s.RowAccessPolicy = RowAccessPolicy
s.RowAccessPolicy = rowAccessPolicy
return &s
}

Expand Down
Loading