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

feat: Task resource v1 readiness #3113

Merged
merged 14 commits into from
Nov 5, 2024

Conversation

sfc-gh-jcieslak
Copy link
Collaborator

@sfc-gh-jcieslak sfc-gh-jcieslak commented Oct 3, 2024

Changes

  • Mostly done task resource refactor
  • Sweepers test fixed (they always added errors even when they're nil)
  • Minor changes in SDK (find out the bug with alter task and right now we're only supporting upper-cased warehouse names; added that to the field description)
  • Acceptance tests
  • The enabled field is not a three-valued boolean because it created certain issues when updating the task. The task status is very important for their management and working, so I decided to have them as regular boolean values that are either true or false, nothing in between.

Next prs

  • Apply comments from feat: Tasks v1 readiness - SDK part #3086
  • Data source
  • Move some of the logic to SDK
  • Refactor SDK suspend root logic for tasks (and overall suspend logic in SDK/resource)
  • Examples, documentation, and migration guide
  • More test cases for complicated DAG structures to show the resource can handle more complex structures
  • Analyze non-deterministic test cases
  • Refactor task resuming in task resource (most likely with the use of defer) because currently, there may be cases that error can cause tasks to be not resumed.
  • Test and see how the DAG of tasks could be owned by a role other than the one created with Terraform (also with less privileges, only to run the task).
  • Make config without $$ escapes needed
  • Check if more helper functions from user resource could be used in task resource.
  • Check in one acceptance test why finalizer task in show_output is not set (is that Snowflake or mapping error).
  • More tests for calling (as field) - feat: Task resource v1 readiness #3113 (comment)
  • Re-generate and list all the issues with asserts and models
  • check test tasks_gen_integration_test.go:937 (and see why it's non deterministic).
  • Support session paramters

References

Copy link

github-actions bot commented Oct 3, 2024

Integration tests failure for 28bf6a5cb6a95fa2d9cb42a558710bb4ad08ee58

@sfc-gh-jcieslak sfc-gh-jcieslak marked this pull request as ready for review October 4, 2024 09:20
Copy link

github-actions bot commented Oct 4, 2024

Integration tests failure for 62adccb771be11faeea226dd4b4b4c29fcea2833

func (t *TaskResourceAssert) HasAfterIds(ids ...sdk.SchemaObjectIdentifier) *TaskResourceAssert {
t.AddAssertion(assert.ValueSet("after.#", strconv.FormatInt(int64(len(ids)), 10)))
for i, id := range ids {
t.AddAssertion(assert.ValueSet(fmt.Sprintf("after.%d", i), id.FullyQualifiedName()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order shouldn't matter here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHouldn't because the assertion does not have InOrder in name or because Snowflake ordering for alter in non-deterministic?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but that should be resolved in newly added TODO for asserts to generate or create a helper for creating asserts for list with non-deterministic order. Right now, this one work (despite being reliant on order) and I would leave it as is.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's at least add InOrder suffix to the name of the function then (may be added in the next PR)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we discussed this in one of the previous PRs. Snowflake does not guarantee item order, so in general we should compare ID collections, not one by one. For cases where the order matters, we should add a comment about that.

Copy link
Collaborator Author

@sfc-gh-jcieslak sfc-gh-jcieslak Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in: For now, renamed to have InOrder suffix, the limitation of order was added to assert improvements some time ago (it should be in main or in this pr.)

HasSuspendTaskAfterNumFailuresString("2"),
resourceshowoutputassert.TaskShowOutput(t, rootTaskModel.ResourceReference()).
HasSchedule(schedule).
// HasTaskRelations(sdk.TaskRelations{FinalizerTask: &finalizerTaskId}).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about these comments?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm missed them somehow. Uncommented + added asserts to the rest of the steps.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left TODO for the next pr to analyze this more in-depth. For now, I don't see why it's not there. I'll take a look if that's a mapping or Snowflake issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a short analysis, It seems like a bug in Snowflake. For now, I removed this assert and added an entry in our doc about Snowflake improvements. I'll fill it later.

pkg/resources/task_acceptance_test.go Show resolved Hide resolved
pkg/resources/task_acceptance_test.go Show resolved Hide resolved
expectedTaskConfig := strings.ReplaceAll(taskConfig, "$", "")
taskConfigVariableValue := "$" + taskConfig
comment := random.Comment()
condition := `SYSTEM$STREAM_HAS_DATA('MYSTREAM')`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have some test cases for different spaces and new lines for fields with SQL statements.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, in upcoming tests I also wanted to add tests for different kinds of things in as body. I'll link this comment in the desc and apply when testing other as options.

HasConfig(expectedTaskConfig).
HasBudget("").
HasTaskRelations(sdk.TaskRelations{}),
),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls add a test case with external changes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test cases for Finalize and After fields, added TODO for next pr to see what also could be tested

func (t *TaskResourceAssert) HasAfterIds(ids ...sdk.SchemaObjectIdentifier) *TaskResourceAssert {
t.AddAssertion(assert.ValueSet("after.#", strconv.FormatInt(int64(len(ids)), 10)))
for i, id := range ids {
t.AddAssertion(assert.ValueSet(fmt.Sprintf("after.%d", i), id.FullyQualifiedName()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHouldn't because the assertion does not have InOrder in name or because Snowflake ordering for alter in non-deterministic?

pkg/internal/collections/collection_helpers_test.go Outdated Show resolved Hide resolved
pkg/schemas/task_gen.go Show resolved Hide resolved
pkg/resources/task.go Show resolved Hide resolved
pkg/resources/task_acceptance_test.go Show resolved Hide resolved
HasConfig(expectedTaskConfig).
HasBudget("").
HasTaskRelations(sdk.TaskRelations{}),
),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

# Conflicts:
#	pkg/acceptance/bettertestspoc/README.md
#	pkg/acceptance/bettertestspoc/assert/resourceassert/gen/resource_schema_def.go
#	pkg/sdk/sweepers_test.go
Copy link

Integration tests failure for 80ca12e07e4e1b0fa5a0d6a8245c017496fa00cd

Copy link

Integration tests failure for f0514bcb9d530e9f9afcb89bac43b56a59d69254

Copy link

Integration tests failure for ee9583dfa93da2a748b9003843edc1fa844742f4

@sfc-gh-asawicki sfc-gh-asawicki self-requested a review October 16, 2024 07:43
@@ -147,6 +145,7 @@ func TaskToSchema(task *sdk.Task) map[string]any {
taskSchema["config"] = task.Config
taskSchema["budget"] = task.Budget
taskSchema["last_suspended_reason"] = task.LastSuspendedReason
// This is manually edited, please don't re-generate this file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (next PR): please keep this changes after regenerating the file

# Conflicts:
#	pkg/acceptance/bettertestspoc/README.md
#	pkg/acceptance/bettertestspoc/assert/resourceassert/gen/resource_schema_def.go
Copy link

github-actions bot commented Nov 4, 2024

Integration tests failure for 012fb1835c3fceb166f9b81f159e7e09a9af61de

Copy link

github-actions bot commented Nov 4, 2024

Integration tests failure for 90d70469b3b6fadb123d943875b92dac69d6c261

@sfc-gh-jcieslak sfc-gh-jcieslak changed the base branch from main to tasks-v1-readiness November 5, 2024 10:25
@sfc-gh-jcieslak sfc-gh-jcieslak merged commit 0aba5c9 into tasks-v1-readiness Nov 5, 2024
10 of 11 checks passed
@sfc-gh-jcieslak sfc-gh-jcieslak deleted the task-resource-v1-readiness branch November 5, 2024 13:33
sfc-gh-jcieslak added a commit that referenced this pull request Nov 14, 2024
- [x] Apply comments from
#3086
- [x] Check if more helper functions from user resource could be used in
task resource.
- [ ] Apply comments from
#3113
- [x] Cron
#3113 (comment)
- [ ] Resource logic
#3113 (comment)
- [ ] Refactor SDK suspend root logic for tasks (and overall suspend
logic in SDK/resource)
#3113 (comment)
- [ ] Move some of the logic to SDK (if possible)
- [ ]
#3170 (comment)
- [ ] Refactor task resuming in task resource (most likely with the use
of defer) because currently, there may be cases that error can cause
tasks to be not resumed.
- [ ] Tests
- [ ] External changes -
#3113 (comment)
- [ ] Add more complicated DAG structures to show the resource can
handle more complex structures
- [ ] Calling (`as` field) -
#3113 (comment)
- [ ] For showing how the DAG of tasks could be owned by a role other
than the one created with Terraform (also with less privileges, only to
run the task).
- [ ] Check in one acceptance test why finalizer task in show_output is
not set (is that Snowflake or mapping error).
- [ ] Data source
- [ ] Examples, documentation, and migration guide
- [ ] Keep manually changed files after regeneration
#3113 (comment)
- [ ] Make config without $$ escapes needed
- [ ] Support session paramters
- [ ] Analyze non-deterministic test cases
- [ ] Check test tasks_gen_integration_test.go:937 (and see why it's non
deterministic).
- [ ] Re-generate and list all the issues with asserts and models
sfc-gh-jcieslak added a commit that referenced this pull request Nov 18, 2024
## Changes
- Fixed the need to enclose `config` with $$
- Added full datasource support with tests
- Documentation and examples (v1 candidates; added for resource and
datasource)
  - Migration guide (now only for datasource)
  - Extracted schema for regular `in` filtering
- Describe wasn't added on purpose, because it seems to mirror values
from what we get from the SHOW command (can also add it, but for now it
doesn't provide any benefits)


## List from previous prs
- [ ] Apply comments
#3170
- [ ] Apply comments from
#3113
- [x] Cron
#3113 (comment)
- [ ] Resource logic
#3113 (comment)
- [ ] Refactor SDK suspend root logic for tasks (and overall suspend
logic in SDK/resource)
#3113 (comment)
- [ ] Move some of the logic to SDK (if possible)
- [ ]
#3170 (comment)
- [ ] Refactor task resuming in task resource (most likely with the use
of defer) because currently, there may be cases that error can cause
tasks to be not resumed.
- [ ] Tests
- [ ] External changes -
#3113 (comment)
- [ ] Add more complicated DAG structures to show the resource can
handle more complex structures
- [ ] Calling (`as` field) -
#3113 (comment)
- [ ] For showing how the DAG of tasks could be owned by a role other
than the one created with Terraform (also with less privileges, only to
run the task).
- [x] Check in one acceptance test why finalizer task in show_output is
not set (is that Snowflake or mapping error).
- [x] Data source
- [ ] Examples, documentation, and migration guide
- [ ] Keep manually changed files after regeneration
#3113 (comment)
- [x] Make config without $$ escapes needed
- [ ] Support session paramters
- [ ] Analyze non-deterministic test cases
- [ ] Check test tasks_gen_integration_test.go:937 (and see why it's non
deterministic).
- [ ] Re-generate and list all the issues with asserts and models
sfc-gh-jcieslak added a commit that referenced this pull request Nov 25, 2024
- [x] Apply comments from
#3113
- [x] Cron
#3113 (comment)
- [x] Resource logic
#3113 (comment)
- [x] Refactor SDK suspend root logic for tasks (and overall suspend
logic in SDK/resource)
#3113 (comment)
- [x] Tests
- [x] External changes -
#3113 (comment)
- [x] Add more complicated DAG structures to show the resource can
handle more complex structures
- [x] Calling (`as` field) -
#3113 (comment)
- [x] Check in one acceptance test why the finalizer task in show_output
is not set (is that Snowflake or mapping error).
- [x] Data source
- [x] Examples, documentation, and migration guide
- [x] Keep manually changed files after regeneration
#3113 (comment)
- [x] Make config without $$ escapes needed
- [x] Support session parameters (I think it's already done, but check
https://docs.snowflake.com/en/sql-reference/parameters#label-session-parameters)
- [x] Refactor task resuming in task resource (most likely with the use
of defer) because currently, there may be cases that error can cause
tasks to be not resumed.
- [x] Analyze non-deterministic test cases (All tests seem to be
deterministic, only object_parameter resource tests are causing the
AllParameters test to fail)
- [x] Check test tasks_gen_integration_test.go:937 (and see why it's
non-deterministic).
- [x] Move some of the logic to SDK (if possible)
- [x]
#3170 (comment)
- [x] Apply comments
#3170
- [ ] Re-generate and list all the issues with asserts and models
sfc-gh-jcieslak added a commit that referenced this pull request Nov 26, 2024
Pr that collects all the changes to tasks from previous prs:
-
#3202
-
#3170
-
#3113

**Note**: look at the last commit, added very small changes to
documentation and code (around 8 lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants