confluentinc / terraform-provider-confluent

Terraform Provider for Confluent
Apache License 2.0
27 stars 63 forks source link

Forward retryablehttp logs to tflog #374

Closed FabioBatSilva closed 2 months ago

FabioBatSilva commented 6 months ago

This PR is Introducing a adapter that sends retryablehttp logs to tflogs.

Current retryablehttp logs get double formatted by it's logger

{time} [DEBUG] provider.terraform-provider-confluent: {time} [DEBUG] {message}

Inspired by https://github.com/hashicorp/terraform-provider-http/blob/2982166a23c297b6e934c74539cc5e66c5eca056/internal/provider/data_source_http.go#L413-L444

See: https://github.com/pulumi/pulumi-confluentcloud/issues/48. https://github.com/confluentinc/terraform-provider-confluent/issues/372

cla-assistant[bot] commented 6 months ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Fabio Silva seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

cla-assistant[bot] commented 6 months ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Fabio Silva seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

linouk23 commented 6 months ago

@FabioBatSilva thanks for creating the PR!

What would be the best way to test these changes locally? One option I see is checking whether HTTP call logs are no longer double-formatted:

{time} [DEBUG] provider.terraform-provider-confluent: {time} [DEBUG] {message}:

(for example, like the 2nd and the 3rd lines here)

2024-03-18T19:30:33.710-0400 [DEBUG] provider.terraform-provider-confluent: Reading Schema "xxxx-xxxxx/chesscom/xxxx.proto/latest": @module=provider tf_req_id=674347de-096d-5287-519d-d7afc4fbcb45 tf_resource_type=confluent_schema tf_rpc=ReadResource @caller=/terraform/terraform-provider-confluent/internal/provider/resource_schema.go:597 schema_id=xxxx-xxxxx/chesscom/xxxx.proto/latest tf_provider_addr=provider timestamp=2024-03-18T19:30:33.710-0400
2024-03-18T19:30:33.710-0400 [DEBUG] provider.terraform-provider-confluent: 2024/03/18 19:30:33 [DEBUG] GET https://xxxx.gcp.confluent.cloud/subjects/chesscom%2Fxxxx.proto/versions/latest
2024-03-18T19:30:33.941-0400 [DEBUG] provider.terraform-provider-confluent: 2024/03/18 19:30:33 [DEBUG] GET https://xxxx.gcp.confluent.cloud/schemas?subjectPrefix=chesscom%2Fxxxx.proto
2024-03-18T19:30:33.970-0400 [DEBUG] provider.terraform-provider-confluent: Fetched Schemas "xxxx-xxxxx/chesscom/xxxx.proto/latest": [...]: @caller=/terraform/terraform-provider-confluent/internal/provider/resource_schema.go:781 @module=provider schema_id=xxxx-xxxxx/chesscom/xxxx.proto/latest tf_resource_type=confluent_schema tf_rpc=ReadResource tf_provider_addr=provider tf_req_id=674347de-096d-5287-519d-d7afc4fbcb45 timestamp=2024-03-18T19:30:33.970-0400
2024-03-18T19:30:33.970-0400 [DEBUG] provider.terraform-provider-confluent: Fetched Schema "xxxx-xxxxx/chesscom/xxxx.proto/latest": {...}: schema_id=xxxx-xxxxx/chesscom/xxxx.proto/latest tf_provider_addr=provider tf_req_id=674347de-096d-5287-519d-d7afc4fbcb45 tf_rpc=ReadResource @caller=/terraform/terraform-provider-confluent/internal/provider/resource_schema.go:805 @module=provider tf_resource_type=confluent_schema timestamp=2024-03-18T19:30:33.970-0400
2024-03-18T19:30:33.970-0400 [DEBUG] provider.terraform-provider-confluent: Finished reading Schema "xxxx-xxxxx/chesscom/xxxx.proto/latest": tf_req_id=674347de-096d-5287-519d-d7afc4fbcb45 tf_rpc=ReadResource @caller=/terraform/terraform-provider-confluent/internal/provider/resource_schema.go:629 @module=provider schema_id=xxxx-xxxxx/chesscom/xxxx.proto/latest tf_provider_addr=provider tf_resource_type=confluent_schema timestamp=2024-03-18T19:30:33.970-0400
FabioBatSilva commented 6 months ago

Hi, Sorry forgot to include a example

When you run terraform with TF_LOG=DEBUG you should now see something like this :

2024-03-21T13:19:03.178-0400 [DEBUG] provider.terraform-provider-confluent: Reading Schema "xxxx-xxxxx/chesscom/xxxx.proto/latest": tf_provider_addr=provider @module=provider schema_id=xxxx-xxxxx/chesscom/xxxx.proto/latest tf_req_id=09ea3126-9554-ae6b-eb0a-e1972fbc0988 tf_resource_type=confluent_schema tf_rpc=ReadResource @caller=/workspace/terraform/terraform-provider-confluent/internal/provider/resource_schema.go:597 timestamp=2024-03-21T13:19:03.178-0400
2024-03-21T13:19:03.178-0400 [DEBUG] provider.terraform-provider-confluent: performing request: method=GET tf_req_id=c47bb9f6-4de8-0118-2dd0-fb7bbc4861d6 tf_rpc=Configure @caller=/workspace/terraform/terraform-provider-confluent/internal/provider/factory_utils.go:191 @module=provider tf_provider_addr=provider url="map[ForceQuery:false Fragment: Host:xxxx.gcp.confluent.cloud OmitHost:false Opaque: Path:/subjects/chesscom/xxxx.proto/versions/latest RawFragment: RawPath:/subjects/chesscom%2Fxxx.proto/versions/latest RawQuery: Scheme:https User:<nil>]" timestamp=2024-03-21T13:19:03.178-0400
2024-03-21T13:19:03.386-0400 [DEBUG] provider.terraform-provider-confluent: performing request: url="map[ForceQuery:false Fragment: Host:xxxx.gcp.confluent.cloud OmitHost:false Opaque: Path:/schemas RawFragment: RawPath: RawQuery:subjectPrefix=chesscom%2Fxxx.proto Scheme:https User:<nil>]" @module=provider tf_rpc=Configure tf_req_id=c47bb9f6-4de8-0118-2dd0-fb7bbc4861d6 @caller=/workspace/terraform/terraform-provider-confluent/internal/provider/factory_utils.go:191 method=GET tf_provider_addr=provider timestamp=2024-03-21T13:19:03.386-0400
tmalikconfluent commented 2 months ago

Thank you for creating this PR! We've applied this fix internally and released it in the latest 1.81.0 version of TF Provider.