diff --git a/Taskfile.yml b/Taskfile.yml index 61ec92a7cb..be924cdb79 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -26,7 +26,6 @@ tasks: - build:tsunamiscaffold env: WAVETERM_ENVFILE: "{{.ROOT_DIR}}/.env" - WCLOUD_PING_ENDPOINT: "https://ping-dev.waveterm.dev/central" WCLOUD_ENDPOINT: "https://api-dev.waveterm.dev/central" WCLOUD_WS_ENDPOINT: "wss://wsapi-dev.waveterm.dev" WAVETERM_NOCONFIRMQUIT: "1" @@ -41,7 +40,6 @@ tasks: - build:backend env: WAVETERM_ENVFILE: "{{.ROOT_DIR}}/.env" - WCLOUD_PING_ENDPOINT: "https://ping-dev.waveterm.dev/central" WCLOUD_ENDPOINT: "https://api-dev.waveterm.dev/central" WCLOUD_WS_ENDPOINT: "wss://wsapi-dev.waveterm.dev" @@ -53,7 +51,6 @@ tasks: - build:backend:quickdev env: WAVETERM_ENVFILE: "{{.ROOT_DIR}}/.env" - WCLOUD_PING_ENDPOINT: "https://ping-dev.waveterm.dev/central" WCLOUD_ENDPOINT: "https://api-dev.waveterm.dev/central" WCLOUD_WS_ENDPOINT: "wss://wsapi-dev.waveterm.dev/" WAVETERM_NOCONFIRMQUIT: "1" @@ -80,7 +77,6 @@ tasks: - build:backend:quickdev:windows env: WAVETERM_ENVFILE: "{{.ROOT_DIR}}/.env" - WCLOUD_PING_ENDPOINT: "https://ping-dev.waveterm.dev/central" WCLOUD_ENDPOINT: "https://api-dev.waveterm.dev/central" WCLOUD_WS_ENDPOINT: "wss://wsapi-dev.waveterm.dev/" @@ -92,7 +88,6 @@ tasks: - build:backend:quickdev:linux env: WAVETERM_ENVFILE: "{{.ROOT_DIR}}/.env" - WCLOUD_PING_ENDPOINT: "https://ping-dev.waveterm.dev/central" WCLOUD_ENDPOINT: "https://api-dev.waveterm.dev/central" WCLOUD_WS_ENDPOINT: "wss://wsapi-dev.waveterm.dev/" WAVETERM_NOCONFIRMQUIT: "1" diff --git a/pkg/wcloud/wcloud.go b/pkg/wcloud/wcloud.go index b31ff94150..0803935eb6 100644 --- a/pkg/wcloud/wcloud.go +++ b/pkg/wcloud/wcloud.go @@ -1,4 +1,4 @@ -// Copyright 2025, Command Line Inc. +// Copyright 2026, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 package wcloud @@ -25,7 +25,7 @@ import ( const WCloudEndpoint = "https://api.waveterm.dev/central" const WCloudEndpointVarName = "WCLOUD_ENDPOINT" -const WCloudPingEndpoint = "https://ping.waveterm.dev/central" +const WCloudPingEndpoint = "https://cfapi.waveterm.dev/api" const WCloudPingEndpointVarName = "WCLOUD_PING_ENDPOINT" var WCloudEndpoint_VarCache string @@ -38,6 +38,7 @@ const MaxUpdatesToDeDup = 1000 const MaxUpdateWriterErrors = 3 const WCloudDefaultTimeout = 5 * time.Second const WCloudWebShareUpdateTimeout = 15 * time.Second +const SendEvents = false // setting to 1M to be safe (max is 6M for API-GW + Lambda, but there is base64 encoding and upload time) // we allow one extra update past this estimated size @@ -180,6 +181,9 @@ func sendTEventsBatch(clientId string) (bool, int, error) { } func sendTEvents(clientId string) (int, error) { + if !SendEvents { + return 0, nil + } numIters := 0 totalEvents := 0 for { @@ -219,6 +223,9 @@ func SendAllTelemetry(clientId string) error { } func sendTelemetry(clientId string) error { + if !SendEvents { + return nil + } ctx, cancelFn := context.WithTimeout(context.Background(), WCloudDefaultTimeout) defer cancelFn() activity, err := telemetry.GetNonUploadedActivity(ctx) @@ -255,6 +262,9 @@ func sendTelemetry(clientId string) error { } func SendNoTelemetryUpdate(ctx context.Context, clientId string, noTelemetryVal bool) error { + if !SendEvents { + return nil + } req, err := makeAnonPostReq(ctx, NoTelemetryUrl, NoTelemetryInputType{ClientId: clientId, Value: noTelemetryVal}) if err != nil { return err diff --git a/pkg/wcloud/wcloud_test.go b/pkg/wcloud/wcloud_test.go new file mode 100644 index 0000000000..a11c8d03c5 --- /dev/null +++ b/pkg/wcloud/wcloud_test.go @@ -0,0 +1,76 @@ +// Copyright 2026, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +package wcloud + +import ( + "context" + "encoding/json" + "io" + "net/http" + "strings" + "testing" +) + +type roundTripFunc func(*http.Request) (*http.Response, error) + +func (fn roundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) { + return fn(req) +} + +func TestEventSending(t *testing.T) { + originalClient := http.DefaultClient + originalPingEndpoint := WCloudPingEndpoint_VarCache + t.Cleanup(func() { + http.DefaultClient = originalClient + WCloudPingEndpoint_VarCache = originalPingEndpoint + }) + WCloudPingEndpoint_VarCache = "https://ping.example.test/central" + var requests []*http.Request + var inputs []PingInputType + http.DefaultClient = &http.Client{Transport: roundTripFunc(func(req *http.Request) (*http.Response, error) { + requests = append(requests, req) + if req.Method != http.MethodPost || req.URL.Path != "/api"+PingUrl { + t.Fatalf("unexpected request: %s %s", req.Method, req.URL.Path) + } + var input PingInputType + if err := json.NewDecoder(req.Body).Decode(&input); err != nil { + t.Fatal(err) + } + inputs = append(inputs, input) + return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(strings.NewReader(""))}, nil + })} + + ctx := context.Background() + if count, err := sendTEvents("test-client"); err != nil || count != 0 { + t.Fatalf("event batch returned (%d, %v), want (0, nil)", count, err) + } + if err := sendTelemetry("test-client"); err != nil { + t.Fatal(err) + } + for _, disabled := range []bool{false, true} { + if err := SendNoTelemetryUpdate(ctx, "test-client", disabled); err != nil { + t.Fatal(err) + } + } + if len(requests) != 0 { + t.Fatalf("got %d requests with uploads disabled, want 0", len(requests)) + } + + for _, enabled := range []bool{false, true} { + if err := SendDiagnosticPing(ctx, "test-client", enabled); err != nil { + t.Fatal(err) + } + } + if len(inputs) != 2 { + t.Fatalf("got %d pings, want 2", len(inputs)) + } + for i, input := range inputs { + if input.ClientId != "test-client" || input.UsageTelemetry != (i == 1) { + t.Errorf("ping %d did not preserve its input", i) + } + if input.Arch == "" || input.Version == "" || input.LocalDate == "" { + t.Errorf("ping %d is missing app details", i) + } + } +}