-
Notifications
You must be signed in to change notification settings - Fork 61
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
Write Terraform CLI logs to container stdout #258
Write Terraform CLI logs to container stdout #258
Conversation
Signed-off-by: Katrina Ronquillo <[email protected]>
Signed-off-by: Suvaansh Kumar <[email protected]>
Signed-off-by: Suvaansh Kumar <[email protected]>
Signed-off-by: Katrina Ronquillo <[email protected]>
Signed-off-by: Suresh Ramasamy <[email protected]>
…ging Signed-off-by: Suresh Ramasamy <[email protected]>
Signed-off-by: Suresh Ramasamy <[email protected]>
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.
Hi @suramasamy - thanks for the PR! I took it for a spin and it looks good, just a couple of suggested changes.
apis/v1beta1/workspace_types.go
Outdated
ForProvider WorkspaceParameters `json:"forProvider"` | ||
xpv1.ResourceSpec `json:",inline"` | ||
ForProvider WorkspaceParameters `json:"forProvider"` | ||
EnableTerraformCLILogging bool `json:"enableTerraformCLILogging,omitempty"` |
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 new attribute should be inside the ForProvider structure since it is used by the provider.
cmd/provider/main.go
Outdated
@@ -89,7 +91,7 @@ func main() { | |||
|
|||
// controller-runtime uses both ConfigMaps and Leases for leader | |||
// election by default. Leases expire after 15 seconds, with a | |||
// 10 second renewal deadline. We've observed leader loss due to | |||
// 10 seconds renewal deadline. We've observed leader loss due to |
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 singular is actually ok here - English is a strange language.
docs/monolith/Configuration.md
Outdated
|
||
## Enable Terraform CLI logs | ||
|
||
Terraform CLI logs can be written to the container logs as standard output to assist with debugging and to view detailed information about Terraform operations. |
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.
Terraform CLI logs can be written to the container logs as standard output to assist with debugging and to view detailed information about Terraform operations. | |
Terraform CLI output can be written to the container logs to assist with debugging and to view detailed information about Terraform operations. |
docs/monolith/Configuration.md
Outdated
... | ||
``` | ||
|
||
- `enableTerraformCLILogging`: Specifies whether logging is enabled (`true`) or disabled (`false`). When enabled, Terraform CLI command logs will be written to the container logs as standard output. Default is `false` |
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.
- `enableTerraformCLILogging`: Specifies whether logging is enabled (`true`) or disabled (`false`). When enabled, Terraform CLI command logs will be written to the container logs as standard output. Default is `false` | |
- `enableTerraformCLILogging`: Specifies whether logging is enabled (`true`) or disabled (`false`). When enabled, Terraform CLI command output will be written to the container logs. Default is `false` |
internal/terraform/terraform.go
Outdated
} | ||
case 2: | ||
if h.EnableTerraformCLILogging { | ||
h.Logger.Info(string(log)) |
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.
Would it be useful to the user to prefix the specific command that produced the output in each case - meaning "plan", "apply" or "delete"?
Signed-off-by: Suresh Ramasamy <[email protected]>
Signed-off-by: Suresh Ramasamy <[email protected]>
1c7ed9b
to
3ae263c
Compare
…d Operation key value pair to logs.
3ae263c
to
1d2cf22
Compare
New log Structure: Which includes the {"operation":value} block {"level":"debug","ts":"2024-05-10T16:34:07.437-0400","logger":"provider-terraform","msg":"Reconciling","controller":"providerconfig/providerconfig.tf.upbound.io","request":{"name":"default"}} |
17f560e
to
e0aab2c
Compare
When available, could you please review the PR. We also wanted to discuss if our changes could impact existing users of provider terraform
Will this change impact the format of their container logs? Currently on main, logs are shown in a structured and unstructured format.
With the new change the logs are only structured
|
This almost feels like it should be extrapolated as a provider config option across all providers so you can like opt into all json logging if you want that. Having it as a flag on the workspace feels too low level here. |
Debugging tends to happen at the individual Workspace level so I think it's appropriate to enable/disable logging at that level. |
Hi @bobh66 and @zach-source, I think there is a bit of a miscommunication as there are two separate questions here:
To address the second item, I think an option to select the controller's log format should be introduced. Correct me if I'm wrong, but I don't think the option can be put at the Thoughts? |
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.
Let's separate the logging format changes into a separate PR and make it configurable so we can get the rest of the changes merged. Thanks
cmd/provider/main.go
Outdated
@@ -64,7 +66,7 @@ func main() { | |||
) | |||
kingpin.MustParse(app.Parse(os.Args[1:])) | |||
|
|||
zl := zap.New(zap.UseDevMode(*debug), UseISO8601()) | |||
zl := zap.New(zap.UseDevMode(*debug), UseJSONencoder()) |
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 I agree that the logging format change should be in a separate PR and should be able to be specified as a runtime argument. It should default to the current format to prevent breaking existing deployments and allow for a json option to be specified. If we want to change the default log format in the future we can plan for it and announce it ahead of time, but for now I think it's better not to change the default format.
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.
Hi @bobh66, we reverted the changes for the logging format. Please review them when you get the chance and let us know if you require anything else to get this PR merged!
3a174a1
to
b0723c5
Compare
Signed-off-by: Katrina Ronquillo <[email protected]>
b0723c5
to
04387b3
Compare
Signed-off-by: Katrina Ronquillo <[email protected]>
Signed-off-by: Katrina Ronquillo <[email protected]>
Does it make sense to encapsulate the recurring logic
into the Furthermore it would be nice to emit also a log before the command is executed including the cmd name and all the args. This would help a lot during troubleshooting, because one can reproduce with the exact commands. I think it makes also sense to implement this generally in the What do you think @tammy-young @suramasamy @bobh66 ? |
I know it's late in the game, but it might be worth taking a look at crossplane/crossplane-runtime#754. I like the pattern we landed on for that feature (provider change logs):
This way our change logs aren't mixed in with regular logs. You can easily configure fluent bit or similar to scrape all logs from the sidecar container and do something different with them from regular logs. |
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 - sorry for the delay. We can start with this implementation and make changes as needed. Thanks!
@bobh66 Thanks for merging the changes, Could you please let us know when this planned to be released? |
Description of your changes
Added optional field
enableTerraformCLILogging
to theWorkspace
resource to enable writing of Terraform CLI logs to the container stdout in JSON format to assist with debugging and to view detailed information about Terraform operations.Fixes #163
I have:
make reviewable
to ensure this PR is ready for review.make e2e
with UPTEST_EXAMPLE_LIST="examples/workspace-enable-logging.yaml"How has this code been tested
workspace-enable-logging.yaml
enableTerraformCLILogging
to false, made few other Terraform code changes in the Workspace YAML and re-appliedenableTerraformCLILogging
to true and re-applied the WorkspaceSample Logs:
{"level":"info","ts":"2024-04-10T20:24:04.678Z","logger":"provider-terraform","msg":"\nTerraform used the selected providers to generate the following execution\nplan. Resource actions are indicated with the following symbols:\n + create\n\nTerraform will perform the following actions:\n\n # random_id.example_id will be created\n + resource \"random_id\" \"example_id\" {\n + b64_std = (known after apply)\n + b64_url = (known after apply)\n + byte_length = 7\n + dec = (known after apply)\n + hex = (known after apply)\n + id = (known after apply)\n }\n\n # random_password.password will be created\n + resource \"random_password\" \"password\" {\n + bcrypt_hash = (sensitive value)\n + id = (known after apply)\n + length = 16\n + lower = true\n + min_lower = 0\n + min_numeric = 0\n + min_special = 0\n + min_upper = 0\n + number = true\n + numeric = true\n + result = (sensitive value)\n + special = true\n + upper = true\n }\n\nPlan: 2 to add, 0 to change, 0 to destroy.\n\nChanges to Outputs:\n + random_id_hex = (known after apply)\n + random_password = (sensitive value)\n","request":"example-random-generator"}