-
Notifications
You must be signed in to change notification settings - Fork 189
feat: Adds Stream Processor update support #3180
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial draft review to make sure that the logic makes sense before cleaning up.
processorName = "new-processor" | ||
instanceName = acc.RandomName() | ||
) | ||
func TestAccStreamProcessor_StateTransitionsUpdates(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a whole new test suite since the current config func would be messy to modify for testing all the updates without creating external resources (clusters or kafka). The update that I am check is the pipeline change with tumbling window since this requires no external resources to spin for each of my test case (there are many combinations)
I have three separate test suits for update tests, I remove some of the existing tests here since my new test suits should cover those flows.
The three update suites cover the following:
- Valid state to state updates
- Valid state to empty state updates, it should use the previous state (CREATE state will have CREATE state after the update with empty state).
- Invalid state updates with expected errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really nice abstraction for the tests!
`, projectID, instanceName, processorName, pipeline, state) | ||
} | ||
|
||
func checkConfigAttribute(projectID, instanceName, processorName, state, expectedPipelineStr string) resource.TestCheckFunc { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can rename this checkConfigAttribute
func to have the word update in it or I can merge with the existing composeStreamProcessorChecks
(would complicate that function if I were to do that so I am leaning with a separate function)
@@ -43,6 +43,22 @@ func WaitStateTransition(ctx context.Context, requestParams *admin.GetStreamProc | |||
return nil, errors.New("did not obtain valid result when waiting for stream processor state transition") | |||
} | |||
|
|||
func ValidateUpdateStateTransition(currentState, plannedState string) (errMsg string, isValidTransition bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the validation should live in the state transition? I also added unit tests for this function that may be overkill, I can see the argument to remove or keep so I defer to the team's opinion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to put it here. I like the unit tests for this, it's a nice way to "document" all the possible state transitions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really good job!
@@ -141,7 +128,7 @@ output "stream_processors_results" { | |||
### Optional | |||
|
|||
- `options` (Attributes) Optional configuration for the stream processor. (see [below for nested schema](#nestedatt--options)) | |||
- `state` (String) The state of the stream processor. Commonly occurring states are 'CREATED', 'STARTED', 'STOPPED' and 'FAILED'. Used to start or stop the Stream Processor. Valid values are `CREATED`, `STARTED` or `STOPPED`. When a Stream Processor is created without specifying the state, it will default to `CREATED` state. | |||
- `state` (String) The state of the stream processor. Commonly occurring states are 'CREATED', 'STARTED', 'STOPPED' and 'FAILED'. Used to start or stop the Stream Processor. Valid values are `CREATED`, `STARTED` or `STOPPED`. When a Stream Processor is created without specifying the state, it will default to `CREATED` state. When a Stream Processor is updated without specifying the state, it will default to the Previous state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this detail might not be necessary. The expectation in Terraform is that a non modified attribute will not be changed. Maybe we should mention in a more general level the fact that the stream will be stopped. Maybe something similar to:
**NOTE**: When updating an Atlas Stream Processor, the following behavior applies:
1. If the processor is in a `STARTED` state, it will automatically be stopped before the update is applied
2. The update will be performed while the processor is in `STOPPED` state
3. If the processor was originally in `STARTED` state, it will be restarted after the update
docs team can confirm when they review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about something like this?
***NOTE***: The following behavior applies to an Atlas Stream Processor that is in a STARTED state:
1. The processor will automatically be stopped before the update is applied.
2. The update will be performed while the processor is in a `STOPPED` state.
3. The processor will be restarted after the update if the config state field is empty or set to `STARTED`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this behavior is specific to TF right? Is this something that can be captured in the API spec instead so we can simply add a link here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TF behavior may calling multiple endpoints at once (STOP, GET and MODIFY endpoint). Due to the nature of the stream processor, it can only be modified in the CREATED
or STOPPED
state. I don't think we can have one specific link to a particular endpoint like MODIFY. Perhaps we can add a requirement that the stream processor must be STOPPED before we can modify it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, the client needs to stop, modify, then start again a processor that is running. The update/modify API does not do it. So in TF we are removing this complexity to have a better user experience
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, in that case, I like @oarbusi 's suggestion. Although I'd say we should add it as a separate note to call out what happens during an update instead of adding this note to state
.
For the state
description I think the current one makes sense, maybe rephrase a bit like "When a Stream Processor is updated without specifying the state, it is stopped & then restored to previous state upon update completion."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is now changed with this commit. Can you also take another look @davidhou17 to see if these documentation changes look good?
processorName = "new-processor" | ||
instanceName = acc.RandomName() | ||
) | ||
func TestAccStreamProcessor_StateTransitionsUpdates(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really nice abstraction for the tests!
@@ -43,6 +43,22 @@ func WaitStateTransition(ctx context.Context, requestParams *admin.GetStreamProc | |||
return nil, errors.New("did not obtain valid result when waiting for stream processor state transition") | |||
} | |||
|
|||
func ValidateUpdateStateTransition(currentState, plannedState string) (errMsg string, isValidTransition bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to put it here. I like the unit tests for this, it's a nice way to "document" all the possible state transitions
APIx bot: a message has been sent to Docs Slack channel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
name: "Invalid transition - CREATED to STOPPED", | ||
currentState: CreatedState, | ||
plannedState: StoppedState, | ||
wantErrMsg: "Stream Processor must be in STARTED state to transition to STOPPED state", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message can be a constant that can be used here and in the resource
return fmt.Sprintf("Stream Processor must be in %s state to transition to %s state", StartedState, StoppedState), false | ||
} | ||
|
||
if plannedState == CreatedState && currentState != CreatedState { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any case where the user can manually set the state to "CREATED"? Looks like it would be something that would always be returned from the API, and the user can only update the state to Start/Stop, is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user can also put CREATED
as a state when they first create the resource, so leaving it in the config and changing other areas will trigger an update with the CREATED
state still in place for the update. Leaving it blanks during the creation part also defaults to the CREATED
state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the clarification!
.changelog/3180.txt
Outdated
@@ -0,0 +1,3 @@ | |||
```release-note:enhancement | |||
resource/mongodbatlas_stream_processor: Support modifying a stream processor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resource/mongodbatlas_stream_processor: Support modifying a stream processor | |
resource/mongodbatlas_stream_processor: Support modifying a stream processor |
resource/mongodbatlas_stream_processor: Support modifying a stream processor | |
resource/mongodbatlas_stream_processor: Adds update support |
nit: you can use longer branch names as long as prefixed with ticket in case it helps you to know what the branch is about, e.g. CLOUDP-301766_modify_stream_processor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for addressing the comments!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, minor comment on the note in docs
@@ -2,6 +2,11 @@ | |||
|
|||
`mongodbatlas_stream_processor` describes a stream processor. | |||
|
|||
**NOTE**: When updating an Atlas Stream Processor, the following behavior applies: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the intention was to add this in resource docs right? Within the context of the data source docs this is not too relevant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this was a mistake. I've moved the note to the correct template and regenerated the docs.
👍 |
Description
This PR adds support to modify a stream processor by calling the existing ModifyStreamProcessor endpoint.
I also added a suite of acceptance tests to cover all the possible state transitions. The main behavior is that a stream processor must be in the
CREATED
orSTOPPED
state before it can call the ModifyStreamProcessor endpoint. If the stream processor is currently in aSTARTED
state, it must be stopped before it can be modified.Link to any related issue(s):
CLOUDP-301766
Type of change:
Required Checklist:
Further comments