Skip to content

Commit

Permalink
feat: remove telemetry and agolia
Browse files Browse the repository at this point in the history
  • Loading branch information
gamunu committed Mar 3, 2024
1 parent c2b543c commit a25a2d2
Show file tree
Hide file tree
Showing 12 changed files with 4 additions and 348 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ permissions:
actions: write

env:
PKG_NAME: "terraform-ls"
PKG_NAME: "opentofu-ls"

jobs:
get-go-version:
Expand Down Expand Up @@ -146,7 +146,7 @@ jobs:
arch: ${{ matrix.goarch }}
version: ${{ needs.set-product-version.outputs.product-version }}
maintainer: "HashiCorp"
homepage: "https://github.com/hashicorp/terraform-ls"
homepage: "https://github.com/gamunu/opentofu-ls"
license: "MPL-2.0"
binary: "dist/${{ env.PKG_NAME }}"
deb_depends: "openssl"
Expand Down
10 changes: 0 additions & 10 deletions algolia.go

This file was deleted.

25 changes: 0 additions & 25 deletions internal/algolia/algolia.go

This file was deleted.

7 changes: 0 additions & 7 deletions internal/cmd/serve_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"strings"
"syscall"

"github.com/hashicorp/terraform-ls/internal/algolia"
lsctx "github.com/hashicorp/terraform-ls/internal/context"
"github.com/hashicorp/terraform-ls/internal/langserver"
"github.com/hashicorp/terraform-ls/internal/langserver/handlers"
Expand All @@ -31,9 +30,6 @@ type ServeCommand struct {
Ui cli.Ui
Version string

AlgoliaAppID string
AlgoliaAPIKey string

// flags
port int
logFilePath string
Expand Down Expand Up @@ -108,9 +104,6 @@ func (c *ServeCommand) Run(args []string) int {
logger.Printf("Starting terraform-ls %s", c.Version)

ctx = lsctx.WithLanguageServerVersion(ctx, c.Version)
if c.AlgoliaAppID != "" && c.AlgoliaAPIKey != "" {
ctx = algolia.WithCredentials(ctx, c.AlgoliaAppID, c.AlgoliaAPIKey)
}

var err error
shutdownFunc := func(context.Context) error { return nil }
Expand Down
7 changes: 0 additions & 7 deletions internal/langserver/handlers/completion_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
package handlers

import (
"github.com/algolia/algoliasearch-client-go/v3/algolia/search"
"github.com/hashicorp/hcl-lang/decoder"
"github.com/hashicorp/terraform-ls/internal/algolia"
"github.com/hashicorp/terraform-ls/internal/hooks"
)

Expand All @@ -17,11 +15,6 @@ func (s *service) AppendCompletionHooks(decoderContext decoder.DecoderContext) {
Logger: s.logger,
}

credentials, ok := algolia.CredentialsFromContext(s.srvCtx)
if ok {
h.AlgoliaClient = search.NewClient(credentials.AppID, credentials.APIKey)
}

decoderContext.CompletionHooks["CompleteLocalModuleSources"] = h.LocalModuleSources
decoderContext.CompletionHooks["CompleteRegistryModuleSources"] = h.RegistryModuleSources
decoderContext.CompletionHooks["CompleteRegistryModuleVersions"] = h.RegistryModuleVersions
Expand Down
129 changes: 0 additions & 129 deletions internal/langserver/handlers/hooks_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,137 +11,8 @@ import (
"github.com/hashicorp/terraform-ls/internal/langserver/notifier"
"github.com/hashicorp/terraform-ls/internal/langserver/session"
"github.com/hashicorp/terraform-ls/internal/state"
"github.com/hashicorp/terraform-ls/internal/telemetry"
"github.com/hashicorp/terraform-schema/backend"
)

func sendModuleTelemetry(store *state.StateStore, telemetrySender telemetry.Sender) notifier.Hook {
return func(ctx context.Context, changes state.ModuleChanges) error {
if changes.IsRemoval {
// we ignore removed modules for now
return nil
}

mod, err := notifier.ModuleFromContext(ctx)
if err != nil {
return err
}

properties, hasChanged := moduleTelemetryData(mod, changes, store)
if hasChanged {
telemetrySender.SendEvent(ctx, "moduleData", properties)
}
return nil
}
}

func moduleTelemetryData(mod *state.Module, ch state.ModuleChanges, store *state.StateStore) (map[string]interface{}, bool) {
properties := make(map[string]interface{})
hasChanged := ch.CoreRequirements || ch.Backend || ch.ProviderRequirements ||
ch.TerraformVersion || ch.InstalledProviders

if !hasChanged {
return properties, false
}

if len(mod.Meta.CoreRequirements) > 0 {
properties["tfRequirements"] = mod.Meta.CoreRequirements.String()
}
if mod.Meta.Cloud != nil {
properties["cloud"] = true

hostname := mod.Meta.Cloud.Hostname

// https://developer.hashicorp.com/terraform/language/settings/terraform-cloud#usage-example
// 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"
}

properties["cloud.hostname"] = hostname
}
if mod.Meta.Backend != nil {
properties["backend"] = mod.Meta.Backend.Type
if data, ok := mod.Meta.Backend.Data.(*backend.Remote); ok {
hostname := data.Hostname

// https://developer.hashicorp.com/terraform/language/settings/backends/remote#hostname
// 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"
}

properties["backend.remote.hostname"] = hostname
}
}
if len(mod.Meta.ProviderRequirements) > 0 {
reqs := make(map[string]string, 0)
for pAddr, cons := range mod.Meta.ProviderRequirements {
if telemetry.IsPublicProvider(pAddr) {
reqs[pAddr.String()] = cons.String()
continue
}

// anonymize any unknown providers or the ones not publicly listed
id, err := store.GetProviderID(pAddr)
if err != nil {
continue
}
addr := fmt.Sprintf("unlisted/%s", id)
reqs[addr] = cons.String()
}
properties["providerRequirements"] = reqs
}
if mod.TerraformVersion != nil {
properties["tfVersion"] = mod.TerraformVersion.String()
}
if len(mod.InstalledProviders) > 0 {
installedProviders := make(map[string]string, 0)
for pAddr, pv := range mod.InstalledProviders {
if telemetry.IsPublicProvider(pAddr) {
versionString := ""
if pv != nil {
versionString = pv.String()
}
installedProviders[pAddr.String()] = versionString
continue
}

// anonymize any unknown providers or the ones not publicly listed
id, err := store.GetProviderID(pAddr)
if err != nil {
continue
}
addr := fmt.Sprintf("unlisted/%s", id)
installedProviders[addr] = ""
}
properties["installedProviders"] = installedProviders
}

if !hasChanged {
return nil, false
}

modId, err := store.GetModuleID(mod.Path)
if err != nil {
return nil, false
}
properties["moduleId"] = modId

return properties, true
}

