winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.97k stars 196 forks source link

winglibs: checks will be be called at the wrong time on deploy #5205

Open skorfmann opened 9 months ago

skorfmann commented 9 months ago

I tried this:

add a winglib check and use it with tf-aws for smoke tests

This happened:

only when a dependency of the check is changed, the check is executed at the right time in the terraform apply phase

Direct check dependency change

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place
 <= read (data resources)

Terraform will perform the following actions:

  # data.aws_lambda_invocation.Testam7SU1BD2X_env0_smokeTestsSmokeTests_checksCheck_cloudOnDeploy_Invocation_0A69D58B will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "aws_lambda_invocation" "Testam7SU1BD2X_env0_smokeTestsSmokeTests_checksCheck_cloudOnDeploy_Invocation_0A69D58B" {
      + function_name = "Function-c80746ea"
      + id            = (known after apply)
      + input         = jsonencode({})
      + result        = (known after apply)
    }

  # aws_lambda_function.Testam7SU1BD2X_env0_smokeTestsSmokeTests_checksCheck_cloudOnDeploy_Function_2BF3C38B will be updated in-place
  ~ resource "aws_lambda_function" "Testam7SU1BD2X_env0_smokeTestsSmokeTests_checksCheck_cloudOnDeploy_Function_2BF3C38B" {
        id                             = "Function-c80746ea"
      ~ memory_size                    = 1024 -> 2048
      ~ qualified_arn                  = "arn:aws:lambda:us-east-1:207534322588:function:Function-c80746ea:1" -> (known after apply)
      ~ qualified_invoke_arn           = "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:207534322588:function:Function-c80746ea:1/invocations" -> (known after apply)
        tags                           = {}
      ~ version                        = "1" -> (known after apply)
        # (19 unchanged attributes hidden)

        # (3 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_lambda_function.Testam7SU1BD2X_env0_smokeTestsSmokeTests_checksCheck_cloudOnDeploy_Function_2BF3C38B: Modifying... [id=Function-c80746ea]
aws_lambda_function.Testam7SU1BD2X_env0_smokeTestsSmokeTests_checksCheck_cloudOnDeploy_Function_2BF3C38B: Modifications complete after 7s [id=Function-c80746ea]
data.aws_lambda_invocation.Testam7SU1BD2X_env0_smokeTestsSmokeTests_checksCheck_cloudOnDeploy_Invocation_0A69D58B: Reading...
data.aws_lambda_invocation.Testam7SU1BD2X_env0_smokeTestsSmokeTests_checksCheck_cloudOnDeploy_Invocation_0A69D58B: Read complete after 2s [id=Function-c80746ea_$LATEST_99914b932bd37a50b983c5e7c90ae93b]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Unrelated resources changed

it's executed in the planning stage, not after all resources were applied

...
data.aws_lambda_invocation.Testam7SU1BD2X_env0_smokeTestsSmokeTests_checksCheck_cloudOnDeploy_Invocation_0A69D58B: Reading...
...
data.aws_lambda_invocation.Testam7SU1BD2X_env0_smokeTestsSmokeTests_checksCheck_cloudOnDeploy_Invocation_0A69D58B: Read complete after 1s [id=Function-c80746ea_$LATEST_99914b932bd37a50b983c5e7c90ae93b]
...

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_lambda_function.Testam7SU1BD2X_env0_smokeTestsSmokeTests_checksCheck_run_F9817624 will be updated in-place
  ~ resource "aws_lambda_function" "Testam7SU1BD2X_env0_smokeTestsSmokeTests_checksCheck_run_F9817624" {
        id                             = "run-c8308ede"
      ~ memory_size                    = 1024 -> 2048
      ~ qualified_arn                  = "arn:aws:lambda:us-east-1:207534322588:function:run-c8308ede:1" -> (known after apply)
      ~ qualified_invoke_arn           = "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:207534322588:function:run-c8308ede:1/invocations" -> (known after apply)
        tags                           = {}
      ~ version                        = "1" -> (known after apply)
        # (19 unchanged attributes hidden)

        # (3 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_lambda_function.Testam7SU1BD2X_env0_smokeTestsSmokeTests_checksCheck_run_F9817624: Modifying... [id=run-c8308ede]
aws_lambda_function.Testam7SU1BD2X_env0_smokeTestsSmokeTests_checksCheck_run_F9817624: Modifications complete after 7s [id=run-c8308ede]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Outputs:

I expected this:

can use checks as a smoke test

Is there a workaround?

create manual dependencies, but that's really awkward.

Anything else?

No response

Wing Version

0.51.21

Node.js Version

18.7

Platform(s)

MacOS

Community Notes

skorfmann commented 9 months ago

it's executed in the planning stage, not after all resources were applied

this could be fixed by using a null resource / terraform data which triggers on each run. However, it would still run at any time the resource dependencies would be fulfilled. It's still not straightforward to run this at the very end of the apply run.

For this being usable as a smoke test concept, it could be invoked via the wing cli similar to tests.

skorfmann commented 9 months ago

well, thinking about this again maybe the better way would be to use cloudwatch alarams to monitor for the check functions response codes. Then in a separate step wait for a a few minutes and then check the status of cloudwatch alarms.

Also, perhaps a dedicated cloudwatch synthetics Check cloud be useful https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Synthetics_Canaries.html

eladb commented 9 months ago

I am wondering if the issue is with cloud.OnDeploy. @Chriscbr, thoughts?

github-actions[bot] commented 7 months ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!