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

Add TFC usage detection #1208

Merged
merged 2 commits into from
Mar 14, 2023
Merged

Add TFC usage detection #1208

merged 2 commits into from
Mar 14, 2023

Conversation

jpogran
Copy link
Contributor

@jpogran jpogran commented Mar 9, 2023

This builds on the existing methods to detect remote backend usage and adds detection of cloud blocks in the terraform block.

Closes #912

@jpogran jpogran force-pushed the track_tc_usage branch 6 times, most recently from 61ff41e to a489c84 Compare March 10, 2023 15:25
@jpogran jpogran marked this pull request as ready for review March 10, 2023 15:33
@jpogran jpogran requested a review from a team as a code owner March 10, 2023 15:33
@jpogran jpogran self-assigned this Mar 10, 2023
This builds on the existing methods to detect remote backend usage and adds detection of cloud blocks in the terraform block
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

Aside from that in-line question about how we handle empty/default hostnames, this LGTM and works as expected:

2023/03/13 09:36:22 opts.go:205: Posting server notification "telemetry/event" {"v":1,"name":"moduleData","properties":{"cloud":true,"cloud.hostname":"custom-hostname","moduleId":"d1a79a40-a1df-414d-03ef-d1ff802e721d","tfVersion":"1.4.0"}}

internal/langserver/handlers/hooks_module.go Outdated Show resolved Hide resolved
Comment on lines +53 to +62
// Required for Terraform Enterprise;
// Defaults to app.terraform.io for Terraform Cloud
if hostname == "" {
hostname = "app.terraform.io"
}

// anonymize any non-default hostnames
if hostname != "app.terraform.io" {
hostname = "custom-hostname"
}
Copy link
Member

Choose a reason for hiding this comment

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

This looks slightly inconsistent with how we check & report hostnames below for backends.

I don't have too strong opinion on whether we should be reporting the difference between default and empty (implied default) hostname, but I do think we should approach both the same way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to https://developer.hashicorp.com/terraform/cli/cloud/settings#hostname, hostname is optional, and is an empty string if not specified. Using the same logic as backend would result is us sending an empty string in telemetry, which defeats the purpose in doing this.

Copy link
Member

Choose a reason for hiding this comment

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

I would assume that telemetry metrics with empty string still get sent through? As in - we'd still be able to see any cloud blocks parsed, the only difficulty would be treating empty strings as app.terraform.io when processing the data.

To put it differently - I'm happy with your implementation - which implies that we do no further interpretation of empty strings in AppInsights, but in that case I think we should do the same for the remote backend below, otherwise we end up comparing apples to pears.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sending empty data is allowed.

If the default is known, I don't see the need for sending empty strings and then having to do conversion when reporting.

I'll open a ticket for backend reporting.

Co-authored-by: Radek Simko <radek.simko@gmail.com>
@jpogran jpogran merged commit 9e2f537 into main Mar 14, 2023
@jpogran jpogran deleted the track_tc_usage branch March 14, 2023 13:30
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Track usage of cloud block
2 participants