func updateDiagnostics(dNotifier *diagnostics.Notifier) notifier.Hook {
return func(ctx context.Context, changes state.ModuleChanges) error {
if changes.Diagnostics {
Expand Down
65 changes: 0 additions & 65 deletions internal/langserver/handlers/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,11 @@ func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams)
return serverCaps, err
}

properties := getTelemetryProperties(out)
properties["lsVersion"] = serverCaps.ServerInfo.Version

clientCaps := params.Capabilities
expClientCaps := lsp.ExperimentalClientCapabilities(clientCaps.Experimental)

svc.server = jrpc2.ServerFromContext(ctx)

setupTelemetry(expClientCaps, svc, ctx, properties)
defer svc.telemetry.SendEvent(ctx, "initialize", properties)

if params.ClientInfo.Name != "" {
err = ilsp.SetClientName(ctx, params.ClientInfo.Name)
if err != nil {
Expand All @@ -54,19 +48,15 @@ func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams)

if _, ok := expClientCaps.ShowReferencesCommandId(); ok {
expServerCaps.ReferenceCountCodeLens = true
properties["experimentalCapabilities.referenceCountCodeLens"] = true
}
if _, ok := expClientCaps.RefreshModuleProvidersCommandId(); ok {
expServerCaps.RefreshModuleProviders = true
properties["experimentalCapabilities.refreshModuleProviders"] = true
}
if _, ok := expClientCaps.RefreshModuleCallsCommandId(); ok {
expServerCaps.RefreshModuleCalls = true
properties["experimentalCapabilities.refreshModuleCalls"] = true
}
if _, ok := expClientCaps.RefreshTerraformVersionCommandId(); ok {
expServerCaps.RefreshTerraformVersion = true
properties["experimentalCapabilities.refreshTerraformVersion"] = true
}

serverCaps.Capabilities.Experimental = expServerCaps
Expand Down Expand Up @@ -128,13 +118,6 @@ func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams)

if params.RootURI == "" {
svc.singleFileMode = true
properties["root_uri"] = "file"
if properties["options.ignoreSingleFileWarning"] == false {
jrpc2.ServerFromContext(ctx).Notify(ctx, "window/showMessage", &lsp.ShowMessageParams{
Type: lsp.Warning,
Message: "Some capabilities may be reduced when editing a single file. We recommend opening a directory for full functionality. Use 'ignoreSingleFileWarning' to suppress this warning.",
})
}
} else {
rootURI := string(params.RootURI)

Expand All @@ -143,16 +126,13 @@ func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams)
"This is most likely client bug, please report it.", rootURI)

