Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Telemetry #83

Merged
merged 3 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/klotho/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ func run(cmd *cobra.Command, args []string) (err error) {
}

cli.CloseTreeSitter(result)

analyticsClient.AppendProperties(map[string]interface{}{"resource_types": cli.GetResourceTypeCount(result)})
analyticsClient.AppendProperties(map[string]interface{}{"languages": cli.GetLanguagesUsed(result)})
analyticsClient.AppendProperties(map[string]interface{}{"resources": resourceCounts})
analyticsClient.Info("klotho compile complete")

Expand Down
22 changes: 22 additions & 0 deletions pkg/cli/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,28 @@ func OutputResources(result *core.CompilationResult, outDir string) (resourceCou
return
}

func GetLanguagesUsed(result *core.CompilationResult) map[core.ExecutableType]bool {
executableLangs := make(map[core.ExecutableType]bool)
for _, res := range result.Resources() {
switch r := res.(type) {
case *core.ExecutionUnit:
executableLangs[r.Executable.Type] = true
}
}
return executableLangs
}

func GetResourceTypeCount(result *core.CompilationResult) (resourceCounts map[string]map[string]int) {
resourceCounts = make(map[string]map[string]int)
for _, res := range result.Resources() {
if _, ok := resourceCounts[res.Key().Kind]; !ok {
resourceCounts[res.Key().Kind] = make(map[string]int)
}
resourceCounts[res.Key().Kind][res.Type()] = resourceCounts[res.Key().Kind][res.Type()] + 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
resourceCounts[res.Key().Kind][res.Type()] = resourceCounts[res.Key().Kind][res.Type()] + 1
resourceCounts[res.Key().Kind][res.Type()]++

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, will update before pushing

}
return
}

func CloseTreeSitter(result *core.CompilationResult) {
for _, res := range result.Resources() {
if eu, ok := res.(*core.ExecutionUnit); ok {
Expand Down