-
Notifications
You must be signed in to change notification settings - Fork 894
chore: track terraform modules in telemetry #15450
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
0f713ed
add the workspace_modules table, add the module column to workspace_r…
hugodutka 82c8a3c
insert workspace modules on provisioner job completion
hugodutka 307a57e
add foreign key to job on workspace_modules
hugodutka 2ae16fc
don't return the root module
hugodutka 7f2f155
add and populate the module_path column to workspace_resources
hugodutka 863235d
TestCompleteJob - Modules WIP
hugodutka 993f0ab
TemplateImport CompleteJob Modules test
hugodutka e8fbd40
TestCompleteJob Modules WorkspaceBuild
hugodutka 5c542e5
add a test for returning modules in provision_test.go, fix test in re…
hugodutka 9ec5ee1
make gen
hugodutka 119a686
fix dbauthz tests
hugodutka 3a5a025
add workspace modules and workspace resources's ModulePath to telemetry
hugodutka 3377d22
add a workspace_modules fixture
hugodutka 422b112
add a workspace resource's modulePath default to the e2e helper
hugodutka 46b9b36
add modules default on PlanComplete for e2e tests
hugodutka f3f4d5c
lint
hugodutka 93ed136
set module path to sentinel value when parsing failed and log an error
hugodutka 301a153
change error string
hugodutka 212e7d5
obfuscate workspace module source and version
hugodutka e9b7c46
fixes after rebase
hugodutka 25cba6d
change migration number
hugodutka 780730f
change fixture number
hugodutka b47a018
add index on created_at
hugodutka 03be52e
add a comment about using modules from plan instead of apply
hugodutka 00b8131
convert sentinel string to an error
hugodutka 4187fbf
remove unnecessary comment
hugodutka 7e82c3d
don't fail if we can't get modules from disk
hugodutka 42e57ca
add a test for a malformed module
hugodutka 368fc25
add a comment
hugodutka 73b22cf
combine assignment and conditional
hugodutka 7b9d70a
make isCoderModule into a top level function
hugodutka ea82313
use dbtestutil.NewDB instead of dbmem
hugodutka 8564e9a
make gen
hugodutka d11fc82
combine 2 more assignments and conditionals
hugodutka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
set module path to sentinel value when parsing failed and log an error
- Loading branch information
commit 93ed1360c19fb4dcc4453edfc1c2fbea84d48272
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package terraform | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
|
@@ -9,6 +10,8 @@ import ( | |
"github.com/mitchellh/mapstructure" | ||
"golang.org/x/xerrors" | ||
|
||
"cdr.dev/slog" | ||
|
||
"github.com/coder/terraform-provider-coder/provider" | ||
|
||
tfaddr "github.com/hashicorp/go-terraform-address" | ||
|
@@ -134,7 +137,7 @@ type State struct { | |
// ConvertState consumes Terraform state and a GraphViz representation | ||
// produced by `terraform graph` to produce resources consumable by Coder. | ||
// nolint:gocognit // This function makes more sense being large for now, until refactored. | ||
func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error) { | ||
func ConvertState(ctx context.Context, modules []*tfjson.StateModule, rawGraph string, logger slog.Logger) (*State, error) { | ||
parsedGraph, err := gographviz.ParseString(rawGraph) | ||
if err != nil { | ||
return nil, xerrors.Errorf("parse graph: %w", err) | ||
|
@@ -598,9 +601,16 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error | |
modulePath, err := convertAddressToModulePath(resource.Address) | ||
if err != nil { | ||
// Module path recording was added primarily to keep track of | ||
// modules in telemetry. We're adding this fallback so we can | ||
// detect if there are any issues with the address parsing. | ||
modulePath = fmt.Sprintf("error parsing address: %s", resource.Address) | ||
// modules in telemetry. We're adding this sentinel value so | ||
// we can detect if there are any issues with the address | ||
// parsing. | ||
// | ||
// We don't want to set modulePath to null here because, in | ||
// the database, a null value in WorkspaceResource's ModulePath | ||
// indicates "this resource was created before module paths | ||
// were tracked." | ||
modulePath = "FAILED_TO_PARSE_TERRAFORM_ADDRESS" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we extract this to a constant we can refer to elsewhere? EDIT: it might actually be even better as a sentinel error |
||
logger.Error(ctx, "failed to parse Terraform address", slog.F("address", resource.Address)) | ||
} | ||
|
||
agents, exists := resourceAgents[label] | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.