if uri.IsWSLURI(rootURI) {
properties["root_uri"] = "invalid"
// For WSL URIs we return additional error data
// such that clients (e.g. VS Code) can provide better UX
// and nudge users to open in the WSL Remote Extension instead.
return serverCaps, invalidUriErr.WithData("INVALID_URI_WSL")
}

if !uri.IsURIValid(rootURI) {
properties["root_uri"] = "invalid"

return serverCaps, invalidUriErr
}

Expand Down Expand Up @@ -180,51 +160,6 @@ func (svc *service) Initialize(ctx context.Context, params lsp.InitializeParams)
return serverCaps, err
}

func setupTelemetry(expClientCaps lsp.ExpClientCapabilities, svc *service, ctx context.Context, properties map[string]interface{}) {
if tv, ok := expClientCaps.TelemetryVersion(); ok {
svc.logger.Printf("enabling telemetry (version: %d)", tv)
err := svc.setupTelemetry(tv, svc.server)
if err != nil {
svc.logger.Printf("failed to setup telemetry: %s", err)
}
svc.logger.Printf("telemetry enabled (version: %d)", tv)
}
}

func getTelemetryProperties(out *settings.DecodedOptions) map[string]interface{} {
properties := map[string]interface{}{
"experimentalCapabilities.referenceCountCodeLens": false,
"options.ignoreSingleFileWarning": false,
"options.rootModulePaths": false,
"options.excludeModulePaths": false,
"options.commandPrefix": false,
"options.indexing.ignoreDirectoryNames": false,
"options.indexing.ignorePaths": false,
"options.experimentalFeatures.validateOnSave": false,
"options.terraform.path": false,
"options.terraform.timeout": "",
"options.terraform.logFilePath": false,
"options.validation.earlyValidation": false,
"root_uri": "dir",
"lsVersion": "",
}

properties["options.rootModulePaths"] = len(out.Options.XLegacyModulePaths) > 0
properties["options.excludeModulePaths"] = len(out.Options.XLegacyExcludeModulePaths) > 0
properties["options.commandPrefix"] = len(out.Options.CommandPrefix) > 0
properties["options.indexing.ignoreDirectoryNames"] = len(out.Options.Indexing.IgnoreDirectoryNames) > 0
properties["options.indexing.ignorePaths"] = len(out.Options.Indexing.IgnorePaths) > 0
properties["options.experimentalFeatures.prefillRequiredFields"] = out.Options.ExperimentalFeatures.PrefillRequiredFields
properties["options.experimentalFeatures.validateOnSave"] = out.Options.ExperimentalFeatures.ValidateOnSave
properties["options.ignoreSingleFileWarning"] = out.Options.IgnoreSingleFileWarning
properties["options.terraform.path"] = len(out.Options.Terraform.Path) > 0
properties["options.terraform.timeout"] = out.Options.Terraform.Timeout
properties["options.terraform.logFilePath"] = len(out.Options.Terraform.LogFilePath) > 0
properties["options.validation.earlyValidation"] = out.Options.Validation.EnableEnhancedValidation

return properties
}

func initializeResult(ctx context.Context) lsp.InitializeResult {
serverCaps := lsp.InitializeResult{
Capabilities: lsp.ServerCapabilities{
Expand Down
Loading

0 comments on commit a25a2d2

Please sign in to comment.